[英]my model's Training/Validation accuracy behave strange
i'm new to ML and i'm trying to fit a model for some images to do a binary classification.i have a dataset of 550 images for each of these two classes and i use 100 images of each class for validation.i use augmentation for my data and tensorboard for visualizing accurazy and loss.my loss function is 'binary_crossentropy' and i use 'rmsprop' as optimizer.my images i wrote my code here.the problem is my accuracy still between 49 and 52 for first 3 epochs and rises to 95 percent to 5th epoch but it falls back to 50 percent at 8th and this rise and fall happens in next epochs as well.also i provided some images from tensorboard till 8th epoch .i used this exact same code for kaggle cat and dog classification and it worked fine with about more than 86 percent accuracy.i think my problem is from my data because images in each classes are very different but in same class some times i can't say if two images are not same(they are not but they're very similar). 我是ML的新手,我正在尝试为某些图像拟合模型以进行二进制分类。我为这两个类别中的每个类别都有550张图像的数据集,并且我使用每个类别的100张图像进行验证。我的数据和张量板的增强用于可视化准确度和损失。我的损失函数是'binary_crossentropy'并且我使用'rmsprop'作为优化器。我的图像是我在此处编写的代码。问题是我在前3个时期的精度仍然在49到52之间并上升到第5个时期的95%,但在第8个时期下降到50%,这种上升和下降也发生在下一个时期。我也提供了一些张量板的图像,直到第8个时期。我对kaggle cat使用了完全相同的代码,狗分类,它的正确率约86%以上,可以很好地工作。我认为我的问题出在我的数据上,因为每个类别中的图像都非常不同,但在同一类别中有时我无法确定两个图像是否不相同(它们是不是,但是它们非常相似)。 i'll be very grateful if any one can answer what should i do.
如果有人可以回答我该怎么办,我将不胜感激。
https://i.imgur.com/jLJwnWN.png https://i.imgur.com/jLJwnWN.png
https://i.imgur.com/94odStK.png https://i.imgur.com/94odStK.png
https://i.imgur.com/xUE9K4a.png https://i.imgur.com/xUE9K4a.png
https://i.imgur.com/gGy3hO7.png https://i.imgur.com/gGy3hO7.png
i tried to add and remove some layers but it didn't work 我试图添加和删除一些图层,但是没有用
i tried to change batch size how ever i think it's not that much important but still same things happens . 我试图更改批处理大小,但我认为这并不重要,但还是会发生同样的事情。
i tried changing input dimensions too. 我也尝试更改输入尺寸。 my images are actually 720*500 bu i tried different inputs here .it didn't work:
我的图像实际上是720 * 500 bu,我在这里尝试了不同的输入。它不起作用:
model = Sequential()
model.add(Conv2D(32, (3, 3),input_shape=(300,300,3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy',optimizer='rmsprop',metrics=['accuracy'])
batch_size = 10
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1./255)
train_generator =
train_datagen.flow_from_directory('castData/train-set',
batch_size=batch_size,
class_mode='binary')
validation_generator = test_datagen.flow_from_directory(,
target_size=(300, 300),
batch_size=batch_size,
class_mode='binary')
model.fit_generator(
train_generator,
steps_per_epoch=1075 ,
epochs=50,
validation_data=validation_generator,validation_steps=200,
callbacks=[tensorboard_cb])
Indeed strange behavior. 确实是奇怪的行为。
I wouldn't use flatten layer but GlobalAveragePooling2D or GlobalMaxPooling2D 我不会使用平坦层,但会使用GlobalAveragePooling2D或GlobalMaxPooling2D
from keras.layers import GlobalAveragePooling2D
model = Sequential()
model.add(Conv2D(32, (3, 3),input_shape=(300,300,3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(GlobalAveragePooling2D())
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
if this won't work try reducing the learning rate 如果这样做不起作用,请尝试降低学习率
from keras.optimizers import RMSprop
model.compile(loss='binary_crossentropy',optimizer=RMSprop(lr=0.0001),metrics=['accuracy'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.