Code Monkey home page Code Monkey logo

pytorch_image_classifier's Introduction

Image classfication

Easy-to-use/Easy-to-deploy/Easy-to-develop

图片名称 图片名称

*** example
models (efficientnet/mobilenet/resnest/seresnext等) 1
metric (Swish/ArcMarginProduct_subcenter/ArcFaceLossAdaptiveMargin/...) 2
data aug (rotate/flip/...、mixup/cutmix) 3
loss (ce_loss/ce_smothing_loss/focal_loss/bce_loss/...) 4
deploy (flask/grpc/BentoML等) 5
onnx/trt () 6

models:

RESNEST_LIST = ['resnest50', 'resnest101', 'resnest200', 'resnest269']

SERESNEXT_LIST = ['seresnext101']

GEFFNET_LIST = ['GenEfficientNet', 'mnasnet_050', 'mnasnet_075', 'mnasnet_100', 'mnasnet_b1', 'mnasnet_140', 'semnasnet_050', 'semnasnet_075', 'semnasnet_100', 'mnasnet_a1', 'semnasnet_140', 'mnasnet_small','mobilenetv2_100', 'mobilenetv2_140', 'mobilenetv2_110d', 'mobilenetv2_120d', 'fbnetc_100', 'spnasnet_100', 'efficientnet_b0', 'efficientnet_b1', 'efficientnet_b2', 'efficientnet_b3', 'efficientnet_b4', 'efficientnet_b5', 'efficientnet_b6', 'efficientnet_b7', 'efficientnet_b8', 'efficientnet_l2', 'efficientnet_es', 'efficientnet_em', 'efficientnet_el', 'efficientnet_cc_b0_4e', 'efficientnet_cc_b0_8e', 'efficientnet_cc_b1_8e', 'efficientnet_lite0', 'efficientnet_lite1', 'efficientnet_lite2', 'efficientnet_lite3', 'efficientnet_lite4', 'tf_efficientnet_b0', 'tf_efficientnet_b1', 'tf_efficientnet_b2', 'tf_efficientnet_b3', 'tf_efficientnet_b4', 'tf_efficientnet_b5', 'tf_efficientnet_b6', 'tf_efficientnet_b7', 'tf_efficientnet_b8', 'tf_efficientnet_b0_ap', 'tf_efficientnet_b1_ap', 'tf_efficientnet_b2_ap', 'tf_efficientnet_b3_ap', 'tf_efficientnet_b4_ap', 'tf_efficientnet_b5_ap', 'tf_efficientnet_b6_ap', 'tf_efficientnet_b7_ap', 'tf_efficientnet_b8_ap', 'tf_efficientnet_b0_ns', 'tf_efficientnet_b1_ns', 'tf_efficientnet_b2_ns', 'tf_efficientnet_b3_ns', 'tf_efficientnet_b4_ns', 'tf_efficientnet_b5_ns', 'tf_efficientnet_b6_ns', 'tf_efficientnet_b7_ns', 'tf_efficientnet_l2_ns', 'tf_efficientnet_l2_ns_475', 'tf_efficientnet_es', 'tf_efficientnet_em', 'tf_efficientnet_el', 'tf_efficientnet_cc_b0_4e', 'tf_efficientnet_cc_b0_8e', 'tf_efficientnet_cc_b1_8e', 'tf_efficientnet_lite0', 'tf_efficientnet_lite1', 'tf_efficientnet_lite2', 'tf_efficientnet_lite3', 'tf_efficientnet_lite4', 'mixnet_s', 'mixnet_m', 'mixnet_l', 'mixnet_xl', 'tf_mixnet_s', 'tf_mixnet_m', 'tf_mixnet_l', 'mobilenetv3_rw', 'mobilenetv3_large_075', 'mobilenetv3_large_100', 'mobilenetv3_large_minimal_100','mobilenetv3_small_075', 'mobilenetv3_small_100', 'mobilenetv3_small_minimal_100','tf_mobilenetv3_large_075', 'tf_mobilenetv3_large_100', 'tf_mobilenetv3_large_minimal_100','tf_mobilenetv3_small_075', 'tf_mobilenetv3_small_100', 'tf_mobilenetv3_small_minimal_100']

train/test/deploy

0、Data format transform

git clone https://github.com/MachineLP/PyTorch_image_classifier
pip install -r requirements.txt
cd PyTorch_image_classifier
python tools/data_preprocess.py --data_dir "./data/data.csv" --n_splits 5 --output_dir "./data/train.csv" --random_state 2020

resnest101

1、Modify configuration file

cp conf/resnest101.yaml conf/resnest101.yaml
vim conf/resnest101.yaml

2、Train:

python train.py --config_path conf/resnest101.yaml

3、Test

python test.py --config_path "conf/resnest101.yaml" --n_splits 5

4、Infer

    python infer.py --config_path "conf/resnest101.yaml" --img_path "./data/img/0male/0(2).jpg" --fold "0"
    pre>>>>> [1]
    python infer.py --config_path "conf/resnest101.yaml" --img_path "./data/img/1female/1(5).jpg" --fold "1"
    pre>>>>> [0]

5、Models transform ( https://github.com/NVIDIA-AI-IOT/torch2trt )(Tensorrt installation guide on Ubuntu1804)

    onnx:python tools/pytorch_to_onnx.py --config_path "conf/resnest101.yaml" --img_path "./data/img/0male/0(2).jpg" --batch_size 4 --fold 0 --save_path "lp.onnx"
    '''
    load model ok.....
    >>>>> [[-0.15416172  0.36190417]]
    cost time: 0.050855159759521484
    ==> Exporting model to ONNX format at 'lp.onnx'
    >>>>> (1, 3, 512, 512)
    preds>>>>> [array([[-0.15416166,  0.36190417]], dtype=float32)]
    cost time: 3.649467706680298
    error_distance: 2.9802322e-08
    '''

    tensorrt:python tools/onnx_to_tensorrt.py --config_path "conf/resnest101.yaml" --img_path "./data/img/0male/0(2).jpg" --batch_size 4 --fold 0 --save_path "lp_pp.onnx" --trt_save_path "lp.trt"
    '''
    outputs: tensor([[-0.1543,  0.3619]])
    tensor([0.6263]) tensor([1])
    '''

6、Deploying models serving

effb3_ns

1、Modify configuration file

cp conf/test.yaml conf/effb3_ns.yaml
vim conf/effb3_ns.yaml

2、Train:

python train.py --config_path "conf/effb3_ns.yaml"

3、Test

python test.py --config_path "conf/effb3_ns.yaml" --n_splits 5

4、Infer

    python infer.py --config_path "conf/effb3_ns.yaml" --img_path "./data/img/0male/0(2).jpg" --fold "0"
    pre>>>>> [1]
    python infer.py --config_path "conf/effb3_ns.yaml" --img_path "./data/img/1female/1(5).jpg" --fold "1"
    pre>>>>> [0]

5、Models transform ( https://github.com/NVIDIA-AI-IOT/torch2trt )(Tensorrt installation guide on Ubuntu1804)

    onnx:python tools/pytorch_to_onnx.py --config_path "conf/effb3_ns.yaml" --img_path "./data/img/0male/0(2).jpg" --batch_size 4 --fold 0 --save_path "lp.onnx"
    tensorrt:python tools/onnx_to_tensorrt.py

6、Deploying models serving

ref

(1)https://github.com/haqishen/SIIM-ISIC-Melanoma-Classification-1st-Place-Solution
(2)https://github.com/BADBADBADBOY/pytorchOCR
(3)https://github.com/MachineLP/QDServing
(4)https://github.com/bentoml/BentoML
(5)mixup-cutmix:https://blog.csdn.net/u014365862/article/details/104216086
(7)focalloss:https://blog.csdn.net/u014365862/article/details/104216192
(8)https://blog.csdn.net/u014365862/article/details/106728375 / https://blog.csdn.net/u014365862/article/details/106728402 

pytorch_image_classifier's People

Contributors

machinelp 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytorch_image_classifier's Issues

> Hello, I now want to use resnest to train my own image data set. What I do is image classification, but how to convert my image file into data.csv, because the data processing in the README is a bit unclear, I hope to get Thank you for your reply!

Hello, I now want to use resnest to train my own image data set. What I do is image classification, but how to convert my image file into data.csv, because the data processing in the README is a bit unclear, I hope to get Thank you for your reply!

Just convert your data to this format:https://github.com/MachineLP/PyTorch_image_classifier/blob/master/data/data.csv.
"filepath": The path of the image.
"target": The label of the image.
"fold": Not needed.

Originally posted by @MachineLP in #5 (comment)

ckpt_pb 导出 rnn模型失败

[libprotobuf FATAL google/protobuf/wire_format.cc:830] CHECK failed: (output->ByteCount()) == (expected_endpoint): : Protocol message serialized to a size different from what was originally expected. Perhaps it was modified by another thread during serialization?

train default dataset, acc unchange.

Fri Dec 11 22:08:15 2020 Fold 2, Epoch 11, lr: 0.0000849, train loss: 0.03911, valid loss: 0.00720, acc: 47.3684, auc: 0.500000.
Fri Dec 11 22:08:15 2020 Fold 2, Epoch 12
loss: 0.03136, smth: 0.02190: 100%|
100%|
Fri Dec 11 22:08:20 2020 Fold 2, Epoch 12, lr: 0.0000565, train loss: 0.02190, valid loss: 0.00529, acc: 47.3684, auc: 0.500000.
Fri Dec 11 22:08:20 2020 Fold 2, Epoch 13
loss: 0.00997, smth: 0.02012: 100%|
100%|
Fri Dec 11 22:08:24 2020 Fold 2, Epoch 13, lr: 0.0000327, train loss: 0.02012, valid loss: 0.00648, acc: 47.3684, auc: 0.500000.
Fri Dec 11 22:08:24 2020 Fold 2, Epoch 14
loss: 0.06338, smth: 0.05295: 100%|

Fri Dec 11 22:08:29 2020 Fold 2, Epoch 14, lr: 0.0000149, train loss: 0.05295, valid loss: 0.00702, acc: 47.3684, auc: 0.500000.
Fri Dec 11 22:08:29 2020 Fold 2, Epoch 15
loss: 0.00576, smth: 0.01205: 100%|
Fri Dec 11 22:08:35 2020 Fold 2, Epoch 15, lr: 0.0000038, train loss: 0.01205, valid loss: 0.00804, acc: 47.3684, auc: 0.500000.
77 19
Fri Dec 11 22:08:35 2020 Fold 3, Epoch 1
loss: 0.65180, smth: 0.65786: 100%|
Fri Dec 11 22:08:40 2020 Fold 3, Epoch 1, lr: 0.0000300, train loss: 0.65786, valid loss: 0.64426, acc: 47.3684, auc: 0.500000.

Question about model name

Hi!

Great work done here!
I‘m wondering how the model name combined, such as , what 'ns' in 'tf_efficientnet_b4_ns' means?
other like...
'es' in 'tf_efficientnet_es', 'ap' in ‘tf_efficientnet_b6_ap’, etc.

Really makes me confused...

Thank you!

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.