Skip to content

Commit a2be414

Browse files
author
yixu.cui
committed
fix np.dtype bug
1 parent e3483ce commit a2be414

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

utils/datasets.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ def __init__(
570570
x[:, 0] = 0
571571

572572
n = len(shapes) # number of images
573-
bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index
573+
bi = np.floor(np.arange(n) / batch_size).astype(np.int32) # batch index
574574
nb = bi[-1] + 1 # number of batches
575575
self.batch = bi # batch index of image
576576
self.n = n
@@ -599,7 +599,7 @@ def __init__(
599599
shapes[i] = [1, 1 / mini]
600600

601601
self.batch_shapes = (
602-
np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int)
602+
np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int32)
603603
* stride
604604
)
605605

@@ -965,7 +965,7 @@ def __init__(
965965
x[:, 0] = 0
966966

967967
n = len(shapes) # number of images
968-
bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index
968+
bi = np.floor(np.arange(n) / batch_size).astype(np.int32) # batch index
969969
nb = bi[-1] + 1 # number of batches
970970
self.batch = bi # batch index of image
971971
self.n = n
@@ -994,7 +994,7 @@ def __init__(
994994
shapes[i] = [1, 1 / mini]
995995

996996
self.batch_shapes = (
997-
np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int)
997+
np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int32)
998998
* stride
999999
)
10001000

@@ -1332,7 +1332,7 @@ def copy_paste(img, labels, segments, probability=0.5):
13321332
segments.append(np.concatenate((w - s[:, 0:1], s[:, 1:2]), 1))
13331333
cv2.drawContours(
13341334
im_new,
1335-
[segments[j].astype(np.int)],
1335+
[segments[j].astype(np.int32)],
13361336
-1,
13371337
(255, 255, 255),
13381338
cv2.FILLED,
@@ -1355,7 +1355,7 @@ def remove_background(img, labels, segments):
13551355
img_new = np.ones(img.shape, np.uint8) * 114
13561356
for j in range(n):
13571357
cv2.drawContours(
1358-
im_new, [segments[j].astype(np.int)], -1, (255, 255, 255), cv2.FILLED
1358+
im_new, [segments[j].astype(np.int32)], -1, (255, 255, 255), cv2.FILLED
13591359
)
13601360

13611361
result = cv2.bitwise_and(src1=img, src2=im_new)
@@ -1392,7 +1392,7 @@ def sample_segments(img, labels, segments, probability=0.5):
13921392
mask = np.zeros(img.shape, np.uint8)
13931393

13941394
cv2.drawContours(
1395-
mask, [segments[j].astype(np.int)], -1, (255, 255, 255), cv2.FILLED
1395+
mask, [segments[j].astype(np.int32)], -1, (255, 255, 255), cv2.FILLED
13961396
)
13971397
sample_masks.append(mask[box[1] : box[3], box[0] : box[2], :])
13981398

@@ -1699,7 +1699,7 @@ def pastein(image, labels, sample_labels, sample_images, sample_masks):
16991699
r_image = cv2.resize(sample_images[sel_ind], (r_w, r_h))
17001700
temp_crop = image[ymin : ymin + r_h, xmin : xmin + r_w]
17011701
m_ind = r_mask > 0
1702-
if m_ind.astype(np.int).sum() > 60:
1702+
if m_ind.astype(np.int32).sum() > 60:
17031703
temp_crop[m_ind] = r_image[m_ind]
17041704
# print(sample_labels[sel_ind])
17051705
# print(sample_images[sel_ind].shape)
@@ -1809,7 +1809,7 @@ def extract_boxes(
18091809
b = x[1:] * [w, h, w, h] # box
18101810
# b[2:] = b[2:].max() # rectangle to square
18111811
b[2:] = b[2:] * 1.2 + 3 # pad
1812-
b = xywh2xyxy(b.reshape(-1, 4)).ravel().astype(np.int)
1812+
b = xywh2xyxy(b.reshape(-1, 4)).ravel().astype(np.int32)
18131813

18141814
b[[0, 2]] = np.clip(b[[0, 2]], 0, w) # clip boxes outside of image
18151815
b[[1, 3]] = np.clip(b[[1, 3]], 0, h)

utils/general.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def labels_to_class_weights(labels, nc=80):
219219
return torch.Tensor()
220220

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

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

235235
def labels_to_image_weights(labels, nc=80, class_weights=np.ones(80)):
236236
# Produces image weights based on class_weights and image contents
237-
class_counts = np.array([np.bincount(x[:, 0].astype(np.int), minlength=nc) for x in labels])
237+
class_counts = np.array([np.bincount(x[:, 0].astype(np.int32), minlength=nc) for x in labels])
238238
image_weights = (class_weights.reshape(1, nc) * class_counts).sum(1)
239239
# index = random.choices(range(n), weights=image_weights, k=1) # weight image sample
240240
return image_weights

0 commit comments

Comments
 (0)