In this guide, we are demonstrating a Deep Learning model-based image classification problem using the popular Fashion-MNIST dataset. The deep learning model will be trained to classify images of clothing, like sneakers and t-shirts, a total of 10 labels.
Although the dataset is relatively simple, it can be used as the basis for learning and practicing how to develop, train, and use neural networks on RazorThink Platform from scratch.
This dataset has 60,000 small squares, and 28×28 pixel grayscale images of 10 different types of clothing, such as shoes, t-shirts, dresses, and more. The mapping of all 0-9 integers to class labels and sample data is depicted in the image below.
The following tutorial will mainly walk you through:
- Create a Block to read the data file for DL model training and DL model inference
- Create a Block to write the Deep Learning model prediction results to a file
- How to visually create a Deep Learning model using RazorThink Platform
- How to use a DL model for training or prediction
- How to build a Pipeline with Blocks and DL model
Preparing the dataset:
We are getting the dataset from Keras APIs. Basically there are 2 files with image data, ‘data_train.npz’ will be used for training the model and ‘data_test.npz’ will be used for prediction.
How to build this use case on RazorThink Platform:
We will be building the model for this project using RazorThink Platform DL model designer and will create two custom blocks, one to read the file and another one to write the output to a file. In total, we will be
- Create a project from the RazorThink Platform homepage, we'll name it ‘Fashion MNIST classification”. You can provide it with a description you would like.
- Click on the Project you just created and once you are inside, click on the “data” icon on the left side panel. Here you’ll see the “Open Jupyter Lab” button on the top right corner. Click on that. It will open an instance of Jupyter Lab for you. Now, create a Python Jupyter Notebook.
- Let's start with the import statements
- Setting up the data:
1. You can upload the data in your project-space directly if you have that in your local computer or you can use Keras API like we have, to get the dataset.
2. And then you can save it in your project-space using the following command.
- We have two levels of hierarchy for blocks, org and project. The blocks which are published as “org” blocks will be available for all the projects in your organisation account, and “project” blocks will be available only inside that particular project.
- We will be creating a project level block in this tutorial. We go inside the project folder and create our Python bundle (bundle is basically how we are grouping our blocks in a category to have a proper hierarchy).
- We will create an “ImageClassificationV1” bundle for now.
- Then we’ll go inside our bundle folder and create a python file to write our block code. Here, the python file name is “fashionmnist.py”.
- Then import RZT aiOS SDK libraries to create blocks.
- We can now write our first custom block which we will use to read input files from Project Space. You can use this Block to read any numpy files from Project Space as well. This block takes two inputs, one is the path URL of string type and other is for number of examples/samples to read from the numpy file which is of integer type and has one output data.
- We will now define a class “LoadImages” which we will use to load our images data file from Project Space. Add necessary details for the block, and write to your code inside the run function.
- Similarly we will create another block to write the output data as a CSV file, configure its input and output, add details and then add our code inside run function. Again, you can reuse this Block to write any CSV file into Project Space.
- Then we go inside our “__init__.py” file inside the bundle folder and import our blocks.
- Then you can publish your bundle anywhere inside your project space in jupyter lab.
- Now that we have our read and write blocks published, we can create our model. Click on the “DL model designer” in the right panel, and add a model name. For example, we are naming it “new_model”.
- Open “new_model” and start building your model with existing components like layers, metrics, optimizers et al and build your model.
- Now that we have our model we can build our train pipeline. Click on pipelines on left side panel and create you pipeline. We’ll name it “Classification model train”.
- Drag out your custom block “LoadImages” to load the file, then drag the block “DLTrainBlock” for training. Add the input path and other parameters add your model in DLTrainBlock. Click on play icon to start training the model after adding an engine you want to run it on.
- Now that you made the run, you can see progress on in pipeline runs, to get more details on the run you can click on that particular run and see that.
- Once we’re done training your model we can run inference on it. Go back to the pipelines and create a new pipeline to run inference. We’ll name it “classification prediction”.
- Again drag out your custom block “LoadImages” to load the images along with “SavePredsV2” to save the prediction, drag out “DLInferBlock” and add your trained model.
- Similarly for this run also you can get block wise details in the pipeline runs.
Cheers! You have successfully trained a model and have a pipeline to run predictions on the trained model using RazorThink Platform.