Tensorflow 关于Keras imagedatagenerator.flow(图像,目标)中的目标发生了什么的问题
我的图像有前景和背景,我的目标是图像的像素分类(0和1)。我想使用ImageDataGenerator剪切/缩放/翻转这些图像-目标对,以便获得更多的训练数据。如果我使用imagedatagenerator.flow(图像,目标),我的目标是否会以与图像相同的方式被剪切/放大?如果samplewise center为真,目标值是否也会居中?谢谢大家!Tensorflow 关于Keras imagedatagenerator.flow(图像,目标)中的目标发生了什么的问题,tensorflow,machine-learning,keras,Tensorflow,Machine Learning,Keras,我的图像有前景和背景,我的目标是图像的像素分类(0和1)。我想使用ImageDataGenerator剪切/缩放/翻转这些图像-目标对,以便获得更多的训练数据。如果我使用imagedatagenerator.flow(图像,目标),我的目标是否会以与图像相同的方式被剪切/放大?如果samplewise center为真,目标值是否也会居中?谢谢大家! tf.keras.preprocessing.image.ImageDataGenerator用于根据目标图像的指定规格从给定图像生成图像。示例:
tf.keras.preprocessing.image.ImageDataGenerator
用于根据目标图像的指定规格从给定图像生成图像。示例:您可以执行翻转/剪切/缩放/更改高度/宽度以获取图像
获取目标映像的规范,并将其提供给ImageDataGenerator库以生成所需类型的映像
下面的示例代码可能对您有所帮助
import tensorflow as tf
image = tf.keras.preprocessing.image.load_img('2.jpeg')
datagen = tf.keras.preprocessing.image.ImageDataGenerator(rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
image.getpixel
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = image_array.reshape((1,) + image_array.shape)
count = 0
for batch in datagen.flow(image_new, batch_size=1, save_to_dir ='images_gen' , save_prefix='cat', save_format='jpeg'):
count +=1
if count==10:
break
#显示输入图像
import matplotlib.pylab as plt
image = plt.imread('2.jpeg')
plt.imshow(image)
plt.show()
#在ImageDataGenerator之后显示图像
import matplotlib.pylab as plt
image = plt.imread('images_gen/cat_0_2229.jpeg')
plt.imshow(image)
plt.show()
tf.keras.preprocessing.image.ImageDataGenerator
用于根据指定的目标图像规格从给定图像生成图像。示例:您可以执行翻转/剪切/缩放/更改高度/宽度以获取图像
获取目标映像的规范,并将其提供给ImageDataGenerator库以生成所需类型的映像
下面的示例代码可能对您有所帮助
import tensorflow as tf
image = tf.keras.preprocessing.image.load_img('2.jpeg')
datagen = tf.keras.preprocessing.image.ImageDataGenerator(rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
image.getpixel
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = image_array.reshape((1,) + image_array.shape)
count = 0
for batch in datagen.flow(image_new, batch_size=1, save_to_dir ='images_gen' , save_prefix='cat', save_format='jpeg'):
count +=1
if count==10:
break
#显示输入图像
import matplotlib.pylab as plt
image = plt.imread('2.jpeg')
plt.imshow(image)
plt.show()
#在ImageDataGenerator之后显示图像
import matplotlib.pylab as plt
image = plt.imread('images_gen/cat_0_2229.jpeg')
plt.imshow(image)
plt.show()
清楚地解释你的问题,最好是用代码和错误部分。清楚地解释你的问题,最好是用代码和错误部分。