-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor transformer decoder #36
Conversation
* use better variable names * remove complicated code pathways * save embeddings in a dictionary and always return that dictionary instead of sometimes returning None
WalkthroughThe changes involve refining type annotations in the transformer model classes, improving variable naming in test functions for clarity, and enhancing anomaly detection for debugging in the training tests. Changes
Poem
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (2)
Files skipped from review as they are similar to previous changes (1)
Additional Context UsedRuff (2)
Additional comments not posted (6)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 0
Out of diff range and nitpick comments (6)
tests/test_training.py (3)
Line range hint
9-9
: Remove unused importGlobalTrackingTransformer
.- from biogtr.models.global_tracking_transformer import GlobalTrackingTransformer
Line range hint
10-10
: Remove unused importDictConfig
.- from omegaconf import DictConfig
Line range hint
46-46
: The variablefeats
is declared but never used intest_basic_gtr_runner
.Consider removing or using the variable if it was intended for future use.
tests/test_models.py (2)
Line range hint
314-314
: The variableimg_shape
is declared but never used intest_transformer_basic
.Consider removing or using the variable if it was intended for future use.
Line range hint
386-386
: The variablecfg
is declared but never used intest_tracking_transformer
.Consider removing or using the variable if it was intended for future use.
biogtr/models/transformer.py (1)
45-45
: Ensure the constructor's documentation is updated to reflect all parameters.Consider updating the documentation to include all new parameters and their descriptions to maintain clarity and developer understanding.
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.
Looks amazing as-is, but would make some small changes
biogtr/models/transformer.py
Outdated
|
||
reid_features = reid_features.permute( | ||
1, 0, 2 | ||
) # (total_instances x batch_size x embed_dim) |
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.
Use standard shape tuple syntax for documenting shapes:
) # (total_instances x batch_size x embed_dim) | |
) # (total_instances, batch_size, embed_dim) |
biogtr/models/transformer.py
Outdated
# print(f'T: {window_length}; N: {total_instances}; N_t: {instances_per_frame} n_reid: {reid_features.shape}') | ||
pred_box, pred_time = get_boxes_times(frames) # total_instances x 4 | ||
|
||
temp_emb = self.temp_emb(pred_time / window_length) | ||
if self.return_embedding: | ||
embeddings_dict["temp"] = temp_emb # .detach().cpu() |
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.
unused comment
biogtr/models/transformer.py
Outdated
|
||
pos_emb = self.pos_emb(pred_box) | ||
if self.return_embedding: | ||
embeddings_dict["pos"] = pos_emb # .detach().cpu() |
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.
unused comment
biogtr/models/transformer.py
Outdated
|
||
encoder_queries = reid_features | ||
|
||
encoder_logits = self.encoder( |
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.
Are you sure these are logits? That term is usually reserved for the pre-softmax/sigmoid activations in a classification head.
Maybe encoder_features
?
biogtr/models/transformer.py
Outdated
q, | ||
k, | ||
value=src, | ||
attn_logits = self.self_attn( |
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.
attn_features
?
biogtr/models/transformer.py
Outdated
encoder_logits = self.norm2(queries) | ||
|
||
return src | ||
return encoder_logits |
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.
encoder_features
?
* replace use of `logits` with more appropriate `features` * remove unnecessary comments * standardize shape hinting format
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.
Actionable comments posted: 0
Out of diff range and nitpick comments (2)
tests/test_models.py (2)
Line range hint
314-314
: Unused variableimg_shape
.- img_shape = (1, 100, 100)
The variable
img_shape
is defined but never used within thetest_transformer_basic
function. Consider removing it if it's not needed.
Line range hint
386-386
: Unused variablecfg
.- cfg = {"resnet18", "ResNet18_Weights.DEFAULT"}
The variable
cfg
is defined but not used in thetest_tracking_transformer
function. It appears to be a mistake since a dictionary is expected but a set is provided. Ifcfg
is intended for use, correct the syntax and ensure it's utilized.
Refactor transformer implementation as requested by #34.
Summary by CodeRabbit