Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

Getting Started with Kaggle Competitions Using Monk AI
Data Science   Machine Learning   Tutorials

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

Data: https://data.mendeley.com/datasets/rscbjbr9sj/2

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

Monk_Object_Detection

A one-stop repository for low-code easily-installable object detection pipelines.

Monk_Gui

A Graphical User Interface for deep learning and computer vision over Monk Libraries.

Pytorch_Tutorial

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

Feedback ↓