EasyVision's prediction component runs offline prediction jobs on Platform for AI (PAI), processing large volumes of image and video data against trained models. The following sections describe the supported input data formats and PAI command parameters.
When to use offline prediction
Use offline prediction when you need to:
Run inference on large datasets in batch
Process images stored in MaxCompute tables or Object Storage Service (OSS) buckets in bulk
Apply video-level models or per-frame image models to video data
Use custom predictors or preprocessing logic with EasyVision's built-in I/O pipeline
How it works
Offline prediction runs as a distributed pipeline. Each atomic operation is processed asynchronously across multiple threads on every worker node.
Data flow:
Inputs: Images or videos from a MaxCompute table or an OSS file list
Processing: Each worker node reads its assigned data shard, decodes it (Base64 or URL), runs model inference, and writes results to the output shard — all concurrently across threads
Outputs: Prediction results written to a MaxCompute output table or an OSS file
For example, when reading images from a MaxCompute table, the system splits the table based on the number of worker nodes. Each worker independently reads its shard, decodes Base64 data, performs model prediction, and writes results to the corresponding output partition. Base64 decoding and inference run asynchronously in parallel threads to fully use both CPU and GPU capacity.
EasyVision provides video-level prediction models that you can use directly, or you can apply image-level models to individual video frames. The framework automatically decodes video data, runs per-frame inference, and aggregates the results.
The default prediction code provided by EasyVision does not support loading trained models for offline prediction. Use the user_predictor_cls parameter to specify a custom predictor class and reuse EasyVision's built-in I/O pipeline (ev_predict). You can also insert a custom preprocessing step before the predictor receives input — see Custom input data.
Input data formats
Read data from MaxCompute tables
The input table must include at least one column containing Base64-encoded binary data or URLs for the images. That column must be of the string type. Sample schema:
+------------------------------------------------------------------------------------+
| Field | Type | Label | Comment |
+------------------------------------------------------------------------------------+
| id | string | | |
| url | string | | |
+------------------------------------------------------------------------------------+Read data from OSS files
Each line in the OSS input file is either an OSS path or an HTTP URL pointing to an image:
oss://your/path/to/image.jpg
http://your.path/to/image.jpgCustom input data
By default, reading from a MaxCompute table retrieves only the URL or Base64-encoded image data, and reading from OSS retrieves only the image URL. Both methods produce NumPy arrays in the {"image": np.ndarray} format — a single-input format that cannot meet all use cases.
The custom format can be the original OSS file format or JSON string format. Each line in the input file is a JSON string with one or more key-value pairs:
{"image":"http://your/path/to/image.jpg", "prior":"oss://your/path/to/prior.txt", "config": {"key1":1, "key2":"value2"}}
{"image":"http://your/path/to/image.jpg", "prior":"oss://your/path/to/prior.txt", "config": {"key2":1, "key2":"value2"}}All key-value pairs are collected into a dictionary and passed to your custom predictor and process classes. The system automatically handles downloads and decoding:
If a value is an OSS path or HTTP URL, the system downloads the file content using multiple threads and returns a file-like object. Call
read()orreadlines()to access the content.If the URL points to a file with an image extension, the system automatically decodes it and returns a
numpy.ndarray.
The input is delivered to your predictor as an input_data dictionary:
input_dict = {
"image": np.ndarray, # Decoded image data
"prior": file_like_object, # Downloaded file as a file-like object
"config": {"key1": 1, "key2": "value2"} # Raw JSON sub-dictionary
}All built-in EasyVision predictors use the image key to access input images. If you use a custom input format with built-in predictors, the image data must be stored under the image key.
Parameters
Required parameters
| Parameter | Description | Type | Example |
|---|---|---|---|
model_path | OSS path of the model directory | STRING | oss://your_bucket/your_model_dir |
model_type | Type of the model. See Model types. | STRING | classifier |
buckets | OSS bucket information for accessing the model and data | STRING | oss://{bucket_name}.{oss_host}/{path} |
arn | Alibaba Cloud Resource Name (ARN) of the RAM role with OSS access permissions. For details, see the "I/O parameters" section of Parameters of PAI-TensorFlow tasks. | STRING | — |
Input and output
| Parameter | Description | Type | Default | Example |
|---|---|---|---|---|
input_table | Name of the input MaxCompute table. Supports non-partitioned and partitioned tables. | STRING | "" | odps://prj_name/tables/table_name/pt=xxx |
image_col | Name of the column that contains image data | STRING | "image" | "url" |
image_type | Format of image data in the table. base64: Base64-encoded binary. url: URL or OSS path. | STRING | "base64" | "url" |
reserved_columns | Names of additional columns to carry through to the output. Separate multiple names with commas. | STRING | "" | "col1,col2,col3" |
result_column | Name of the output column for prediction results | STRING | "prediction_result" | — |
output_table | Output MaxCompute table. Uses the same format as input_table. If the table does not exist, the system creates it automatically with the required partitions. | STRING | "" | odps://prj_name/tables/output_table |
lifecycle | Lifecycle (in days) of the output table | INT | 10 | 30 |
input_oss_file | Path of the OSS input file. Each line is either an image path/URL or a JSON string (for custom input). | STRING | "" | oss://your_bucket/filelist.txt |
output_oss_file | Path of the output OSS file. The system generates one result file per worker node, then merges them into this file. Result files are prefixed with this filename. | STRING | "" | oss://your_bucket/results.txt |
output_dir | OSS folder for output files when using a custom output format | STRING | "" | oss://your_bucket/dir |
Compute and concurrency
| Parameter | Description | Type | Default | When to adjust |
|---|---|---|---|---|
num_worker | Number of prediction worker nodes | INT | 2 | Increase for larger datasets to speed up processing |
cpuRequired | Number of CPUs per worker node. A value of 100 equals one CPU. | INT | 1600 | Increase for CPU-heavy preprocessing |
gpuRequired | Number of GPUs per worker node. A value of 100 equals one GPU. A value of 0 uses a CPU-only cluster. Maximum: 100. | INT | 100 | Set to 0 for CPU-only workloads |
queue_size | Length of the inter-stage buffer queue | INT | 1024 | Reduce if memory is constrained |
batch_size | Batch size for model inference | INT | 1 | Increase for GPU workloads to improve throughput |
preprocess_thread_num | Number of concurrent preprocessing threads (image decoding and download) | INT | 4 | Increase for URL-based inputs with high download latency |
predict_thread_num | Number of concurrent inference threads | INT | 2 | Increase for lightweight models with fast inference |
Video parameters
| Parameter | Description | Type | Default |
|---|---|---|---|
is_input_video | Set to true when the input is video data | BOOL | false |
use_image_predictor | Set to true if the predictor accepts only image frames (not raw video) | BOOL | true |
decode_type | Video decode mode. 1: intra frames only. 2: keyframes only. 3: exclude bidirectional frames. 4: decode all frames. | INT | 4 |
sample_fps | Number of frames extracted per second for sampling | FLOAT | 5 |
reshape_size | Output frame size in pixels. Set to -1 to keep the original size. | INT | -1 |
decode_batch_size | Number of frames decoded in each batch | INT | 10 |
decode_keep_size | Number of overlapping frames between consecutive decode batches | INT | 0 |
Custom predictor and process
| Parameter | Description | Type | Default | Example |
|---|---|---|---|---|
feature_name | Name of the feature layer to extract. Required only when model_type is feature_extractor. | STRING | "" | resnet_v1_50/logits |
user_resource | Path of a resource package (TAR.GZ, ZIP, or Python file) uploaded with the job. OSS paths and HTTP URLs are supported. | STRING | "" | oss://xxx/a.tar.gz |
user_predictor_cls | Module path of the custom predictor class. | STRING | "" | module.MyPredictor |
user_process_config | JSON configuration for a custom process class. Fields: job_name, num_threads, batch_size, user_process_cls. | JSON | "" | '[{"job_name":"myprocess","user_process_cls":"module.ClassA","num_threads":2,"batch_size":1}]' |
Reliability
| Parameter | Description | Type | Default |
|---|---|---|---|
enableDynamicCluster | Set to true to allow single worker node failover. Enable this if task exceptions occur frequently. | BOOL | false |
useSparseClusterSchema | Must be set to true when enableDynamicCluster is true. | BOOL | false |
Model types
The model_type parameter specifies which built-in model pipeline to load:
| Value | Task | When to use |
|---|---|---|
feature_extractor | Feature extraction | Extract intermediate layer representations from images. Set feature_name to specify the layer. |
classifier | Image classification | Assign a single label to each image |
multilabel_classifier | Multi-label classification | Assign multiple labels to each image |
detector | Object detection | Locate and classify objects in images |
text_detector | Text detection | Locate text regions in images |
text_recognizer | Text line recognition | Transcribe text from detected regions |
text_detection_recognition | Text detection and recognition | Detect and transcribe text in a single pass |
text_spotter | End-to-end text recognition | Locate and recognize arbitrary text end-to-end |
segmentor | Semantic image segmentation | Assign a class label to each pixel |
self_define | Custom prediction | Load the predictor class specified by user_predictor_cls |