[ Web Proxy ]
URL:
Viewing: https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-convert-image-type [Back]  [Original]

The ML.CONVERT_IMAGE_TYPE function  |  BigQuery  |  Google Cloud Documentation Skip to main content
Google Cloud Documentation [Google Cloud Documentation]
Send feedback Stay organized with collections Save and categorize content based on your preferences.

The ML.CONVERT_IMAGE_TYPE function

This document describes the ML.CONVERT_IMAGE_TYPE scalar function, which lets you convert the data type of pixel values in an image to INT64 with a range of [0, 255). You can use ML.CONVERT_IMAGE_TYPE with the ML.PREDICT function or chain it with other functions or subqueries.

Syntax

ML.CONVERT_IMAGE_TYPE(image)

Arguments

ML.CONVERT_IMAGE_TYPE takes the following argument:

Output

ML.CONVERT_IMAGE_TYPE returns a STRUCT<ARRAY<INT64>, ARRAY<INT64>> value that represents the image.

The first array in the struct represents the dimensions of the image, and the second array in the struct contains the image data, similar to the image input argument. Each value in the second array is between [0, 255).

Note: If you reference ML.CONVERT_IMAGE_TYPE in SQL statements in the BigQuery editor, it is possible for the function output to be too large to display. If this occurs, write the output to a table instead.

Example

The SSD Mobilenet V2 Object detection model model requires input to be in tf.uint8. The following example changes the pixel values for the input images from floating point numbers to integers so that they work with this model:

CREATE OR REPLACE TABLE mydataset.detections
AS (
  SELECT uri, detection_scores
  FROM
    ML.PREDICT(
      MODEL `mydataset.mobilenet`,
      SELECT
        ML.CONVERT_IMAGE_TYPE(ML.DECODE_IMAGE(data))
          AS image,
        uri
      FROM `mydataset.images`)
);

What's next

Send feedback

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-08-11 UTC.

Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-11 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page