Code Monkey home page Code Monkey logo

dogs-vs-cats-pytorch's Introduction

dogs-VS-cats-pytorch

Pytorch实现Kaggle竞赛“猫狗分类”,准确率超过99%。

Kaggle网站:https://www.kaggle.com/c/dogs-vs-cats-redux-kernels-edition

数据集下载:

Step1:特征提取

使用feature_extract.py提取特征。

采用迁移学习的**,使用Pytorch预训练的模型“GoogLeNet”、“ResNet”和“ResNeXt”提取图像特征。

选择预训练模型的全局平均池化层的输出为新的特征,注意到对于每张图像,GoogLeNet提取到1024维特征;ResNet和ResNeXt提取到2048维特征;最后组合成5120维特征。

特征提取这一步比较花时间,这里提供了特征提取后的结果下载:

Step2:模型训练

使用train_test.py训练模型。

使用提取的特征作为输入进行二分类,直接用一个全连接层,输入5120维,输出2维(Softmax分类)。

使用Dropout,设置p=0.5。

训练速度相对于使用raw image就很快了,CPU上几秒完成。

Step3:结果预测

使用train_test.py预测结果。

模型训练好以后,就可以对测试集进行预测,然后提交到 kaggle 上查看最终成绩。

预测时使用了一个小技巧,将每个预测值限制到[0.005, 0.995]的区间内,这是由于kaggle官方的评估标准是LogLoss,对于预测正确的样本,0.995和1相差无几;但是对于预测错误的样本,0和0.005的差距是非常大的。

值得一提的是,使用ImageFolder读取文件是按照以下顺序(而不是顺序编号):

['test/1.jpg',
 'test/10.jpg',
 'test/100.jpg',
 'test/1000.jpg',
 'test/10000.jpg',
 'test/10001.jpg',
 'test/10002.jpg',
 'test/10003.jpg',
 ......

故需建立测试数据与预测结果之间的联系(见代码)。

dogs-vs-cats-pytorch's People

Contributors

0809zheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dogs-vs-cats-pytorch's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.