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.

Data Overview:

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

    import numpy as np

    import pandas as pd

    import matplotlib.pyplot as plt

    import razor.flow as rf

    from razor.flow import Pipeline

    from razor.api import project_space_path

    import typing as t

    from typing import Any

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

from tensorflow.keras.datasets.fashion_mnist import load_data

(x1, y1), (x2, y2)= load_data()


                    2. And then you can save it in your project-space using the following command.

from razor.api import project_space_path

np.savez(project_space_path('data_train.npz'), images=x1, labels=y1)

np.savez(project_space_path('data_test.npz'), images=x2, labels=y2)

  • 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 “”.

  • Then import RZT aiOS SDK libraries to create blocks.

from razor import Block, inputs, outputs, Pipeline

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


class LoadImages:

    path: str

    no_of_examples: int

    data: rf.SeriesOutput[dict]


    __label__ = "Load NPZ Images"

    __description__ = "Load NPX images from a Project Space path"

    __tags__ = []

    __publish__ = True

    __category__ = "Image Classification"


    from razor.api import project_space_path

    def run(self):

        self.logger.debug('Running Load Images')


        npy = np.load(project_space_path(self.path))


        for image, label in zip(npy['images'][:self.no_of_examples], npy['labels'][:self.no_of_examples]):

            image = image.astype('float32') / 255.0

            label = np.eye(10)[[label]].reshape(-1)

            image = np.reshape(image, (image.shape[0], image.shape[1], 1))


  {"images":image, "labels":label})


        self.logger.debug('Completed Load Images')

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


class SavePreds:

    preds: rf.SeriesInput[Any]

    path: str

    __label__ = "Save CSV File"

    __description__ = "Save CSV file to Project space"

    __tags__ = []

    __publish__ = True

    __category__ = "Image Classification"

    def run(self):

        import os

        import pandas as pd

        import numpy as np

        y_true = []

        y_hats = [] 

        if os.path.exists(project_space_path(self.path)):



        for batch in self.preds:

            y_true.extend(list(np.argmax(batch['labels'], axis=1)))


        df = pd.DataFrame({'true class':y_true, 'predicted class':y_hats}).to_csv(project_space_path(self.path), index=False, mode='a')


  • Then we go inside our “” file inside the bundle folder and import our blocks.

from .fashionmnist import LoadImages, SavePreds

from razor.platform.setuptools import block_setup

__metadata__ = block_setup(version="0.0.1")


  • Then you can publish your bundle anywhere inside your project space in jupyter lab.

import razor

razor.platform.publish_project_blocks(bundle='ImageClassificationV1', overwrite=True)


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