-
Notifications
You must be signed in to change notification settings - Fork 8
feature(): Adding reset parameters - usefull for transfer learnings #31
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,7 +163,8 @@ def annotation(self, annotation): | |
| frame = self.framerate * (seconds + 60 * minutes) | ||
|
|
||
| cont = False | ||
|
|
||
| # Initializing label var in case the cont is False dont thrown an error | ||
| label = None | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, it would fail as |
||
| if event not in self.classes: | ||
| cont = True | ||
| else: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,27 @@ def build_model(cfg, verbose=True, default_args=None): | |
| neck=cfg.model.neck, | ||
| runner=cfg.runner.type, | ||
| ) | ||
|
|
||
| # Adding reset_backbone, reset_neck and freeze_backbone will allow | ||
| # in case of transfer learning domains | ||
| if getattr(cfg.model, "freeze_backbone", False): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
| for p in model.model.backbone.parameters(): | ||
| p.requires_grad = False | ||
| logging.info(f"[INFO] Backbone is freeze_backbone: and set requires_grad=False") | ||
|
|
||
| # 2. Freeze neck (optional) | ||
| if getattr(cfg.model, "freeze_neck", False): | ||
| for p in model.model.neck.parameters(): | ||
| logging.info(f"[INFO] Neck is set to freeze_neck: and set requires_grad=False") | ||
| p.requires_grad = False | ||
|
|
||
| # 3. Reset head | ||
| if getattr(cfg.model, "reset_head", False): | ||
| for m in model.model.head.modules(): | ||
| if hasattr(m, "reset_parameters"): | ||
| m.reset_parameters() | ||
| logging.info("[INFO] Hed is set to reset: reset_head: reset_parameters() was called") | ||
|
|
||
| elif cfg.model.type == "E2E": | ||
| model = E2EModel( | ||
| cfg, | ||
|
|
@@ -97,4 +118,4 @@ def build_model(cfg, verbose=True, default_args=None): | |
| logging.info(f"Total trainable parameters: {total_params:,}") | ||
| logging.info(f"Number of parameter groups: {len(parameters_per_layer)}") | ||
|
|
||
| return model | ||
| return model | ||
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 was failing if you set only limited classes to the dataset it tries to evaluate everything but the dictionary will contain only the limited list of classes.