Introduction
This page explains how to use the BLOCKS machine learning service for image classification. Some use cases for image classification systems include analyzing products for faults and diagnosing diseases from medical images.
In this tutorial, we will train a model to classify images of cats and dogs, then test using this model to classify new images.

General overview of steps
We’ll mainly be using the Model Generator and Flow Designer services. The following images shows a general overview of how each of these services will be used in the image classification:

We’ll start by training a model in the Model Generator. During this training, we’ll give the Model Generator lots of pictures of cats and dogs. It then “learns” the characteristics of the images that determine which are of cats and which are of dogs. We call the results of this training a model or trained model.
Once we’ve trained a model, we’ll a Flow Designer to make predictions—judge if images are of cats or dogs—for new images that weren’t used in the training.
BLOCKS supports JPEG, PNG, GIF, BMP image files. However, Model Generator trainings with the “prioritize speed” setting only support JPEG files.
info_outline For more information about training types, refer to Model Generator Help.
Trying out image classification
Before starting
We recommend using Google Chrome for this tutorial. You can also use Firefox, but one feature (explained in more detail later) is only available in Google Chrome.
We’ve prepared data that you can use for this tutorial. As mentioned previously, you will need data for the Model Generator to train a model that can classify images of cats and dogs. Once the model is trained, you will also need images for predictions. You can download the sample data for this tutorial from the following link:
Data | Explanation |
---|---|
file_download Sample Data |
This download contains folders of image files for training our model and making predictions. |
-
Download the sample data
Click the link above to download the sample data as a ZIP file. The ZIP file contains multiple folders and files.
-
Extract the files
Extract the data from the ZIP file. The extracted data should be organized as shown in the image below:
The training data images are separated into folders by class or label (in this case, dog and cat). The Model Generator uses the folder names from the training data as the class labels, so we’ve named the folders with easily understood names.
Since this tutorial will create a model that classifies images as either cats or dogs, we’ve organized our training images into a folder named dog and a folder named cat and placed 100 images of each into the folders.
All of the images are JPEG files.
-
Upload the data to Google Cloud Storage (GCS)
During the training, the Model Generator will read the training data from GCS. We’ll use the GCS Explorer tool in BLOCKS to upload the folder we extracted (blocks_ml_image_example) to GCS by doing the following.
First, sign in to BLOCKS.
- Click the menu (menu) in the global navigation bar.
- Click GCS Explorer.
- Select a GCP service account
- Select the bucket to upload the data into. We’re using a bucket that ends with -data.
info_outline Users on the Self-Service Plan (including the free trial) users, can select to automatically create default buckets including a -data bucket when creating a BLOCKS project.
If you do not have any buckets, you can create one from the GCP service accounts section of the project settings menu.
You can select another bucket if you have already created one. However, its Storage Class must be Regional and its Location must be us-central1.
- Click Upload Folder.
info_outline The upload folder function of the GCS Explorer is not available when using Firefox. If you are using Firefox, you can use the create folder function of the GCS Explorer to create the same folders as the downloaded data in GCS, then upload the text files into those folders. For more information on uploading files in the GCS Explorer, refer to Uploading files to GCS.
- Select the blocks_ml_image_example folder you extracted.
- Click Upload.
- Click Upload.

It will take a bit of time for the sample data folder to finish uploading.
Once finished, your training and prediction data will be ready to use.
Creating a Model Generator
We’ll now create Model Generator where we can train a model using the images we just uploaded by doing the following:

- Click the menu icon (menu) in the global navigation bar.
- Click Model Generator.
A screen titled What is the Model Generator? will appear if you haven’t created any Model Generators.

- Click Start.
info_outline A message will appear if you do not have enough licenses to create the Model Generator. If you are an admin for your organization, you will see the license purchase screen, where you can purchase an additional Model Generator license to continue. If you are not an admin, you will need to contact your organization’s admins to request that they purchase a license.
The list of Model Generators in your project will appear if any have already been created.

- Click Add.
info_outline A message will appear if you do not have enough licenses to create the Model Generator. If you are an admin for your organization, you will see the license purchase screen, where you can purchase an additional Model Generator license to continue. If you are not an admin, you will need to contact your organization’s admins to request that they purchase a license.

- Click Image classification model.
- Click Next.

- Enter a name for the Model Generator.
- Click Next.
info_outline Free Trial and Self-Service Plan users should follow the directions on the screen to complete the following two steps:

- Confirm that your settings are correct and click Finish.
Training a model
Now that the Model Generator is ready, we’ll use our training data to train a model.

- Click Start Training.

- Enter a name for the training.
- Click the folder icon (folder).

- Click the arrow icon (arrow_right) next to the bucket that contains your training data. We’ve used a bucket that ends in -data.
- Click the arrow icon (arrow_right) next to folder blocks_ml_image_example.
- Click folder training/.
- Click Select.

- Click Start.

You can check on the status of a training while it is running by looking at the training list.
The training for this tutorial should take about two hours, depending on server circumstances. The status will change to Successful if it finishes successfully.
Once this occurs, we need to set our trained model to be available for making predictions. To do this, we will Apply the training.

- Click the drop-down arrow (arrow_drop_down)
- Click Production.
- Click Apply.
info_outline For more details about applying to production or testing, refer to the Model Generator Help page’s Training list section.
If your training fails, please try running it again. For help determining the reason for a training’s failure, refer to In case of an error.
If the training fails due to a shortage of GCP resources, try running a new training with the Machine type setting set to Single node.
For help determining the reason for a training’s failure, refer to In case of an error.
Creating a Flow Designer
With the trained model ready, we can now use it to make predictions in a Flow Designer. We’ll use the Flow Templates feature of the Flow Designer to quickly create a Flow for image classification predictions.

- Click the menu icon (menu) in the global navigation bar.
- Click Flow Designer.

- Click Start.
info_outline If you have already created a Flow Designer in your project, you will see the Flow Designer list instead of the “What is a Flow Designer?” screen. In this case, you can click on the name of an existing Flow Designer and use it for the rest of this tutorial. If you have enough licenses and want to use a new Flow Designer, you can click Add in the upper-left corner of the Flow Designer list.
info_outline A message will appear if you do not have enough licenses to create the Flow Designer. If you are an admin for your organization, you will see the license purchase screen, where you can purchase an additional Flow Designer license to continue. If you are not an admin, you will need to contact your organization’s admins to request that they purchase a license.

- Enter a name for the Flow Designer.
- Configure the language setting (for logs).
- Configure the time zone setting.
- Click Create.
Creating a Flow for making predictions
With the Flow Designer ready, we’ll use the Flow Templates menu to create a Flow for making predictions with the model we trained.

- Click the name of the Flow Designer you will use.
Your Flow Designer will open in a new tab.

- Click Flow Templates.

- Click Image classification prediction.
- Click Next.

- Enter a name for the Flow.
- Click Next.

- Click on the Model Generator that you created for this tutorial. Ours was named Dog or Cat Classification.
- Select Batch prediction.
- Click Next.

- Click the folder icon (folder ).

- Click the arrow icon (arrow_right) for the bucket that contains your prediction data. We used a bucket that ends with -data.
- Click the arrow icon (arrow_right) for folder blocks_ml_image_example
- Click folder prediction.
- Click Select.

- Click Next.

- Select DataEditor for the storage location.
- Select Register as new.
- Enter a name for identifying the data in the DataEditor. (Example shown above:
Dog or cat prediction results
) - Enter the dataset that will store the results. (Example shown above:
tutorials
) - Enter the table that will store the results. (Example shown above:
image_classification_results
)
info_outline DataEditor is a tool for visualizing data stored in BigQuery. You don’t need any specialized knowledge of BigQuery to use the DataEditor, but you do need to configure the dataset and table that your data will be stored in. If you are familiar with spreadsheet software, you can compare a dataset to a workbook and a table to a single sheet.

Scroll down to see the Number of labels setting.
- Set the number of labels to 2.
- Click Next.

- Click Create.

- Click Save.
info_outline Make sure to click Save after creating the Flow. You won’t be able to execute the Flow to make predictions unless you save. If you close the Flow Designer tab or your web browser without saving, the Flow will be lost.
Making predictions
We can now use the Flow to make predictions.

- Click the menu icon (more_vert) on your Start of Flow BLOCK (We named this BLOCK Dog or cat prediction).
- Click Execute Flow.
We can view the Logs section to check on the status of our Flow as it executes.

- Click View Logs.

- Confirm that the Flow’s status is Running.
The Flow will take a bit of time to run.

- Wait until the status changes to Finished.
Once this happens, the Flow has successfully executed.
If the Flow fails to execute successfully, refer to In case of an error for help determining the cause of the error.
Checking the prediction results
When we used the Flow Template to create the Flow, we configured for the results of the prediction to be sent to the DataEditor. To check the results in the DataEditor, switch back from the Flow Designer to the BLOCKS tab. We had previously left it on the Flow Designer list page.

- Click the menu icon (menu) in the global navigation bar.
- Click DataEditor.

- Click the name you configured for the results. We used Dog or cat prediction results.

- Click the Table tab.

- Click View data.

The following chart explains the meaning of each column in the results data:
Name | Explanation |
---|---|
key | The GCS URL for the prediction image file. |
label | The predicted label. Our labels were dog and cat. |
score |
The confidence level for predicting the label shown in the label column. This is shown as a number between 0–1 with 1 signifying 100% confidence. |
score_(ascending numbers from 0) |
The confidence level for each specific label. This is shown as a number between 0–1 with 1 signifying 100% confidence. |
The above results can also be expressed as follows:
In case of an error
If an error occurs during the Model Generator’s training, you can find the error logs by doing the following:

- Click on the name of the training whose status is Failed.

- Click Error logs.
- If needed, you can click Copy error logs to copy the logs to your clipboard.
If an error occurs while using the Flow Designer, you can find the error logs by checking the Logs panel.

Error messages are shown in red.
It’s often helpful to read the logs before and after an error when attempting to determine its cause (click Show error log details).
If you encounter an error that you cannot solve after several attempts, you can contact the BLOCKS support team by clicking your user icon in the right side of the global navigation bar and selecting Contact Us. For errors in a Model Generator, please copy the entire contents of the error logs and include these as a text file when you send your message.
For errors in a Flow Designer, click the Show error log details checkbox in the Logs panel of the Flow designer, then copy the logs. You should also export your Flow as a JSON file and include this as an attachment in your message to BLOCKS support.
info_outline For more details on contacting BLOCKS support, refer to the Basic Guide: Contact Us page.
Summary
With BLOCKS, you just need to prepare image files into labelled folders to get started with image classification machine learning.
As a final note, please keep in mind the following about the kinds of images that can be used for image classification in BLOCKS:
- Images with extreme aspect ratios may not be classified properly.
- Images used for training should be placed into separate folders by label.
- Images within the folder can be JPEG, PNG, GIF, or BMP. However, trainings that prioritize speed can only support JPEG files. Do not create subfolders within the class folders.