#
Home Pets Categorizer
In this tutorial, you will build a classifier model to recognize pets - cats and dogs, in photos and video frames.
You will learn how to:
- add a dataset,
- create and train your model with Keras,
- test your classifier's performance in real-time.
To train the model, use the publicly available collection of 25,000 cat and dog photos provided by Microsoft.
#
Adding the dataset
To upload your images collection, navigate to the Datasets view:
#
Upload images
As this is your first visit, you do not have a collection of images yet. Start by adding the first one. To do this, select Add new dataset and give it a name.
Keep in mind: The name must be a string of letters, digits and spaces.
To load images into the application, you can drag and drop them, or:
- load the whole directory including its subdirectories Add directory,
- load selected files Add files,
- upload .zip folder Add ZIP.
Let's say you have uploaded your images from the PetImages
directory, which contains subdirectories. The application will use the subdirectory names to create two classification categories: Cat
and Dog
.
*Read more about the logic adopted in the One Step AI service for loading images and their automatic categorization based on the directory structure. Upload
When you select a directory, OSAI searches for images in it and displays the thumbnails in a gallery.
You can browse through the images as they load and delete those you do not need.
The ALL, ANNOTATED, CLASSIFIED, DOG, CAT tabs visible in the gallery view show how the collection was divided using the automatic analysis - classes in the classification process and objects in the detection process.
Once the search process is complete, the Upload button will be enabled. You can now upload your image collection.
Before uploading, will be informed about our image size limits.
You will be asked to decide what the application should do if the size limit is exceeded.
The decision is a one-off for the uploaded set and involves choosing one of two options: Scale / Skip.
The loading task is performed in the background. You can monitor the progress in the Dashboard or Dataset view.
When the upload is complete, you will see the number of uploaded images in the Dashboard. In the Datasets section you will find a tile with one of the images on the cover.
If you look at the upload, you will see that some of the images were not uploaded. This is probably because the images were incorrectly converted from different extensions to .jpg, and their metadata contained information about extensions that OSAI does not support.
#
Pick categories
When you click on the image collection tile, you will see a gallery view, similar to the one you are already familiar with from the process of adding a dataset.
You can browse through the tabs and filter the images according to the category/object classification set up in the automatic analysis process. Here you see two classes - Cat
and Dog
, and the images that belong to them.
You now have a dataset that you can use to train your classification model.
#
Working on the model
#
Create the model
To create a model, go to the Models section in the Trainings menu. Start with preparing a classifier.
Click Add new model and follow the model configuration process that OSAI will guide you through.
You will be asked to choose the model type (Detection or Classification), and since you want to create a classifier, you need to choose the latter. You can now move on to the model parametrization.
First, you need to select the dataset that will be the input data for the model training. Choose cats_and_dogs
:
Now you can move on to the next configuration step. Here you need to give your model a name (a string of characters without spaces) and then choose the Framework you want to use. Next, click on the Pretrained model to select the model that has been predefined in this framework.
OSAI will suggest the model's preferred input image sizes of the learning set and the percentage split of the dataset (into training, validation and test sets). The hints have been designed according to what is reported in the literature to be the correct and most effective parameters. However, you are free to change any of them.
Use the default parameters, suggested by OSAI and enter 500 in the Number of epochs field.
In the last parametrization step, you can manage the categories of images within the dataset. This option is described in much more detail in Creating and training models.
In this case, you only have two categories and they are correctly named, so do not edit their names and move directly to model training, by clicking Start training.
#
Train the model
Just like the image upload process, the model training task is performed in the background. You can track its progress in the Dashboard and in the Models section, where a new Model tile has now appeared.
On the tile, you will find a Stop button. There are two ways to terminate the training process.
- Choose Stop immediately to terminate the process and not save any data.
- Or choose to Stop with progress. This will stop the training as soon as the current iteration (epoch) is completed. The models and training results will be saved.
When the training is complete, click on the gear icon and select Details
to view full statistics of the training process, and options for converting the trained model to run on hardware other than the architecture on which it was trained.
We want to test your model on NVIDIA Jetson Nano, so let's convert the model to run on nVIDIA Maxwell.
Once the model has been converted, you can use the selected hardware to test its accuracy.
#
Testing your idea
To test your model, go to the Live Testing menu section, click Add device to add a new device and receive a token to connect it to the test space.
#
Add the device
If you have your own Jetson Nano device, you can use it and host a private environment on it to run trained models. In this case, select Own
when adding the device and follow the instructions in the documentation.
OneStepAI allows you to rent a device for testing models for a fee. In this case, select Rent
.
Name the device Jetson
, select Jetson Nano from the list of available devices and click Add device
.
As a service we are not able to guarantee the availability of the requested devices. In case of problems and long waiting times, please contact OSAI support who will always inform you when other devices will be available.
#
Connect to web app
Once you have added the device, it will appear in your device list. Click Connect and copy the registration code to the clipboard, then click Log in. This will open a new tab in your browser, where you will find a web app that is now using your local Nano device.
Enter the credentials you received and paste your registration code into the Token field.
Once registered, the device will change its status to Connected in the Live Testing section of the OSAI app.
On the homepage of the web app for testing, you will find a list of models that are compatible with the device you have connected. In this case, it is the cats-and-dogs
model that you have converted earlier.
As you can see from the icon on the model tile, the model has not yet been loaded into the device. Selecting the model will begin downloading it to the device's local memory.
Selecting the model again will take you to the section where you can select the input data required to test the selected model.
#
Load the input data
To test the model, use the cat and dog photo you have on your computer. Select Upload file.
Choose the image and confirm.
The image will be loaded into the device's local memory and processed by the selected model.
Keep in mind: The first run takes longer due to the additional conversion from the universal ONNX format to the TensorRT engine. We have transferred this conversion to the final device to optimize the model and maximize the neural network performance.
You can now view the test results.