【发布时间】:2021-01-30 06:15:30
【问题描述】:
我想创建一个 CNN 模型来对 10 种不同的汽车进行分类。首先,我下载了一些图像,现在我想通过数据增强来增加图像的数量。由于一次做一张图片很忙,我为它写了一个 for 循环,它显示了一个错误。
TypeError Traceback (most recent call last)
<ipython-input-14-9ced4a120c2d> in <module>
10
11 for i in images:
---> 12 x = img_to_array(images[i])
13 x = x.reshape((1,) + x.shape)
14 j=0
~\anaconda3\envs\DSEnv\lib\site-packages\keras_preprocessing\image\iterator.py in __getitem__(self, idx)
51
52 def __getitem__(self, idx):
---> 53 if idx >= len(self):
54 raise ValueError('Asked to retrieve element {idx}, '
55 'but the Sequence '
TypeError: '>=' not supported between instances of 'tuple' and 'int'
代码:
images = ImageDataGenerator().flow_from_directory(r'\Users\Mohda\OneDrive\Desktop\ferrari sf90 stradale')
datagen = ImageDataGenerator(
rotation_range=30,
width_shift_range=0.3,
height_shift_range=0.3,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
vertical_flip=True,
fill_mode='nearest')
for i in images:
x = img_to_array(images[i])
x = x.reshape((1,) + x.shape)
j=0
for batch in datagen.flow(x,batch_size=1,save_to_dir='preview',save_prefix='ferrari sf90 stradale',save_format='jpeg'):
i+=1
if i>20:
break
【问题讨论】:
标签: python conv-neural-network data-augmentation