Repository containing Keras code for the blog post titled "How to Perform Multi Label Classification using Deep Learning". You can checkout the blog post here.
This section lists out the steps involved in training a Keras model (with TensorFlow backend) for Multi Label Classification.
- You can explore this notebook on Colab to directly experiment with training the models.
Follow these steps to train and use a model for Multilabel Classification. You can also directly use a sample trained model (mobilenet.h5
) without training, which can be downloaded from here (skip to Step 4 in that case).
git clone https://github.com/thatbrguy/Multilabel-Classification.git
cd Multilabel-Classification
- Download data.tar.gz and place it in the current directory.
- Extract the dataset using
tar -xzvf data.tar.gz
- Move the contents of
./data/keras/
to the current directory by usingmv ./data/keras/* ./
- Run
train.py --model ResNet50
to train the model. - The
--model
argument can take one amongResNet50
,MobileNet
,DenseNet121
orXception
.
- Run
predict.py --image PATH_TO_FILE --saved_model PATH_TO_h5
to obtain a prediction once the model is trained. PATH_TO_FILE
refers to the path of the image.PATH_TO_h5
refers to the path of the h5 file.
This section lists out the steps involved in training a Nanonets model for Multi Label Classification.
git clone https://github.com/thatbrguy/Multilabel-Classification.git
cd Multilabel-Classification/nanonets
Get your free API Key from http://app.nanonets.com/user/api_key
export NANONETS_API_KEY=YOUR_API_KEY_GOES_HERE
python ./code/create_model.py
_Note: This generates a MODEL_ID that you need for the next step
export NANONETS_MODEL_ID=YOUR_MODEL_ID
_Note: you will get YOUR_MODEL_ID from the previous step
- Download data.tar.gz and place it in the current directory.
- Extract the dataset using
tar -xzvf data.tar.gz
- Move the contents of
./data/nanonets/
to the current directory by usingmv ./data/nanonets/* ./
- Run
python ./code/upload_training.py
to upload the data.
Once the Images have been uploaded, begin training the Model
python ./code/train_model.py
The model takes ~2 hours to train. You will get an email once the model is trained. In the meanwhile you check the state of the model
python ./code/model_state.py
Once the model is trained. You can make predictions using the model
python ./code/prediction.py PATH_TO_YOUR_IMAGE.jpg
Sample Usage:
python ./code/prediction.py ./multilabel_data/ImageSets/2_my_caesar_salad_hostedLargeUrl.jpg