Getting Started with Kaggle Competitions Using Monk AI
Last Updated on May 15, 2020 by Editorial Team
Author(s): sinchana S.R
Deep Learning
Monk is a low code deep learning tool and a suitable wrapper for computerΒ vision.
Monk Features
- Low-code.
- Unified wrapper over major deep learning framework sβββKeras, PyTorch,Β gluoncv.
- Syntax invariant wrapper.
Monk Enables
- To create, manage, and version control deep learning experiments.
- To compare experiments across trainingΒ metrics.
- To quickly find the best hyperparameters.
Goals
- To experiment withΒ Models.
- Understand how easy is it to useΒ Monk.
Table ofΒ contents
- About theΒ dataset.
- Installation.
- Importing PytorchΒ Backend.
- Creating and managing experiments.
- List of all the available models.
- Training a Pneumonia Vs. Normal image classifier.
- Quick mode training.
- Validating the trained classifier.
- Running inference on testΒ images.
About theΒ dataset
License: CC BYΒ 4.0
Paper: http://www.cell.com/cell/fulltext/S0092-8674(18)30154-5
Dataset structure
The dataset is organized into three folders (train, test, val) and contains subfolders for each image category (Pneumonia/Normal). There are 5,863 X-Ray images (JPEG) and two categories (Pneumonia/Normal).
Train
-----Normal
-----Pneumonia
Test
-----Normal
-----Pneumonia
Validation
-----Normal
-----Pneumonia
Installation
Setting up MONK and its dependencies:
$ !git clone https://github.com/Tessellate-Imaging/monk_v1.git
$ !cd monk_v1/installation/Misc && pip install -r requirements_kaggle.txt
Since I am using Kaggle, I installed Kaggle dependencies.
If you are LinuxΒ user
$ cd monk_v1/installation/Linux && pip install -r requirements_cu9.txt
(Select the requirements file as per OS and CUDAΒ version)
If using Colab install using the commandsΒ below
$ cd monk_v1/installation/Misc && pip install -r requirements_colab.txt
If using Kaggle uncomment the following command
$ cd monk_v1/installation/Misc && pip install -r requirements_kaggle.txt
You can find the installation procedure here.
MONK supports PyTorch, Keras, and mxnet-gluon backends.
Importing PytorchΒ Backend
#Using pytorch backend
$ from pytorch_prototype import prototype
- To use mxnetΒ backend
$ from gluon_prototype import prototype
- To use KerasΒ backend
$ from keras_prototype import prototype
Creating and managing experiments
- Provide a projectΒ name
- Provide an experiment name
- For specific data create a singleΒ project
- Inside each project, multiple experiments can beΒ created
- Every experiment can have different hyper-parameters attached toΒ it
$ gtf = prototype(verbose=1);
$ gtf.Prototype("PneumoniaClassificationMONK", "UsingPytorchBackend");
This creates files and directories as per the following structure workspace
|
|--------PneumoniaClassificationMONK (Project name can be different)
|
|
|-----UsingPytorchBackend (Experiment name can be different)
|
|-----experiment-state.json
|
|-----output
|
|------logs (All training logs and graphs saved here)
|
|------models (all trained models saved here)
List of all the available models
$ gtf.List_Models()
You can also find the list of available models, layers, blocks, optimizers here.
Training a Pneumonia vs. Normal image classifier
Quick modeΒ training
- Using the DefaultΒ Function
- dataset_path
- model_name
- num_epochs
Dataset folder structure parent_directory
|
|
|------Pneumonia
|
|------img1.jpg
|------img2.jpg
|------.... (and so on)
|------Normal
|
|------img1.jpg
|------img2.jpg
|------.... (and so on)
So for quick mode training,
$ gtf.Default(dataset_path="/kaggle/input/chest-xray-pneumonia/chest_xray/train",
model_name="resnet50",
freeze_base_network=False,
num_epochs=25);
You can also find update mode and expert mode training.
Training the classifier
$ gtf.Train();
I trained my model for 25 epochs. After the end of the training, you can read theΒ summary:
Validating the trained classifier
Load the experiment in validation mode
- Set flag eval_infer asΒ True
$ gtf = prototype(verbose=1);
$ gtf.Prototype("PneumoniaClassificationMONK", "UsingPytorchBackend",eval_infer=True);
Load the validation dataset
$ gtf.Dataset_Params(dataset_path="/kaggle/input/chest-xray-pneumonia/chest_xray/val");
$ gtf.Dataset();
Run validation
$ accuracy, class_based_accuracy = gtf.Evaluate();
Running inference on testΒ images
Load the experiment in inference mode
- Set flag eval_infer asΒ True
$ gtf = prototype(verbose=1);
$ gtf.Prototype("PneumoniaClassificationMONK", "UsingPytorchBackend",eval_infer=True);
Select image and Run inference
$ img_name = "/kaggle/input/chest-xray-pneumonia/chest_xray/test/NORMAL/IM-0005-0001.jpeg";
$ predictions = gtf.Infer(img_name=img_name);
Training v/s Validation AccuracyΒ Curves
$ from IPython.display import Image
$ Image(filename="/kaggle/working/workspace/PneumoniaClassificationMONK/UsingPytorchBackend/output/logs/train_val_accuracy.png")
Similarly, we can obtain Training v/s Validation lossΒ Curves.
You can find the starter code on KaggleβsΒ website.
Resources
A one-stop repository for low-code easily-installable object detection pipelines.
A Graphical User Interface for deep learning and computer vision over Monk Libraries.
A set of jupyter notebooks on PyTorch functions with examples.
I am an open-source contributor to the monk library. If you have any issues, please feel free to open an issue onΒ GitHub.
Getting Started with Kaggle Competitions Using Monk AI was originally published in Towards AIβββMultidisciplinary Science Journal on Medium, where people are continuing the conversation by highlighting and responding to this story.
Published via Towards AI