All Projects → floydhub → Imagenet

floydhub / Imagenet

Licence: bsd-3-clause
Pytorch Imagenet Models Example + Transfer Learning (and fine-tuning)

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Imagenet

Classification models
Classification models trained on ImageNet. Keras.
Stars: ✭ 938 (+600%)
Mutual labels:  resnet, pretrained-models, densenet, vgg
Chainer Cifar10
Various CNN models for CIFAR10 with Chainer
Stars: ✭ 134 (+0%)
Mutual labels:  convolutional-neural-networks, resnet, densenet, vgg
python cv AI ML
用python做计算机视觉,人工智能,机器学习,深度学习等
Stars: ✭ 73 (-45.52%)
Mutual labels:  vgg, densenet, resnet
Tensornets
High level network definitions with pre-trained weights in TensorFlow
Stars: ✭ 982 (+632.84%)
Mutual labels:  resnet, densenet, vgg
sparsezoo
Neural network model repository for highly sparse and sparse-quantized models with matching sparsification recipes
Stars: ✭ 264 (+97.01%)
Mutual labels:  resnet, transfer-learning, pretrained-models
Pytorch Image Classification
Tutorials on how to implement a few key architectures for image classification using PyTorch and TorchVision.
Stars: ✭ 272 (+102.99%)
Mutual labels:  convolutional-neural-networks, resnet, vgg
Cnn Models
ImageNet pre-trained models with batch normalization for the Caffe framework
Stars: ✭ 355 (+164.93%)
Mutual labels:  resnet, pretrained-models, vgg
Tianchi Medical Lungtumordetect
天池医疗AI大赛[第一季]:肺部结节智能诊断 UNet/VGG/Inception/ResNet/DenseNet
Stars: ✭ 314 (+134.33%)
Mutual labels:  resnet, densenet, vgg
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 (+437.31%)
Mutual labels:  resnet, densenet, vgg
Imagenet
This implements training of popular model architectures, such as AlexNet, ResNet and VGG on the ImageNet dataset(Now we supported alexnet, vgg, resnet, squeezenet, densenet)
Stars: ✭ 126 (-5.97%)
Mutual labels:  resnet, densenet, vgg
Pytorch Image Models
PyTorch image models, scripts, pretrained weights -- ResNet, ResNeXT, EfficientNet, EfficientNetV2, NFNet, Vision Transformer, MixNet, MobileNet-V3/V2, RegNet, DPN, CSPNet, and more
Stars: ✭ 15,232 (+11267.16%)
Mutual labels:  resnet, pretrained-models
Big transfer
Official repository for the "Big Transfer (BiT): General Visual Representation Learning" paper.
Stars: ✭ 1,096 (+717.91%)
Mutual labels:  convolutional-neural-networks, transfer-learning
Cyclegan Qp
Official PyTorch implementation of "Artist Style Transfer Via Quadratic Potential"
Stars: ✭ 59 (-55.97%)
Mutual labels:  convolutional-neural-networks, resnet
Deep Ranking
Learning Fine-grained Image Similarity with Deep Ranking is a novel application of neural networks, where the authors use a new multi scale architecture combined with a triplet loss to create a neural network that is able to perform image search. This repository is a simplified implementation of the same
Stars: ✭ 64 (-52.24%)
Mutual labels:  convolutional-neural-networks, resnet
Pytorch Speech Commands
Speech commands recognition with PyTorch
Stars: ✭ 128 (-4.48%)
Mutual labels:  resnet, densenet
Teacher Student Training
This repository stores the files used for my summer internship's work on "teacher-student learning", an experimental method for training deep neural networks using a trained teacher model.
Stars: ✭ 34 (-74.63%)
Mutual labels:  convolutional-neural-networks, transfer-learning
Farm
🏡 Fast & easy transfer learning for NLP. Harvesting language models for the industry. Focus on Question Answering.
Stars: ✭ 1,140 (+750.75%)
Mutual labels:  transfer-learning, pretrained-models
Gluon2pytorch
Gluon to PyTorch deep neural network model converter
Stars: ✭ 70 (-47.76%)
Mutual labels:  resnet, densenet
Vgg16 Pytorch
VGG16 Net implementation from PyTorch Examples scripts for ImageNet dataset
Stars: ✭ 26 (-80.6%)
Mutual labels:  resnet, vgg
Sru Deeplearning Workshop
دوره 12 ساعته یادگیری عمیق با چارچوب Keras
Stars: ✭ 66 (-50.75%)
Mutual labels:  convolutional-neural-networks, transfer-learning

Traning and Transfer Learning ImageNet model in Pytorch

This project implements:

  • Training of popular model architectures, such as ResNet, AlexNet, and VGG on the ImageNet dataset;
  • Transfer learning from the most popular model architectures of above, fine tuning only the last fully connected layer.

Note:

  • ImageNet training will be documeted in the next release.
  • Transfer-learning was fully tested on alexnet, densenet121, inception_v3, resnet18 and vgg19. The other models will be tested in the next release.

Usage

usage: main.py [-h] [--data DIR] [--outf OUTF] [--evalf EVALF] [--arch ARCH]
               [-j N] [--epochs N] [--start-epoch N] [-b N] [--lr LR]
               [--momentum M] [--weight-decay W] [--print-freq N]
               [--resume PATH] [-e] [--train] [--test] [-t] [--pretrained]
               [--world-size WORLD_SIZE] [--dist-url DIST_URL]
               [--dist-backend DIST_BACKEND]

PyTorch ImageNet Training

optional arguments:
  -h, --help            show this help message and exit
  --data DIR            path to dataset
  --outf OUTF           folder to output model checkpoints
  --evalf EVALF         path to evaluate sample
  --arch ARCH, -a ARCH  model architecture: alexnet | densenet121 |
                        densenet161 | densenet169 | densenet201 | inception_v3
                        | resnet101 | resnet152 | resnet18 | resnet34 |
                        resnet50 | squeezenet1_0 | squeezenet1_1 | vgg11 |
                        vgg11_bn | vgg13 | vgg13_bn | vgg16 | vgg16_bn | vgg19
                        | vgg19_bn (default: resnet18)
  -j N, --workers N     number of data loading workers (default: 4)
  --epochs N            number of total epochs to run
  --start-epoch N       manual epoch number (useful on restarts)
  -b N, --batch-size N  mini-batch size (default: 256)
  --lr LR, --learning-rate LR
                        initial learning rate
  --momentum M          momentum
  --weight-decay W, --wd W
                        weight decay (default: 1e-4)
  --print-freq N, -p N  print frequency (default: 10)
  --resume PATH         path to latest checkpoint (default: none)
  -e, --evaluate        evaluate model on validation set
  --train               train the model
  --test                test a [pre]trained model on new images
  -t, --fine-tuning
                        transfer learning enabled + fine tuning - train only the last FC
                        layer.
  --pretrained          use pre-trained model
  --world-size WORLD_SIZE
                        number of distributed processes
  --dist-url DIST_URL   url used to set up distributed training
  --dist-backend DIST_BACKEND
                        distributed backend

ImageNet models Architecture

Alexnet

alexnet architecture

Credit: Imagenet classification with deep convolutional neural networks paper

Densenet

densenet architecture

Credit: Densely Connected Convolutional Networks

Inception_v3

inception_v3 architecture

Credit: Rethinking the Inception Architecture for Computer Vision paper (image taken from google research blog)

Resnet34

Resnet architecture

Credit: Deep Residual Learning for Image Recognition paper

Squeezenet1_0

Squeezenet architecture

Credit: Squeezenet: Alexnet-level accuracy with 50x fewer parameters and <0.5MB model size

Vgg19net

vgg19 architecture

Credit: Very Deep Convolutional Networks For Large-Scale Image Recognition paper (image taken from Resnet paper)

ImageNet training in PyTorch

imagenet dataset tsne visualization

Credit: karpathy.github.io

This project implements the ImageNet classification task on ImageNet dataset with different famous Convolutional Neural Network(CNN or ConvNet) models. This is a porting of pytorch/examples/imagenet making it usables on FloydHub.

Requirement

Download the ImageNet dataset and move validation images to labeled subfolders. Unfortunately at the moment the imagenet is not fully supported as torchvision.dataset, so we need to use the ImageFolder API which expects to load the dataset from a structure of this type:

ls /dataset

train
val
test

# Train
ls /dataset/train
cat
dog
tiger
plane
...

ls /dataset/train/cat
cat01.png
cat02.png
...

ls /dataset/train/dog
dog01.jpg
dog02.jpg
...
...[others classification folders]

# Val
ls /dataset/val
cat
dog
tiger
plane
...

ls /dataset/val/cat
cat01.png
cat02.png
...

ls /dataset/val/dog
dog01.jpg
dog02.jpg
...

# Test
ls /dataset/test
images

ls /dataset/test/images
test01.png
test02.png
...

Once you have build the dataset following the steps above, upload it as FloydHub dataset following this guide: create and upload FloydHub dataset.

Run on FloydHub

Here's the commands to train and evaluate your [pretrained] model on FloydHub(these section will be improved with the next release):

Project Setup

Before you start, log in on FloydHub with the floyd login command, then fork and init the project:

$ git clone https://github.com/floydhub/imagenet.git
$ cd imagenet
$ floyd init imagenet

Training

To train a model, run main.py with the desired model architecture and the path to the ImageNet dataset:

floyd run --gpu --data <your_user_name>/datasets/imagenet/<version>:input "python main.py -a resnet18 [other params]"

The default learning rate schedule starts at 0.1 and decays by a factor of 10 every 30 epochs. This is appropriate for ResNet and models with batch normalization, but too high for AlexNet and VGG. Use 0.01 as the initial learning rate for AlexNet or VGG:

floyd run --gpu --data <your_user_name>/datasets/imagenet/<version>:input "python main.py -a <arch> --lr 0.01 [other params]"

Note:

A full training on Imagenet can takes weeks according to the selected model.

Evaluating

It's time to evaluate our model with some images(put the images you want to classify in the test/images folder):

floyd run --gpu --env pytorch-0.2 --data <your_user_name>/datasets/imagenet/<version>:input --data <REPLACE_WITH_JOB_OUTPUT_NAME>:model "python main.py -a <arch> --test  --evalf test/ --resume /model/model_best.pth.tar"

#### Try Pytorch Pretrained model

Pytorch provided to you pretrained model for different models, if you want to evaluate your dataset with one of this model run:

```bash
floyd run --gpu --data <your_user_name>/datasets/<test_image>/<version>:input "python main.py -a [arch] --pretrained --data /input/test [other params]"

Serve model through REST API

FloydHub supports seving mode for demo and testing purpose. Before serving your model through REST API, you need to create a floyd_requirements.txt and declare the flask requirement in it. If you run a job with --mode serve flag, FloydHub will run the app.py file in your project and attach it to a dynamic service endpoint:

floyd run --gpu --mode serve --env pytorch-0.2  --data <your_user_name>/datasets/<test_image>/<version>:input --data <REPLACE_WITH_JOB_OUTPUT_NAME>:model

Note: The script retrieve the number of classes from the dataset --data <your_user_name>/datasets/<test_image>/<version>. This behavior will be fixed in the next release.

The above command will print out a service endpoint for this job in your terminal console.

The service endpoint will take a couple minutes to become ready. Once it's up, you can interact with the model by sending an image file with a POST request that the model will classify(according to ImageNet labels):

# Template
# curl -X POST -F "[email protected]<IMAGE>" <SERVICE_ENDPOINT>

# e.g. of a POST req
curl -X POST -F "[email protected]/test/images/test01.png"  https://www.floydlabs.com/expose/BhZCFAKom6Z8RptVKskHZW

Any job running in serving mode will stay up until it reaches maximum runtime. So once you are done testing, remember to shutdown the job!

Note that this feature is in preview mode and is not production ready yet

Transfer Learning

Bees Vs Ants dataset

This project implements the a Transfer Learning classification task on the Bees Vs Ants toy dataset(train: 124 images of ants and 121 images of bees, val: 70 images of ants and 83 images of bees) with different Convolutional Neural Network(CNN or ConvNet) models. This is a porting of the transfer learning tutorial from the official PyTorch Docs making it usables on FloydHub.

Credit: Sasank Chilamkurthy who has written the amazing tutorial on transfer learning in the PyTorch docs.

Run on FloydHub

Here's the commands to train and evaluate your [pretrained] model on FloydHub(these section will be improved with the next release):

Project Setup

Before you start, log in on FloydHub with the floyd login command, then fork and init the project:

$ git clone https://github.com/floydhub/imagenet.git
$ cd imagenet
$ floyd init imagenet

Training

I have already uploaded it as FloydHub dataset so that you can try and familiarize with --data parameter which mounts the specified volume(datasets/model) inside the container of your FloydHub instance. Now it's time to run our training on FloydHub. In this example we will train the model for 10 epochs with a gpu instance. Note: If you want to mount/create a dataset look at the docs.

floyd run --gpu --env pytorch-0.2 --data redeipirati/datasets/pytorch-hymenoptera/1:input "python main.py -a resnet18 --train --fine-tuning --pretrained --epochs 10 -b 4"

Note:

  • --gpu run your job on a FloydHub GPU instance
  • --env pytorch-0.2 prepares a pytorch environment for python 3.
  • --data redeipirati/datasets/pytorch-hymenoptera/1 mounts the pytorch hymenoptera dataset(bees vs ants) in the /input folder inside the container for our job so that we do not need to dowload it at training time.

Evaluating

It's time to evaluate our model with some images:

floyd run --gpu --env pytorch-0.2 --data redeipirati/datasets/pytorch-hymenoptera/1:input --data <REPLACE_WITH_JOB_OUTPUT_NAME>:model "python main.py -a resnet18 --test --fine-tuning  --evalf test/ --resume /model/model_best.pth.tar"

Notes:

  • I've prepared for you some images in the test folder that you can use to evaluate your model. Feel free to add on it a bunch of bee/ant images downloaded from the web.
  • Remember to evaluate images which are taken from a similar distribution, otherwise you will have bad performance due to distribution mismatch.

Try our pre-trained model

We have provided to you a pre-trained model trained for 30 epochs with an accuracy of about 95%.

floyd run --gpu --env pytorch-0.2 --data redeipirati/datasets/pytorch-hymenoptera/1:input --data redeipirati/datasets/pytorch-hymenoptera-30-epochs-resnet18-model/1:model "python main.py -a resnet18 --test --fine-tuning  --evalf test/ --resume /model/model_best.pth.tar"

Serve model through REST API

FloydHub supports seving mode for demo and testing purpose. Before serving your model through REST API, you need to create a floyd_requirements.txt and declare the flask requirement in it. If you run a job with --mode serve flag, FloydHub will run the app.py file in your project and attach it to a dynamic service endpoint:

floyd run --gpu --mode serve --env pytorch-0.2  --data redeipirati/datasets/pytorch-hymenoptera/1:input --data <REPLACE_WITH_JOB_OUTPUT_NAME>:model

Note: The script retrieve the number of classes from the dataset --data redeipirati/datasets/pytorch-hymenoptera/1. This behavior will be fixed in the next release.

The above command will print out a service endpoint for this job in your terminal console.

The service endpoint will take a couple minutes to become ready. Once it's up, you can interact with the model by sending an images(of ant or bee) file with a POST request that the model will classify:

# Template
# curl -X POST -F "[email protected]<ANT_OR_BEE>" <SERVICE_ENDPOINT>

# e.g. of a POST req
curl -X POST -F "[email protected]/test/images/test01.png"  https://www.floydlabs.com/expose/BhZCFAKom6Z8RptVKskHZW

Any job running in serving mode will stay up until it reaches maximum runtime. So once you are done testing, remember to shutdown the job!

Note that this feature is in preview mode and is not production ready yet

More resources

Some useful resources on ImageNet and the famous ConvNet models:

Contributing

For any questions, bug(even typos) and/or features requests do not hesitate to contact me or open an issue!

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