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 collection of images, go to the Owned datasets
:
![Datasets view](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_1.jpg)
#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, click Add new dataset
, enter the dataset name, and select Personal
.
Keep in mind: The name must be a string of letters, digits and spaces.
![Add new dataset](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_2.jpg)
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 a .zip folder - Add archive,
use live footage - Live from the camera.
![Upload view](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_3.jpg)
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
.
To learn more about OneStepAI's adopted logic for loading images and automatically categorizing them based on the directory structure, read the Upload article.
![Choose directories for upload](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_4.jpg)
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
, Other
, 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.
![Upload images](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_5.jpg)
Before uploading, you will be informed of our image size limits. You will be asked to decide what the application should do if the size limit is exceeded. This decision is a one-off for the uploaded set and involves choosing one of two options: Scale
/ Skip
.
![Image size limits](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_limit.jpg)
The loading task is performed in the background. You can monitor the progress in the Dashboard
or Datasets view
.
![Uploading in progress](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_6.jpg)
When the upload is complete, you will see the number of uploaded images in the Dashboard
.
![Dashboard](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_7.jpg)
In the Datasets view
you will find a tile with one of the images on the cover.
![Datasets view](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_8.jpg)
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 various extensions to .jpg, and their metadata contained information about extensions that OSAI does not support.
![Errors](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_9.jpg)
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.
In the right-hand menu, you can switch between the Classification
and Object Detection
tabs. If you only want to view one category of photos, narrow down the selection by clicking on the relevant tag set in the automatic analysis process. Here, you can see two classes, Cat
and Dog
, and the photos that belong to them.
![View 'Dog' category](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_10.jpg)
![View 'Cat' category](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_11.jpg)
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 of the Trainings
menu. Start by preparing a classifier.
Click Add new model
and follow the model configuration process that OSAI will guide you through.
![Models list](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_12.jpg)
You will be asked to select the model type, Detection or Classification, and since you want to create a classifier, you must choose the latter.
![Create new model](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_13.jpg)
First, you need to select the dataset that will be the input data for the model training. Choose Cats-and-Dogs
:
![Choose datasets and categories](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_14.jpg)
Now you can manage the categories of images within the dataset. This option is described in much more detail in Creating and training models article. In this case, you only have two categories and they are correctly named, so continue by clicking Next
.
![Merge categories](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_17.jpg)
The next step is to parameterize the model. Here you need to give your model a name (a string of characters without spaces) and then select the Framework
one you want to use. Then, 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 breakdown 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. Click Start training
.
![Set model parameters](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_15.jpg)
![Set model parameters](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_16.jpg)
#Train the model
Like the image upload process, the model training task runs in the background. You can track its progress in the Dashboard
and in the Models section
, where a new Model tile has now appeared.
![Training in progress](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_18.jpg)
On the tile, there is a Stop
button. There are two ways to terminate the training process.
- Select
Stop immediately
to terminate the process and not save any data. - Or select 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.
![Training tile](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_19.jpg)
When the training is complete, hover over the gear icon and select Details
to view full statistics of the training process, model history, results from the test subset, and options for converting the trained model to run on hardware other than the architecture on which it was trained.
To learn more about model performance, read Tracking model performance article.
![Training statistics](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_20.jpg)
![Accuracy and loss charts](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_21a.jpg)
![Confusion matrix](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_21b.jpg)
![Results from test subset](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_22.jpg)
We want to test your model on NVIDIA Jetson Nano, so let's convert the model to run on NVIDIA Maxwell.
![Conversion](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_23.jpg)
Once the model is 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 new device](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_24.jpg)
#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
.
![Device source](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_25.jpg)
Select Jetson Nano from the list of available devices, name the device Jetson Nano
, and click Add device
.
As a service, we cannot 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.
![Device type](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_26.jpg)
![Device details](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_27.jpg)
#Connect to web app
Once you have added the device, it will appear in your device list. Click on the device tile and copy the registration code to the clipboard, then click Copy token and go to device
. This will open a new tab in your browser, where you will find a web app that is now using your local Nano device.
![Token](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_28.jpg)
Enter your e-mail, paste your registration code into the Token
field, and create a password.
![Log in to the web app](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_29.jpg)
Once registered, the device will change its status to Connected in the Live Testing
section of the OSAI app.
![Devices](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_30.jpg)
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.
Select the model to download it to the device's local memory.
![Downloaded model](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_31.jpg)
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
.
![Upload file](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_32.jpg)
Select the image and confirm.
![Select image](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_33.jpg)
The image will be loaded into the device's local memory and processed by the selected model.
![Create engine](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_34.jpg)
You can now view the test results.
#Results
![Image result](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_35.jpg)
![Image result](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_36.jpg)
![Image result](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_37.jpg)
![Image result](https://docs.onestepai.com/static/tutorials/advanced/home_pets_categorizer/cat_and_dogs_38.jpg)