简体   繁体   English

Inception v3 的数据增强

[英]Data Augmentation for Inception v3

I'm trying to use inception v3 to classify images but my dataset is very small (can't have more img than that) and I'd like to augment it with transformations such as rotation or inversions.我正在尝试使用 inception v3 对图像进行分类,但我的数据集非常小(不能有比这更多的 img),我想通过旋转或反转等转换来增强它。 I'm new to TF and can't figure out how to do so, I've read the documentation for the ImageDataGenerator which should augment my data but when training I still get the error that states that I don't have enough data.我是 TF 的新手,不知道该怎么做,我已经阅读了ImageDataGenerator的文档,它应该会增加我的数据,但是在训练时我仍然收到错误消息,指出我没有足够的数据。 I could use masks also but don't know how to implement in tf.我也可以使用面具,但不知道如何在 tf. Can someone enlighten me?有人可以启发我吗? Thanks a lot for any input非常感谢任何输入

Here's my code:这是我的代码:

train_datagen = ImageDataGenerator(rescale = 1./255.,
                                   rotation_range = 180,
                                   width_shift_range = 0.2,
                                   height_shift_range = 0.2,
                                   zoom_range = 0.2,
                                   horizontal_flip = True,
                                   vertical_flip = True)
 
test_datagen = ImageDataGenerator(rescale = 1./255.,
                                   rotation_range = 180,
                                   width_shift_range = 0.2,
                                   height_shift_range = 0.2,
                                   zoom_range = 0.2,
                                   horizontal_flip = True,
                                   vertical_flip = True)

 
train_generator = train_datagen.flow_from_directory(train_dir,
                                                    batch_size = 100,
                                                    class_mode = 'binary',
                                                    target_size = (224, 224))


validation_generator =  test_datagen.flow_from_directory(validation_dir,
                                                          batch_size  = 100,
                                                          class_mode  = 'binary',
                                                          target_size = (224, 224))
base_model = InceptionV3(input_shape = (224, 224, 3),
                                include_top = False,
                                weights = 'imagenet')
for layer in base_model.layers:
  layer.trainable = False

%%time
x = layers.Flatten()(base_model.output)
x = layers.Dense(1024, activation='relu')(x)
x = layers.Dropout(0.2)(x)                 
x = layers.Dense(1, activation='sigmoid')(x)          
 
model = Model( base_model.input, x)
 
model.compile(optimizer = RMSprop(learning_rate=0.0001),loss = 'binary_crossentropy',metrics = ['acc'])
callbacks = myCallback()
 
history = model.fit_generator(
            train_generator,
            validation_data = validation_generator,
            steps_per_epoch = 100,
            epochs = 10,
            validation_steps = 10,
            verbose = 2,
            callbacks=[callbacks])

Error:错误:

WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least `steps_per_epoch * epochs` batches (in this case, 1000 batches). You may need to use the repeat() function when building your dataset.

As you are using generators, you will have to calculate the number of steps per epoch as follows:当您使用生成器时,您必须按如下方式计算每个时期的步数:

steps_per_epoch=(data_samples/batch_size)

OR或者

You could let the model figure out how many steps are there to cover an epoch.你可以让 model 算出有多少步可以覆盖一个纪元。 Did you try running it without the steps_per_epoch parameter?您是否尝试在没有steps_per_epoch参数的情况下运行它?

Let us know if the issue still persists.让我们知道问题是否仍然存在。 Thanks!谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM