Keras猫狗大战五:采用全部数据集训练,精度提高到90%

Posted zhengbiqing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Keras猫狗大战五:采用全部数据集训练,精度提高到90%相关的知识,希望对你有一定的参考价值。

深度学习严重依赖训练数据量的大小,前面(https://www.cnblogs.com/zhengbiqing/p/11070783.html)只随机抽取猫狗图片各1000、500、200分别作为训练、验证、测试集,即使采用了数据增强,精度只达到83%。

采用kaggle 猫狗数据集全部25000张进行训练学习,随机选取猫狗图片各9000、2250、1250分别作为训练、验证、测试集,进行训练。

训练100次迭代:

history = model.fit_generator(
    train_generator,
    steps_per_epoch=train_generator.samples // batch_size,
    epochs=100,
    validation_data=validation_generator,
    validation_steps=validation_generator.samples // batch_size)
Epoch 1/100
281/281 [==============================] - 140s 498ms/step - loss: 0.6736 - acc: 0.5683 - val_loss: 0.6532 - val_acc: 0.6074
Epoch 2/100
281/281 [==============================] - 74s 262ms/step - loss: 0.6358 - acc: 0.6310 - val_loss: 0.5861 - val_acc: 0.6803
Epoch 3/100
281/281 [==============================] - 73s 261ms/step - loss: 0.6094 - acc: 0.6625 - val_loss: 0.5559 - val_acc: 0.7146
Epoch 4/100
281/281 [==============================] - 73s 261ms/step - loss: 0.5936 - acc: 0.6807 - val_loss: 0.5511 - val_acc: 0.7216
Epoch 5/100
281/281 [==============================] - 73s 260ms/step - loss: 0.5797 - acc: 0.6918 - val_loss: 0.5308 - val_acc: 0.7347
Epoch 6/100
281/281 [==============================] - 73s 261ms/step - loss: 0.5681 - acc: 0.7018 - val_loss: 0.5318 - val_acc: 0.7356
......
Epoch 96/100
281/281 [==============================] - 74s 264ms/step - loss: 0.2963 - acc: 0.8717 - val_loss: 0.3118 - val_acc: 0.8614
Epoch 97/100
281/281 [==============================] - 74s 263ms/step - loss: 0.2983 - acc: 0.8726 - val_loss: 0.2581 - val_acc: 0.8862
Epoch 98/100
281/281 [==============================] - 74s 263ms/step - loss: 0.2936 - acc: 0.8781 - val_loss: 0.2546 - val_acc: 0.8922
Epoch 99/100
281/281 [==============================] - 74s 263ms/step - loss: 0.3047 - acc: 0.8711 - val_loss: 0.2548 - val_acc: 0.8884
Epoch 100/100
281/281 [==============================] - 74s 263ms/step - loss: 0.3013 - acc: 0.8744 - val_loss: 0.2745 - val_acc: 0.8848

训练曲线:

技术图片

技术图片

用测试集对模型进行测试:

test_generator = test_datagen.flow_from_directory(
    test_dir,
    target_size=(150, 150),
    batch_size=batch_size,
    class_mode=binary)

test_loss, test_acc = model.evaluate_generator(test_generator, steps=test_generator.samples // batch_size)
print(test acc:, test_acc)
Found 2500 images belonging to 2 classes.
test acc: 0.9

 混淆矩阵:

技术图片

以上是关于Keras猫狗大战五:采用全部数据集训练,精度提高到90%的主要内容,如果未能解决你的问题,请参考以下文章

tfrecord数据集训练验证-猫狗大战

PyTorch 和 Albumentations 实现图像分类(猫狗大战)

训练时 Keras 神经网络精度始终为 0

py4CV例子1猫狗大战和Knn算法

Python分类实例之猫狗大战

DenseNet实战:tensorflow2.X版本,DenseNet121图像分类任务(小数据集)