如何在Python深度学习模型中重新定位同一图像中的对象

问题描述 投票:0回答:1

我正在开发一个

DL
模型,其中我需要将图像对象重新定位到同一图像本身内的某个位置。示例:

https://vectorstock.com/royalty-free-vector/lemon-soft-drink-advertising-lemonade-can-ads-vector-20584763

从这张图片中,我需要将精灵瓶重新定位到右侧。

我该怎么做?

我已经使用

keras
类尝试了
ImageDataGenerator
库, 但在这里,我为每次运行的模型获得相同 width_shift_range 和 height 的不同生成图像。 链接在这里:

https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html

如何解决这个问题。

from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(rotation_range=40, width_shift_range=0.2,height_shift_range=0.2)
python keras deep-learning
1个回答
0
投票

ImageDataGenerator
用于数据增强 - 它通过根据提供的参数对训练数据应用随机变换来合成新样本。

如果你想应用一些固定的转换,你可以使用

apply_affine_transform()
中的
tensorflow.keras.preprocessing.image
(doc ref):

from PIL import Image
import numpy as np

from tensorflow.keras.preprocessing.image import apply_affine_transform

#Load image
img = np.array(Image.open('../img.jpg'))

#Apply fixed transformations
shifted = apply_affine_transform(img, theta=45, tx=200, ty=200,
                                 row_axis=0, col_axis=1, channel_axis=2)

#Plot
f, axs = plt.subplots(1, 2, figsize=(5, 4))
axs[0].imshow(img)
axs[0].set_title('original')

axs[1].imshow(shifted)
axs[1].set_title('rotated, shifted')
[ax.axis('off') for ax in axs]
© www.soinside.com 2019 - 2024. All rights reserved.