PIL读取后图片尺寸为是whc,cv2读取后图片尺寸为hwc,在image_classification的reader中是否存在错误?
Created by: miraclebiu
在models/PaddleCV/image_classification/reader.py中使用PIL读取图片,在117行random_crop函数中: img = np.array(img).astype('float32').transpose((2, 0, 1)) / 255 img -= img_mean img /= img_std 使用该方法,transpose后应为cwh,会导致图片相较于chw传统的思路翻转了90度,虽然train,test均做了处理,最终导致模型训练没有影响, 而在reader_cv2中的对应位置处理方式相同,是否存在问题? `def random_crop(img, size, scale=[0.08, 1.0], ratio=[3. / 4., 4. / 3.]): aspect_ratio = math.sqrt(np.random.uniform(*ratio)) w = 1. * aspect_ratio h = 1. / aspect_ratio
bound = min((float(img.size[0]) / img.size[1]) / (w**2),#在这一步是否存在问题?hw的顺序与cv2不同
(float(img.size[1]) / img.size[0]) / (h**2))
scale_max = min(scale[1], bound)
scale_min = min(scale[0], bound)
target_area = img.size[0] * img.size[1] * np.random.uniform(scale_min,
scale_max)
target_size = math.sqrt(target_area)
w = int(target_size * w)
h = int(target_size * h)
i = np.random.randint(0, img.size[0] - w + 1)
j = np.random.randint(0, img.size[1] - h + 1)
img = img.crop((i, j, i + w, j + h))
img = img.resize((size, size), Image.LANCZOS)
return img`
另在该代码中是否能增加一些注释,以便在使用时帮助理解,谢谢!