this is because image dimension is greater than sh, thus need to add additional check in padding function
def padding(img, sh, pad_value=0):
if sh[0]<img.shape[0]:
new_w,new_h=int(img.shape[1]/img.shape[0])sh[0],sh[0]
print(new_w,new_h,type(img))
img=cv2.resize(img.astype(np.uint8),(new_w,new_h))
elif sh[1]<img.shape[1]:
new_h,new_w=int(img.shape[0]/img.shape[1])sh[1],sh[1]
img=cv2.resize(img.astype(np.uint8),(new_w,new_h))
else:
img=img
if img.ndim == 2:
return np.pad(img, [(0,sh[0]-img.shape[0]), (0, sh[1]-img.shape[1])], 'constant', constant_values=pad_value)
else:
return np.pad(img, [(0,sh[0]-img.shape[0]), (0, sh[1]-img.shape[1]), (0,0)], 'constant', constant_values=pad_value)
when i was training i was getting
this is because image dimension is greater than sh, thus need to add additional check in padding function def padding(img, sh, pad_value=0): if sh[0]<img.shape[0]: new_w,new_h=int(img.shape[1]/img.shape[0])sh[0],sh[0] print(new_w,new_h,type(img)) img=cv2.resize(img.astype(np.uint8),(new_w,new_h)) elif sh[1]<img.shape[1]: new_h,new_w=int(img.shape[0]/img.shape[1])sh[1],sh[1] img=cv2.resize(img.astype(np.uint8),(new_w,new_h)) else: img=img if img.ndim == 2: return np.pad(img, [(0,sh[0]-img.shape[0]), (0, sh[1]-img.shape[1])], 'constant', constant_values=pad_value) else: return np.pad(img, [(0,sh[0]-img.shape[0]), (0, sh[1]-img.shape[1]), (0,0)], 'constant', constant_values=pad_value)