全部产品
Search
文档中心

Object Storage Service:Deteksi label citra

更新时间:Dec 18, 2025

Gunakan deteksi label citra untuk mengidentifikasi konten seperti adegan, objek, dan event dalam citra. Fitur ini memungkinkan Anda memberi tag pada citra secara otomatis.

Deskripsi fitur

Fitur deteksi label citra mendeteksi konten seperti adegan, objek, dan event dalam citra serta secara otomatis menambahkan label. Fitur ini mendukung ribuan label dari lebih dari 30 kategori, seperti yang ditunjukkan pada gambar berikut.

图片标签检测..jpeg

Skenario

Skenario

Deskripsi

Content recognition

Mendeteksi item, adegan, dan informasi lain dalam citra yang diambil atau diunggah. Fitur ini dapat digunakan dalam produk atau fitur untuk pengenalan objek dari foto atau untuk keperluan sains populer.

Smart album

Mengklasifikasikan citra secara otomatis berdasarkan kontennya untuk menerapkan klasifikasi cerdas pada album foto dan galeri. Hal ini membantu mencapai manajemen yang efisien dan otomatis.

Scene analysis

Mendeteksi berbagai objek atau adegan dalam citra dan menambahkan label konten untuk adegan yang berbeda. Hal ini meningkatkan efisiensi analisis adegan dan mengurangi biaya anotasi manual.

Content operations

Memperoleh informasi label citra untuk rekomendasi konten. Fitur ini banyak digunakan di platform konten seperti media sosial, berita, informasi, dan platform e-commerce.

Perhatian

  • Deteksi label citra hanya mendukung citra dalam format JPG, PNG, atau JPEG.

  • Batasan berikut berlaku untuk ukuran citra:

    • Ukuran citra tidak boleh melebihi 20 MB.

    • Tinggi atau lebar citra tidak boleh melebihi 30.000 piksel (px).

    • Jumlah total piksel dalam citra tidak boleh melebihi 250 juta.

  • Deteksi label citra hanya mendukung pemrosesan sinkron (menggunakan metode x-oss-process).

  • Akses anonim akan ditolak.

Cara menggunakan

Prasyarat

Detect image labels

Contoh kode berikut menunjukkan cara mendeteksi label citra menggunakan kit pengembangan perangkat lunak (SDK) umum. Untuk menggunakan SDK lain, sesuaikan kode dari contoh ini.

Java

Gunakan Java SDK versi 3.17.4 atau yang lebih baru.

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyuncs.exceptions.ClientException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class Demo {
    public static void main(String[] args) throws ClientException, ClientException {
        // Set yourEndpoint to the endpoint of the region where the bucket is located.
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // Specify the region corresponding to the endpoint, for example, cn-hangzhou.
        String region = "cn-hangzhou";
        // Obtain access credentials from environment variables. Before running this sample code, make sure the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the bucket name.
        String bucketName = "examplebucket";
        // If the image is in the root directory of the bucket, specify the image name. If the image is not in the root directory, specify the full path, for example, exampledir/example.jpg.
        String key = "example.jpg";

        // Create an OSSClient instance.
        // When the OSSClient instance is no longer needed, call the shutdown method to release resources.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(credentialsProvider)
                .clientConfiguration(clientBuilderConfiguration)
                .region(region)
                .build();

        try {
            // Construct the processing instruction for image label detection.
            GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
            getObjectRequest.setProcess("image/labels");

            // Use the getObject method and pass the processing instruction through the process parameter.
            OSSObject ossObject = ossClient.getObject(getObjectRequest);

            // Read and print the information.
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = ossObject.getObjectContent().read(buffer)) != -1) {
                baos.write(buffer, 0, bytesRead);
            }
            String imageLabels = baos.toString("UTF-8");
            System.out.println("Image Labels:");
            System.out.println(imageLabels);
        } catch (IOException e) {
            System.out.println("Error: " + e.getMessage());
        } finally {
            // Shut down the OSSClient.
            ossClient.shutdown();
        }
    }
}

Python

Gunakan Python SDK versi 2.18.4 atau yang lebih baru.

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before running this sample code, make sure the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the endpoint of the region where the bucket is located. For example, for China (Hangzhou), set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
# Specify the general-purpose Alibaba Cloud region ID.
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)

# If the image is in the root directory of the bucket, specify the image name. If the image is not in the root directory, specify the full path, for example, exampledir/example.jpg.
key = 'example.jpg'

# Construct the processing instruction for image label detection.
process = 'image/labels'

try:
    # Use the get_object method and pass the processing instruction through the process parameter.
    result = bucket.get_object(key, process=process)

    # Read and print the information.
    image_labels = result.read().decode('utf-8')
    print("Image Labels:")
    print(image_labels)
except oss2.exceptions.OssError as e:
    print("Error:", e)

Go

Gunakan Go SDK versi 3.0.2 atau yang lebih baru.

package main

import (
	"fmt"
	"io"
	"os"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
	// Obtain temporary access credentials from environment variables. Before running this sample code, make sure the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
	provider, err := oss.NewEnvironmentVariableCredentialsProvider()
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// Create an OSSClient instance.
	// Set yourEndpoint to the endpoint of the bucket. For example, for China (Hangzhou), set it to https://oss-cn-hangzhou.aliyuncs.com. For other regions, specify the actual endpoint.
	// Set yourRegion to the general-purpose Alibaba Cloud region ID, for example, cn-hangzhou.
	client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// Specify the bucket name, for example, examplebucket.
	bucketName := "examplebucket"

	bucket, err := client.Bucket(bucketName)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// If the image is in the root directory of the bucket, specify the image name. If the image is not in the root directory, specify the full path, for example, exampledir/example.jpg.
	// Use the oss.Process method to construct the processing instruction for image label detection.
	body, err := bucket.GetObject("example.jpg", oss.Process("image/labels"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	defer body.Close()

	data, err := io.ReadAll(body)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	fmt.Println("data:", string(data))
}

PHP

Gunakan PHP SDK versi 2.7.0 atau yang lebih baru.

<?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;

try {
    // Obtain access credentials from environment variables. Before running this sample code, make sure the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
    $provider = new EnvironmentVariableCredentialsProvider(); 
    // Specify the endpoint of the region where the bucket is located. For example, for China (Hangzhou), set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
    $endpoint = 'https://oss-cn-hangzhou.aliyuncs.com';
    // Specify the bucket name, for example, examplebucket.
    $bucket = 'examplebucket';
    // If the image is in the root directory of the bucket, specify the image name. If the image is not in the root directory, specify the full path, for example, exampledir/example.jpg.
    $key = 'example.jpg'; 

    $config = array(
        "provider" => $provider,
        "endpoint" => $endpoint,        
        "signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
        // Specify the general-purpose Alibaba Cloud region ID.
        "region" => "cn-hangzhou"
    );
    $ossClient = new OssClient($config);
  // Construct the processing instruction for image label detection.
  $options[$ossClient::OSS_PROCESS] = "image/labels";
  $result = $ossClient->getObject($bucket,$key,$options);
  var_dump($result);
} catch (OssException $e) {
  printf($e->getMessage() . "\n");
  return;

Parameter

Action: image/labels

Parameter permintaan

Parameter

Type

Wajib

Deskripsi

Contoh

thr

float

Tidak

Label dengan skor kepercayaan di bawah ambang batas yang ditentukan tidak akan ditampilkan. Nilainya harus berada dalam rentang [0, 1]. Nilai default adalah 0,7.

0,5

Parameter respons

Catatan

Untuk informasi selengkapnya tentang parameter respons, lihat DetectImageLabels - Detect labels in an image.

Operasi API terkait

Jika aplikasi Anda memerlukan tingkat kustomisasi yang tinggi, Anda dapat langsung membuat permintaan REST API. Hal ini mengharuskan Anda menulis kode untuk menghitung signature. Untuk informasi selengkapnya tentang cara menghitung header permintaan `Authorization`, lihat Signature Version 4 (disarankan).

Anda dapat memproses citra dengan menambahkan parameter `x-oss-process` ke operasi GetObject. Untuk informasi selengkapnya, lihat GetObject.

Get labels without a filter threshold

Threshold setting

  • Tidak diatur

Processing examples

GET /example.jpg?x-oss-process=image/labels HTTP/1.1
Host: image-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 21 Jul 2023 08:30:25 GMT
Authorization: SignatureValue

Sample response

HTTP/1.1 200 OK
Server: AliyunOSS
Date: Fri, 21 Jul 2023 08:30:26 GMT
Content-Type: application/json;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
x-oss-request-id: 64BA42225DFDD13437ECD00E
Last-Modified: Mon, 10 Jul 2023 13:07:30 GMT
x-oss-object-type: Normal
x-oss-hash-crc64ecma: 13420962247653419692
x-oss-storage-class: Standard
x-oss-ec: 0048-00000104
Content-Disposition: attachment
x-oss-force-download: true
x-oss-server-time: 489
Content-Encoding: gzip

{
    "Labels":[
        {
            "CentricScore": 0.823,
            "LabelConfidence": 1.0,
            "LabelLevel": 2,
            "LabelName": "Outerwear",
            "Language": "zh-Hans",
            "ParentLabelName": "Clothing"
        },
        { 
            "CentricScore": 0.721,
            "LabelConfidence": 0.735,
            "LabelLevel": 2,
            "LabelName": "Apparel",
            "Language": "zh-Hans",
            "ParentLabelName": "Clothing"
        },
    		......,
    ],
    "RequestId": "0EC0B6EC-EB16-5EF4-812B-EF3A60C7D20D"
}
    

Get labels with a filter threshold

Threshold setting

  • thr: 0,85

Processing example

GET /example.jpg?x-oss-process=image/labels,thr_0.85 HTTP/1.1
Host: image-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 21 Jul 2023 08:44:58 GMT
Authorization: SignatureValue

Sample response

HTTP/1.1 200 OK
Server: AliyunOSS
Date: Fri, 21 Jul 2023 08:45:00 GMT
Content-Type: application/json;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
x-oss-request-id: 64BA458C7FFDC2383651DF09
Last-Modified: Mon, 10 Jul 2023 13:07:30 GMT
x-oss-object-type: Normal
x-oss-hash-crc64ecma: 13420962247653419692
x-oss-storage-class: Standard
x-oss-ec: 0048-00000104
Content-Disposition: attachment
x-oss-force-download: true
x-oss-server-time: 421
Content-Encoding: gzip

{
  "RequestId": "B7BDAFD5-C0AF-5042-A749-88BF6E4F2712", 
  "Labels": [
     {
      	"CentricScore": 0.797,
      	"Language": "zh-Hans",
      	"LabelConfidence": 0.927,
      	"LabelName": "Apparel",
      	"LabelLevel": 2,
      	"ParentLabelName": "Clothing"
      },
        ......,
   ]
}

Penagihan

Deteksi label citra memanggil layanan IMM. Pemanggilan ini menghasilkan item yang dapat ditagih untuk OSS dan IMM.

  • OSS: Untuk informasi harga selengkapnya, lihat Harga OSS

    API

    Item yang dapat ditagih

    Deskripsi

    GetObject

    Permintaan GET

    Ditagih berdasarkan jumlah permintaan yang berhasil.

    Lalu lintas outbound melalui internet

    Jika Anda memanggil operasi GetObject menggunakan titik akhir publik (misalnya, oss-cn-hangzhou.aliyuncs.com) atau titik akhir percepatan (misalnya, oss-accelerate.aliyuncs.com), Anda akan dikenai biaya lalu lintas outbound melalui internet. Biaya didasarkan pada volume data.

    Volume data Akses Jarang (IA) yang diambil

    Jika data yang diambil disimpan dalam kelas penyimpanan Akses Jarang (IA), Anda akan dikenai biaya pengambilan data. Biaya didasarkan pada volume data yang diambil.

    Volume data yang diambil menggunakan akses waktu nyata untuk objek Arsip

    Jika Anda membaca objek Arsip dari bucket yang telah diaktifkan akses waktu nyata untuk objek Arsip, Anda akan dikenai biaya pengambilan data. Biaya didasarkan pada volume data yang diambil.

    Akselerasi transfer

    Jika Anda mengaktifkan akselerasi transfer dan menggunakan titik akhir percepatan untuk mengakses bucket Anda, Anda akan dikenai biaya akselerasi transfer. Biaya didasarkan pada volume data.

    HeadObject

    Permintaan GET

    Ditagih berdasarkan jumlah permintaan yang berhasil.

  • IMM: Untuk informasi harga selengkapnya, lihat Item yang dapat ditagih IMM

    Penting

    Mulai pukul 11.00 pada 28 Juli 2025 (UTC+8), harga layanan deteksi label citra IMM tetap tidak berubah, tetapi nama item yang dapat ditagih akan diubah dari ImageClassification menjadi ImageLabel. Untuk informasi selengkapnya, lihat Pengumuman Penyesuaian Penagihan IMM.

    API

    Item yang dapat ditagih

    Deskripsi

    DetectImageLabels

    ImageLabel

    Ditagih berdasarkan jumlah permintaan yang berhasil.