Skip to content
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

Hotfix/sg 000 Fix support of arbitrary number of heads #1431

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/super_gradients/module_interfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from .module_interfaces import HasPredict, HasPreprocessingParams, SupportsReplaceNumClasses
from .exportable_detector import ExportableObjectDetectionModel, AbstractObjectDetectionDecodingModule
from .exportable_detector import ExportableObjectDetectionModel, AbstractObjectDetectionDecodingModule, ModelHasNoPreprocessingParamsException

__all__ = ["HasPredict", "HasPreprocessingParams", "SupportsReplaceNumClasses", "ExportableObjectDetectionModel", "AbstractObjectDetectionDecodingModule"]
__all__ = [
"HasPredict",
"HasPreprocessingParams",
"SupportsReplaceNumClasses",
"ExportableObjectDetectionModel",
"AbstractObjectDetectionDecodingModule",
"ModelHasNoPreprocessingParamsException",
]
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def _init_weights(self):

@torch.jit.ignore
def forward_train(self, feats: Tuple[Tensor, ...]):
feats = feats[: self.num_heads]
anchors, anchor_points, num_anchors_list, stride_tensor = generate_anchors_for_grid_cell(
feats, self.fpn_strides, self.grid_cell_scale, self.grid_cell_offset
)
Expand All @@ -215,7 +216,7 @@ def forward_train(self, feats: Tuple[Tensor, ...]):
return cls_score_list, reg_distri_list, anchors, anchor_points, num_anchors_list, stride_tensor

def forward_eval(self, feats: Tuple[Tensor, ...]) -> Tuple[Tuple[Tensor, Tensor], Tuple[Tensor, ...]]:

feats = feats[: self.num_heads]
cls_score_list, reg_distri_list, reg_dist_reduced_list = [], [], []

for i, feat in enumerate(feats):
Expand Down Expand Up @@ -290,7 +291,7 @@ def _generate_anchors(self, feats=None, dtype=None, device=None):
else:
shift_y, shift_x = torch.meshgrid(shift_y, shift_x)

anchor_point = torch.stack([shift_x, shift_y], dim=-1)
anchor_point = torch.stack([shift_x, shift_y], dim=-1).to(dtype=dtype)
anchor_points.append(anchor_point.reshape([-1, 2]))
stride_tensor.append(torch.full([h * w, 1], stride, dtype=dtype))
anchor_points = torch.cat(anchor_points)
Expand Down