All Projects → lxztju → Pytorch_classification

lxztju / Pytorch_classification

Licence: mit
利用pytorch实现图像分类的一个完整的代码,训练,预测,TTA,模型融合,模型部署,cnn提取特征,svm或者随机森林等进行分类,模型蒸馏,一个完整的代码

Projects that are alternatives of or similar to Pytorch classification

Pytorch Image Classification
Tutorials on how to implement a few key architectures for image classification using PyTorch and TorchVision.
Stars: ✭ 272 (-31.14%)
Mutual labels:  jupyter-notebook, cnn, image-classification, resnet
Keras Idiomatic Programmer
Books, Presentations, Workshops, Notebook Labs, and Model Zoo for Software Engineers and Data Scientists wanting to learn the TF.Keras Machine Learning framework
Stars: ✭ 720 (+82.28%)
Mutual labels:  jupyter-notebook, resnet, densenet, resnext
Pytorch Cifar100
Practice on cifar100(ResNet, DenseNet, VGG, GoogleNet, InceptionV3, InceptionV4, Inception-ResNetv2, Xception, Resnet In Resnet, ResNext,ShuffleNet, ShuffleNetv2, MobileNet, MobileNetv2, SqueezeNet, NasNet, Residual Attention Network, SENet, WideResNet)
Stars: ✭ 2,423 (+513.42%)
Mutual labels:  image-classification, resnet, densenet, resnext
Basic cnns tensorflow2
A tensorflow2 implementation of some basic CNNs(MobileNetV1/V2/V3, EfficientNet, ResNeXt, InceptionV4, InceptionResNetV1/V2, SENet, SqueezeNet, DenseNet, ShuffleNetV2, ResNet).
Stars: ✭ 374 (-5.32%)
Mutual labels:  image-classification, resnet, densenet, resnext
Deep Learning With Python
Deep learning codes and projects using Python
Stars: ✭ 195 (-50.63%)
Mutual labels:  jupyter-notebook, cnn, image-classification, resnet
Awesome Computer Vision Models
A list of popular deep learning models related to classification, segmentation and detection problems
Stars: ✭ 278 (-29.62%)
Mutual labels:  image-classification, resnet, densenet
Segmentation models
Segmentation models with pretrained backbones. Keras and TensorFlow Keras.
Stars: ✭ 3,575 (+805.06%)
Mutual labels:  resnet, densenet, resnext
Tensorflow2.0 Examples
🙄 Difficult algorithm, Simple code.
Stars: ✭ 1,397 (+253.67%)
Mutual labels:  jupyter-notebook, image-classification, resnet
Image classifier
CNN image classifier implemented in Keras Notebook 🖼️.
Stars: ✭ 139 (-64.81%)
Mutual labels:  jupyter-notebook, cnn, image-classification
Video Classification
Tutorial for video classification/ action recognition using 3D CNN/ CNN+RNN on UCF101
Stars: ✭ 543 (+37.47%)
Mutual labels:  jupyter-notebook, cnn, resnet
Keras transfer cifar10
Object classification with CIFAR-10 using transfer learning
Stars: ✭ 120 (-69.62%)
Mutual labels:  jupyter-notebook, cnn, image-classification
Tianchi Medical Lungtumordetect
天池医疗AI大赛[第一季]:肺部结节智能诊断 UNet/VGG/Inception/ResNet/DenseNet
Stars: ✭ 314 (-20.51%)
Mutual labels:  jupyter-notebook, resnet, densenet
Machine Learning With Python
Python code for common Machine Learning Algorithms
Stars: ✭ 3,334 (+744.05%)
Mutual labels:  jupyter-notebook, svm, random-forest
Tensorflow cookbook
Code for Tensorflow Machine Learning Cookbook
Stars: ✭ 5,984 (+1414.94%)
Mutual labels:  jupyter-notebook, cnn, svm
Dogs vs cats
猫狗大战
Stars: ✭ 570 (+44.3%)
Mutual labels:  jupyter-notebook, image-classification, resnet
Snap N Eat
Food detection and recommendation with deep learning
Stars: ✭ 229 (-42.03%)
Mutual labels:  jupyter-notebook, flask, resnext
awesome-computer-vision-models
A list of popular deep learning models related to classification, segmentation and detection problems
Stars: ✭ 419 (+6.08%)
Mutual labels:  image-classification, densenet, resnet
Eeg Dl
A Deep Learning library for EEG Tasks (Signals) Classification, based on TensorFlow.
Stars: ✭ 165 (-58.23%)
Mutual labels:  cnn, resnet, densenet
Hyperparameter Optimization Of Machine Learning Algorithms
Implementation of hyperparameter optimization/tuning methods for machine learning & deep learning models (easy&clear)
Stars: ✭ 516 (+30.63%)
Mutual labels:  jupyter-notebook, svm, random-forest
pyro-vision
Computer vision library for wildfire detection
Stars: ✭ 33 (-91.65%)
Mutual labels:  image-classification, densenet, resnet

pytorch_classification

利用pytorch实现图像分类,其中包含的densenet,resnext,mobilenet,efficientnet, resnet等图像分类网络,可以根据需要再行利用torchvision扩展其他的分类算法

实现功能

  • 基础功能利用pytorch实现图像分类
  • 包含带有warmup的cosine学习率调整
  • warmup的step学习率优调整
  • 多模型融合预测,加权与投票融合
  • 利用flask实现模型云端api部署
  • 使用tta测试时增强进行预测
  • 添加label smooth的pytorch实现(标签平滑)
  • 添加使用cnn提取特征,并使用SVM,RF,MLP,KNN等分类器进行分类。
  • 更新添加了模型蒸馏的的训练方法
  • 添加中间层可视化
  • 更新模型部署(采用flask+Redis的方法)
  • c++ libtorch进行模型部署的简单demo

运行环境

  • python3.7
  • pytorch 1.1
  • torchvision 0.3.0

代码仓库的使用

数据集形式

原始数据集存储形式为,同个类别的图像存储在同一个文件夹下,所有类别的图像存储在一个主文件夹data下。

|-- data
    |-- train
        |--label1
            |--*.jpg
        |--label2
            |--*.jpg
        |--label    
            |--*.jpg
        ...

    |-- val
        |--*.jpg

利用preprocess.py将数据集格式进行转换(个人习惯这种数据集的方式)

python ./data/preprocess.py

转换后的数据集为,将训练集的路径与类别存储在train.txt文件中,测试机存储在val.txt中. 其中txt文件中的内容为

# train.txt

/home/xxx/data/train/label1/*.jpg   label

# val.txt

/home/xxx/data/train/label1/*.jpg
|-- data
    |-- train
        |--label1
            |--*.jpg
        |--label2
            |--*.jpg
        |--label    
            |--*.jpg
        ...

    |-- val
        |--*.jpg
    |--train.txt
    |--val.txt

模型介绍

仓库中模型densenet,mobilenet,resnext模型来自于torchvision

efficientnet来自于 https://github.com/lukemelas/EfficientNet-PyTorch

训练

  • cfg.py中修改合适的参数,并在train.py中选择合适的模型
##数据集的类别
NUM_CLASSES = 206

#训练时batch的大小
BATCH_SIZE = 32

#网络默认输入图像的大小
INPUT_SIZE = 300
#训练最多的epoch
MAX_EPOCH = 100
# 使用gpu的数目
GPUS = 2
# 从第几个epoch开始resume训练,如果为0,从头开始
RESUME_EPOCH = 0

WEIGHT_DECAY = 5e-4
MOMENTUM = 0.9
# 初始学习率
LR = 1e-3
# 训练好模型的保存位置
SAVE_FOLDER = './weights'

# 采用的模型名称
model_name = 'resnext101_32x32d'
python train.py

预测

在cfg.py中TRAINED_MODEL参数修改为指定的权重文件存储位置,在predict文件中可以选定是否使用tta

python predict.py
  • 当训练完成多模型之后生成多个txt文件之后,利用ensamble文件夹中的kaggle_vote.py进行投票融合或者加权投票融合。

将每个模型生成的csv文件,移动到ensamble/samples/然后将每个文件命名为method1.py,method2.py. 然后运行如下命令进行投票融合

python ./kaggle_vote.py "./samples/method*.csv" "./samples/vote.csv"

cnn + svm

代码存在于cnn_ml.py中, 利用训练好的cnn特征提取器,将得到的特征保存为pkl文件,然后训练svm分类器, 并将分类器模型保存,然后读取预测

主要需要修改的就是根据不同模型的输出特征向量的大小在cnn_ml.py中修改NB_features对应的大小

flask云端部署

将训练存储好的权重文件,存储在flask_deployment文件夹中

然后修改server.py中路径运行即可 利用client.py进行调用

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].