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

1. If image suffix is in the label's name, label's path will be error 2. Deprecated alias "np.int" #438

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 8 additions & 7 deletions utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,9 @@ def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, r

def img2label_paths(img_paths):
# Define label paths as a function of image paths
from pathlib import Path
sa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep # /images/, /labels/ substrings
return [x.replace(sa, sb, 1).replace(x.split('.')[-1], 'txt') for x in img_paths]
return [Path(x.replace(sa, sb, 1)).with_suffix('.txt') for x in img_paths]

try:
f = [] # image files
Expand Down Expand Up @@ -406,7 +407,7 @@ def img2label_paths(img_paths):
self.label_files = img2label_paths(cache.keys()) # update

n = len(shapes) # number of images
bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index
bi = np.floor(np.arange(n) / batch_size).astype(np.int64) # batch index
nb = bi[-1] + 1 # number of batches
self.batch = bi # batch index of image
self.n = n
Expand All @@ -433,7 +434,7 @@ def img2label_paths(img_paths):
elif mini > 1:
shapes[i] = [1, 1 / mini]

self.batch_shapes = np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int) * stride
self.batch_shapes = np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int64) * stride

# Check labels
create_datasubset, extract_bounding_boxes, labels_loaded = False, False, False
Expand Down Expand Up @@ -479,7 +480,7 @@ def img2label_paths(img_paths):
b = x[1:] * [w, h, w, h] # box
b[2:] = b[2:].max() # rectangle to square
b[2:] = b[2:] * 1.3 + 30 # pad
b = xywh2xyxy(b.reshape(-1, 4)).ravel().astype(np.int)
b = xywh2xyxy(b.reshape(-1, 4)).ravel().astype(np.int64)

b[[0, 2]] = np.clip(b[[0, 2]], 0, w) # clip boxes outside of image
b[[1, 3]] = np.clip(b[[1, 3]], 0, h)
Expand Down Expand Up @@ -689,7 +690,7 @@ def img2label_paths(img_paths):
self.label_files = img2label_paths(cache.keys()) # update

n = len(shapes) # number of images
bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index
bi = np.floor(np.arange(n) / batch_size).astype(np.int64) # batch index
nb = bi[-1] + 1 # number of batches
self.batch = bi # batch index of image
self.n = n
Expand All @@ -716,7 +717,7 @@ def img2label_paths(img_paths):
elif mini > 1:
shapes[i] = [1, 1 / mini]

self.batch_shapes = np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int) * stride
self.batch_shapes = np.ceil(np.array(shapes) * img_size / stride + pad).astype(np.int64) * stride

# Check labels
create_datasubset, extract_bounding_boxes, labels_loaded = False, False, False
Expand Down Expand Up @@ -762,7 +763,7 @@ def img2label_paths(img_paths):
b = x[1:] * [w, h, w, h] # box
b[2:] = b[2:].max() # rectangle to square
b[2:] = b[2:] * 1.3 + 30 # pad
b = xywh2xyxy(b.reshape(-1, 4)).ravel().astype(np.int)
b = xywh2xyxy(b.reshape(-1, 4)).ravel().astype(np.int64)

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