我正在尝试使用 keras 在图像数据生成器中裁剪图像的中心。我有大小的图像,192x192我想裁剪它们的中心,以便输出批次150x150或类似的东西。
我可以在 Keras 中立即执行此操作ImageDataGenerator吗?我想不会,因为我看到target_sizedatagenerator 中的参数破坏了图像。
我找到了这个随机裁剪的链接:https : //jkjung-avt.github.io/keras-image-cropping/
我已经修改了作物如下:
def my_crop(img, random_crop_size):
if K.image_data_format() == 'channels_last':
# Note: image_data_format is 'channel_last'
assert img.shape[2] == 3
height, width = img.shape[0], img.shape[1]
dy, dx = random_crop_size #input desired output size
start_y = (height-dy)//2
start_x = (width-dx)//2
return img[start_y:start_y+dy, start_x:(dx+start_x), :]
else:
assert img.shape[0] == 3
height, width = img.shape[1], img.shape[2]
dy, dx = random_crop_size # input desired output size
start_y = …Run Code Online (Sandbox Code Playgroud) machine-learning image-processing conv-neural-network keras convolutional-neural-network