You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm reading data process code in ultralytics/data/base.py, set_rectangle is shown below:
def set_rectangle(self):
"""Sets the shape of bounding boxes for YOLO detections as rectangles."""
bi = np.floor(np.arange(self.ni) / self.batch_size).astype(int) # batch index
nb = bi[-1] + 1 # number of batches
s = np.array([x.pop("shape") for x in self.labels]) # hw
ar = s[:, 0] / s[:, 1] # aspect ratio
irect = ar.argsort()
self.im_files = [self.im_files[i] for i in irect]
self.labels = [self.labels[i] for i in irect]
ar = ar[irect]
# Set training image shapes
shapes = [[1, 1]] * nb
for i in range(nb):
ari = ar[bi == i]
mini, maxi = ari.min(), ari.max()
if maxi < 1: # 全是横着的
shapes[i] = [maxi, 1]
elif mini > 1: # 全是竖着的
shapes[i] = [1, 1 / mini]
# 按照5入6更入的方式进行补边,多补至少一个stride
self.batch_shapes = np.ceil(np.array(shapes) * self.imgsz / self.stride + self.pad).astype(int) * self.stride
self.batch = bi # batch index of image
As my understanding this function is used for padding images in a batch according to their ratio so as to concat them and save GPU memory.
My confusion is this line:
self.pad is default set to 0.5, so that if self.imgsz / self.stride >= 0.5, the batch will be extraly pad a stride (e.g. if np.array(shapes) * self.imgsz / self.stride is 6.5, then np.ceil(np.array(shapes) * self.imgsz / self.stride + self.pad).astype(int) will be 8), is this redundant? Seems set self.pad to 0 is enuogh.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I'm reading data process code in
ultralytics/data/base.py
,set_rectangle
is shown below:As my understanding this function is used for padding images in a batch according to their ratio so as to concat them and save GPU memory.
My confusion is this line:
self.pad
is default set to 0.5, so that ifself.imgsz / self.stride >= 0.5
, the batch will be extraly pad a stride (e.g. ifnp.array(shapes) * self.imgsz / self.stride
is 6.5, thennp.ceil(np.array(shapes) * self.imgsz / self.stride + self.pad).astype(int)
will be 8), is this redundant? Seems setself.pad
to 0 is enuogh.Beta Was this translation helpful? Give feedback.
All reactions