added changes to use grayscale images during training

single_channel
Clea Parcerisas 1 year ago
parent e8dcc30754
commit 833d864689

@ -3,6 +3,7 @@
# Parameters # Parameters
nc: 80 # number of classes nc: 80 # number of classes
ch: 1 # number of channels
scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n' scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n'
# [depth, width, max_channels] # [depth, width, max_channels]
n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs

@ -741,9 +741,15 @@ class Format:
def _format_img(self, img): def _format_img(self, img):
"""Format the image for YOLOv5 from Numpy array to PyTorch tensor.""" """Format the image for YOLOv5 from Numpy array to PyTorch tensor."""
# if len(img.shape) < 3:
# img = np.expand_dims(img, -1)
# img = np.ascontiguousarray(img.transpose(2, 0, 1)[::-1])
# img = torch.from_numpy(img)
# return img
if len(img.shape) < 3: if len(img.shape) < 3:
img = np.expand_dims(img, -1) img = img.reshape([1, *img.shape])
img = np.ascontiguousarray(img.transpose(2, 0, 1)[::-1]) img = np.ascontiguousarray(img)
img = torch.from_numpy(img) img = torch.from_numpy(img)
return img return img

@ -148,7 +148,7 @@ class BaseDataset(Dataset):
if fn.exists(): # load npy if fn.exists(): # load npy
im = np.load(fn) im = np.load(fn)
else: # read image else: # read image
im = cv2.imread(f) # BGR im = cv2.imread(f, cv2.IMREAD_GRAYSCALE) # BGR
if im is None: if im is None:
raise FileNotFoundError(f'Image Not Found {f}') raise FileNotFoundError(f'Image Not Found {f}')
h0, w0 = im.shape[:2] # orig hw h0, w0 = im.shape[:2] # orig hw

Loading…
Cancel
Save