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

Crashing AdaptiveDetectionLoss #1

Merged
merged 1 commit into from
Jan 12, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Literal
from typing import Literal, cast

import torch
import torch.nn.functional as F
Expand Down Expand Up @@ -209,8 +209,11 @@ def forward(
def _preprocess_target(self, target: Tensor, batch_size: int, scale_tensor: Tensor):
"""Preprocess target in shape [batch_size, N, 5] where N is maximum number of
instances in one image."""
sample_ids, counts = torch.unique(target[:, 0].int(), return_counts=True)
out_target = torch.zeros(batch_size, counts.max(), 5, device=target.device)
sample_ids, counts = cast(
tuple[Tensor, Tensor], torch.unique(target[:, 0].int(), return_counts=True)
)
c_max = int(counts.max()) if counts.numel() > 0 else 0
out_target = torch.zeros(batch_size, c_max, 5, device=target.device)
out_target[:, :, 0] = -1
for id, count in zip(sample_ids, counts):
out_target[id, :count] = target[target[:, 0] == id][:, 1:]
Expand Down
Loading