
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create a cloud resource connection
/ 20
Grant IAM permissions to the connection's service account
/ 20
Create the dataset and tables in BigQuery
/ 20
Import the model into BigQuery
/ 20
Classify images using the imported ONNX model
/ 20
In this lab, you learn how to help streamline an image classification workflow in BigQuery using an imported model (PyTorch model created in ONNX format), and Google SQL queries.
As a new data analyst at Cymbal Media and Entertainment, you have been tasked to experiment with an imported model and BigQuery Machine Learning for inference to classify wildlife images. This project aims to automate the image classification process, simplify content creation, and potentially build a larger database of wildlife images for future content on Cymbal's streaming platform.
ONNX is an open format built to represent machine learning models. ONNX defines a common set of operators — the building blocks of machine learning and deep learning models — and a common file format to enable AI developers to use models with a variety of frameworks, tools, runtimes, and compilers.
BigQuery is a fully managed, AI-ready data analytics platform which helps you maximize value from your data and is designed to be multi-engine, multi-format, and multi-cloud. One of its key features is BigQuery Machine Learning for inference, which lets you create and run machine learning (ML) models by using SQL queries.
Usually, performing ML or artificial intelligence (AI) on large datasets requires extensive programming and knowledge of ML frameworks. This restricts solution development to a small set of people within each company, and excludes data analysts who understand the data but have limited ML knowledge and programming expertise. However, with BigQuery ML, SQL practitioners can use existing SQL knowledge, skills, and tools to build and to generate results from models built with ONNX, and stored in a cloud storage bucket. This helps companies with model choice, and flexibility from an MLOPs perspective. It also helps scale their ML initiatives.
The images used in this lab are from the Animals Detection Images Dataset on Kaggle.
In this lab, you learn how to:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
In this task, you create a Cloud Resource connection in BigQuery, so you can import the images from Cloud Storage into the object table within your dataset.
In the Google Cloud Console, on the Navigation menu, click BigQuery.
The Welcome to BigQuery pop-up is displayed. Click DONE.
To create a connection, click + ADD, and then click Connections to external data sources.
In the Connection type list, select Vertex AI remote models, remote functions and BigLake (Cloud Resource).
In the Connection ID field, enter onnx_conn for your connection.
For Location type, choose Region.
For Region, choose
Click CREATE CONNECTION.
Click GO TO CONNECTION.
You will also see the connection added under the External Connections section of your project in the BigQuery Explorer. In the Connection info pane, copy the service account ID to a text file for use in the next task.
Click Check my progress to verify the objective.
In this task, you review images and files (ONNX model and classifier csv), and grant IAM permissions to the Cloud Resource connection's service account.
Before you dive into this task to grant permissions to the resource connection service account, review the images, the model and the classifier.csv file as they are stored in the Cloud Storage bucket.
In the Google Cloud console, select the Navigation menu (), and then select Cloud Storage > Buckets.
Click on the
The bucket contains the gsp1248 folder, open the folder. You will see three items in it:
Granting IAM permissions to the resource connection's service account before you start working in BigQuery will ensure you do not encounter access denied errors when running queries.
Return to the bucket root.
Click PERMISSIONS.
Click GRANT ACCESS.
In the New principals field, enter the service account ID you copied earlier.
In the Select a role field, enter Storage Object, and then select Storage Object Admin role.
Click Save.
The result is the service account id now includes the Storage Object Admin role.
Click Check my progress to verify the objective.
In this task, you create a dataset for the project, an object table to store the images, and a table for the classification list.
In the Google Cloud console, select the Navigation menu (), and then select BigQuery.
In the Explorer panel, for
You create a dataset to store database objects, including tables and models.
In the Create dataset pane, enter the following information:
Field | Value |
---|---|
Dataset ID | onnx_demo |
Location type > Region | select |
Leave the other fields at their defaults.
Click Create Dataset.
The result is the onnx_demo dataset is created and listed underneath your project in the BigQuery Explorer.
With the dataset created, you can now create the object table referencing the images in the bucket.
To create the object table you will use a SQL query.
Click the + to create a new SQL query.
In the query editor, paste the query below.
Run the query.
The result is the wildlife object table is added to the onnx_demo dataset and loaded with the URI (the cloud storage location) of each animal image.
In the Explorer, click on the wildlife table and review the schema and details.
To create the table classification list you will use a SQL query.
Click the + to create a new SQL query.
In the query editor, paste the query below.
Run the query.
The result is the classifier table added to the onnx_demo dataset, loaded with the ID and the classification of each item in the dataset. This includes wildlife you will classify later in the lab.
In the Explorer, click on the classifier table and review the schema and details. Feel free to query the table to review how it classifies each item. Note: the table contains many other items, not just wildlife (like animals, fish, insects and birds).
Click Check my progress to verify the objective.
In this task, you import the resnet18 ONNX model into BigQuery so you may use it to classify images.
Click the + to create a new SQL query.
In the query editor, paste the query below.
Run the query.
The result is the model is added to the onnx_demo dataset in the models section.
In the Explorer, click on the model and review the details.
Click Check my progress to verify the objective.
In this task, you reserve a slot, assign it to your project, and use a query to classify new images with the ONNX model.
In order for you to use the ONNX model, you will have to create a slot reservation, and assign it to your project.
From the BigQuery menu click Capacity Management.
On the Capacity Management page, click CREATE RESERVATION.
On the Create Reservation page, enter reservation
as the reservation name.
Choose the
Choose Small (100 Slots) for the Max reservation size selector option.
Click SAVE.
Click on the Reservation Actions button (vertical 3 dots) for your reservation.
In the pop-up menu, click Create Assignment.
In the Create an Assignment pop-up window, you will see the Job Type default to QUERY. Keep this option.
Click BROWSE.
In the pop-up choose the project name. The project is added to the Select an organization, folder or project field.
Click CREATE.
The result is the project is assigned to the slot reservation you just created.
Wait 2 minutes. The slot reservation assignment takes some time to apply to the account.
Return to BigQuery Studio.
Click the + to create a new SQL query.
In the query editor, paste the query below.
Run the query.
The result is the images are each classified by row with the ID and the predicted classification based on the ONNX model.
Click Check my progress to verify the objective.
You successfully created a Cloud Resource connection, granted access to the service account for the connection, created a dataset and tables, imported an ONNX model into BigQuery, and classified images using the model.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated March 21, 2025
Lab Last Tested March 21, 2025
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one