-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Adding args for names of train and val directories #1544
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1544 +/- ##
==========================================
+ Coverage 64.6% 65.49% +0.88%
==========================================
Files 87 90 +3
Lines 6742 7078 +336
Branches 1034 1076 +42
==========================================
+ Hits 4356 4636 +280
- Misses 2085 2134 +49
- Partials 301 308 +7
Continue to review full report at Codecov.
|
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.
Thanks for the PR!
I think there is a problem with how you are handling the different number of classes. Apart from that, the other changes are good to me, so if you would want to get this merged quickly, just removing the output_classes
part of the code would be fine with me
@@ -203,6 +203,8 @@ def main(args): | |||
|
|||
print("Creating model") | |||
model = torchvision.models.video.__dict__[args.model](pretrained=args.pretrained) | |||
if args.output_classes is not None: |
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.
This does not affect anything in the code. You would need to pass num_classes=output_classes
to the video model for it to work.
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.
True, I fixed this in the latest commit.
Fixed it while making the default |
@@ -203,6 +203,7 @@ def main(args): | |||
|
|||
print("Creating model") | |||
model = torchvision.models.video.__dict__[args.model](pretrained=args.pretrained) | |||
model.fc.out_features = args.output_classes |
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.
This is not quite what I meant.
Changing model.fc.out_features
doesn't change the number of output planes, because the model weights have already been generated.
What I meant was to do something like
model = torchvision.models.video.__dict__[args.model](pretrained=args.pretrained, num_classes=args.num_classes)
But then, using pretrained=True
and num-classes different than 400 will give an error, because the state-dicts are not compatible.
I'd rather not expose this option to the training scripts, as the user can modify the model as they want to perform their type of fine-tuning.
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.
If fine-tuning on a custom dataset, one loads in a pretrained model with that model's num_class
(400 here), and then changes the output classes to their custom dataset.
Though the output planes are different, the biggest benefit from a pretrained model aren't in the fc
part of the model, but the convolutional filters that come in the previous parts of the model. The fc
parts get retrained when fine-tuning this way.
I'd rather not expose this option to the training scripts, as the user can modify the model as they want to perform their type of fine-tuning.
This change in model.fc.out_features
is mandatory when fine-tuning on a custom dataset, so I thought it would make sense to have it in the args
. But of course, that's your call :)
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.
What I mean is that this change doesn't actually change anything in the model. The weights are still the same as before, and they are not resized to a different size.
Putting it differently, you'll only predict at most 400 classes in this way.
@rsomani95 take A look at how Kenso deals with finetuning - it's a fairly elegant approach ref: https://github.com/kenshohara/3D-ResNets-PyTorch |
@rsomani95 Let's close the PR for now, and re-open it when you have the time. Thoughts? |
@fmassa That sounds good. Commiting just the video path changes. |
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.
Thanks!
* Generalised for custom dataset * Typo, redundant code, sensible default * Args for name of train and val dir
Summary: * Generalised for custom dataset * Typo, redundant code, sensible default * Args for name of train and val dir Pull Request resolved: #1683 Reviewed By: cpuhrsch Differential Revision: D19156990 Pulled By: fmassa fbshipit-source-id: eb865c4ed3e7eaf455ce5d03d5ac64e0c153d6de
As discussed in #1540