关于图片实际分辨率与训练分辨率配置的疑问
brian95827 opened this issue · comments
brian95827 commented
brian95827 commented
brian95827 commented
找到了代码了! 代码说图片会先等比缩放,缩放以后如果还比设置的分辨率高,那就删掉一部分图片,保证最终图片的分辨率和设置的是一样大小。
# 画像を読み込む。戻り値はnumpy.ndarray,(original width, original height),(crop left, crop top, crop right, crop bottom)
def trim_and_resize_if_required(
random_crop: bool, image: Image.Image, reso, resized_size: Tuple[int, int]
) -> Tuple[np.ndarray, Tuple[int, int], Tuple[int, int, int, int]]:
image_height, image_width = image.shape[0:2]
original_size = (image_width, image_height) # size before resize
if image_width != resized_size[0] or image_height != resized_size[1]:
# リサイズする
image = cv2.resize(image, resized_size, interpolation=cv2.INTER_AREA) # INTER_AREAでやりたいのでcv2でリサイズ
image_height, image_width = image.shape[0:2]
if image_width > reso[0]:
trim_size = image_width - reso[0]
p = trim_size // 2 if not random_crop else random.randint(0, trim_size)
# print("w", trim_size, p)
image = image[:, p : p + reso[0]]
if image_height > reso[1]:
trim_size = image_height - reso[1]
p = trim_size // 2 if not random_crop else random.randint(0, trim_size)
# print("h", trim_size, p)
image = image[p : p + reso[1]]
# random cropの場合のcropされた値をどうcrop left/topに反映するべきか全くアイデアがない
# I have no idea how to reflect the cropped value in crop left/top in the case of random crop
crop_ltrb = BucketManager.get_crop_ltrb(reso, original_size)
assert image.shape[0] == reso[1] and image.shape[1] == reso[0], f"internal error, illegal trimmed size: {image.shape}, {reso}"
return image, original_size, crop_ltrb
还有,图片训练是不训练透明度的,也不知道为什么。。之前我自己处理图片都是保留了RGBA的。。看来是多此一举了。
def load_image(image_path):
image = Image.open(image_path)
if not image.mode == "RGB":
image = image.convert("RGB")
img = np.array(image, np.uint8)
return img
不知道正确的读代码找关键信息的方式是什么,我是直接全局搜索resize
然后打断点运行,哪个地方停,就看哪个地方的代码。。直接读train_network.py
的话,训练过程又贼复杂,看不懂。。。