简体   繁体   English

我的模型的训练/验证准确性表现很奇怪

[英]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.

相关问题 我的 model 产生 1.0 的训练精度和验证精度,但预测的标签不正确 - My model produces 1.0 training accuracy and validation accuracy, but the predicted labels are incorrect 为什么 Keras 的 ModelCheckPoint 在训练期间没有保存我最好的 model 具有最高的验证准确率? - Why doesn't Keras' ModelCheckPoint save my best model with the highest validation accuracy during training? 我的 ResNet 迁移学习模型在训练时始终保持 0.5 准确度 - 怎么了? - My ResNet transfer learning model is always stays 0.5 accuracy when training - What's wrong? MNIST的Keras VGG模型:训练和验证准确性之间的差异 - Keras VGG model for MNIST: Disparity between training and validation accuracy 如何在训练过程后找出 model 的验证准确度? - How to find out the validation accuracy of a model after the training process? Keras 模型不是训练层,验证准确率始终为 0.5 - Keras model not training layers, validation accuracy always 0.5 CNN模型的准确性对于培训和验证集永远不会很高 - Accuracy in a CNN model never goes high for training and validation set 对于具有三个类别的 model,plot 训练和验证准确度/损失是否可行? - Possible to plot training and validation accuracy/loss for a model with three classes? 训练准确度提高但验证准确度保持在 0.5,并且模型为每个验证样本预测几乎相同的类别 - Training accuracy improving but validation accuracy remain at 0.5, and model predicts nearly the same class for every validation sample 我已经为 10 个课程训练了一个 CNN 模型。 模型在训练准确度上表现不错,但在验证准确度上停滞不前 - I have trained a CNN model, for 10 classes. Model is doing good on training accuracy but is stuck in validation accuracy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM