-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Use torch.accelerator API in Siamese Network example #1337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
# Siamese Network Example | ||
Siamese network for image similarity estimation. | ||
The network is composed of two identical networks, one for each input. | ||
The output of each network is concatenated and passed to a linear layer. | ||
The output of the linear layer passed through a sigmoid function. | ||
[FaceNet](https://arxiv.org/pdf/1503.03832.pdf) is a variant of the Siamese network. | ||
This implementation varies from FaceNet as we use the `ResNet-18` model from | ||
[Deep Residual Learning for Image Recognition](https://arxiv.org/pdf/1512.03385.pdf) as our feature extractor. | ||
In addition, we aren't using `TripletLoss` as the MNIST dataset is simple, so `BCELoss` can do the trick. | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
python main.py | ||
# CUDA_VISIBLE_DEVICES=2 python main.py # to specify GPU id to ex. 2 | ||
``` | ||
Optionally, you can add the following arguments to customize your execution. | ||
|
||
```bash | ||
--batch-size input batch size for training (default: 64) | ||
--test-batch-size input batch size for testing (default: 1000) | ||
--epochs number of epochs to train (default: 14) | ||
--lr learning rate (default: 1.0) | ||
--gamma learning rate step gamma (default: 0.7) | ||
--accel use accelerator | ||
--dry-run quickly check a single pass | ||
--seed random seed (default: 1) | ||
--log-interval how many batches to wait before logging training status | ||
--save-model Saving the current Model | ||
``` | ||
|
||
To execute in an GPU, add the --accel argument to the command. For example: | ||
|
||
```bash | ||
python main.py --accel | ||
``` | ||
|
||
This command will execute the example on the detected GPU. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
torch | ||
torchvision==0.20.0 | ||
torchvision |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to #1338 (comment). @eromomon : I did not see this PR before it got merged. But you've changed the default in this example. Previously acceleration was always used (if available) and there was a flag to disable it. Now default is to not use acceleration and there is a flag to enable it. I personally like new behavior better, but we need to change the CI script to reflect that and that was not done:
examples/run_python_examples.sh
Line 112 in 54e132e