Skip to content

Commit

Permalink
utils/loss.py minor bug fix (WongKinYiu#1344)
Browse files Browse the repository at this point in the history
* utils/loss.py L.NO 742

* Changed np.int to np.int32 due to deprecation of np.int
  • Loading branch information
rohanpatankar926 authored Jan 1, 2023
1 parent 48052c4 commit 2fdc7f1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ def pastein(image, labels, sample_labels, sample_images, sample_masks):
r_image = cv2.resize(sample_images[sel_ind], (r_w, r_h))
temp_crop = image[ymin:ymin+r_h, xmin:xmin+r_w]
m_ind = r_mask > 0
if m_ind.astype(np.int).sum() > 60:
if m_ind.astype(np.int32).sum() > 60:
temp_crop[m_ind] = r_image[m_ind]
#print(sample_labels[sel_ind])
#print(sample_images[sel_ind].shape)
Expand Down
4 changes: 2 additions & 2 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def labels_to_class_weights(labels, nc=80):
return torch.Tensor()

labels = np.concatenate(labels, 0) # labels.shape = (866643, 5) for COCO
classes = labels[:, 0].astype(np.int) # labels = [class xywh]
classes = labels[:, 0].astype(np.int32) # labels = [class xywh]
weights = np.bincount(classes, minlength=nc) # occurrences per class

# Prepend gridpoint count (for uCE training)
Expand All @@ -234,7 +234,7 @@ def labels_to_class_weights(labels, nc=80):

def labels_to_image_weights(labels, nc=80, class_weights=np.ones(80)):
# Produces image weights based on class_weights and image contents
class_counts = np.array([np.bincount(x[:, 0].astype(np.int), minlength=nc) for x in labels])
class_counts = np.array([np.bincount(x[:, 0].astype(np.int32), minlength=nc) for x in labels])
image_weights = (class_weights.reshape(1, nc) * class_counts).sum(1)
# index = random.choices(range(n), weights=image_weights, k=1) # weight image sample
return image_weights
Expand Down
2 changes: 1 addition & 1 deletion utils/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def build_targets(self, p, targets, imgs):
+ 3.0 * pair_wise_iou_loss
)

matching_matrix = torch.zeros_like(cost, device="cpu")
matching_matrix = torch.zeros_like(cost, device=device)

for gt_idx in range(num_gt):
_, pos_idx = torch.topk(
Expand Down

0 comments on commit 2fdc7f1

Please sign in to comment.