Deteksi label gambar mengidentifikasi informasi label seperti pemandangan, objek, dan event dalam sebuah gambar. Gunakan fitur ini untuk memberi tag pada gambar Anda secara otomatis.
Kasus penggunaan
Scenario | Description |
Content recognition | Detect items, scenes, and other information in captured or uploaded images for object recognition or educational applications. |
Smart album | Classify images automatically based on content to organize photo albums and galleries without manual effort. |
Scene analysis | Detect objects and scenes in images, then apply content labels to reduce manual annotation costs. |
Content operations | Retrieve image labels for content recommendation on social media, news, and e-commerce platforms. |
Kasus penggunaan
Scenario | Description |
Content recognition | Detect items, scenes, and other information in captured or uploaded images for object recognition or educational applications. |
Smart album | Classify images automatically based on content to organize photo albums and galleries without manual effort. |
Scene analysis | Detect objects and scenes in images, then apply content labels to reduce manual annotation costs. |
Content operations | Retrieve image labels for content recommendation on social media, news, and e-commerce platforms. |
Kasus penggunaan
Scenario | Description |
Content recognition | Detect items, scenes, and other information in captured or uploaded images for object recognition or educational applications. |
Smart album | Classify images automatically based on content to organize photo albums and galleries without manual effort. |
Scene analysis | Detect objects and scenes in images, then apply content labels to reduce manual annotation costs. |
Content operations | Retrieve image labels for content recommendation on social media, news, and e-commerce platforms. |
Kasus penggunaan
Scenario | Description |
Content recognition | Detect items, scenes, and other information in captured or uploaded images for object recognition or educational applications. |
Smart album | Classify images automatically based on content to organize photo albums and galleries without manual effort. |
Scene analysis | Detect objects and scenes in images, then apply content labels to reduce manual annotation costs. |
Content operations | Retrieve image labels for content recommendation on social media, news, and e-commerce platforms. |
Peringatan
Deteksi label gambar hanya mendukung gambar dalam format JPG, PNG, atau JPEG.
Batas berikut berlaku untuk ukuran gambar:
Ukuran gambar tidak boleh melebihi 20 MB.
Tinggi atau lebar gambar tidak boleh melebihi 30.000 piksel.
Jumlah total piksel dalam gambar tidak boleh melebihi 250 juta.
Deteksi label gambar hanya mendukung pemrosesan sinkron menggunakan metode
x-oss-process.-
Akses anonim akan ditolak.
Akses anonim akan ditolak.
Akses anonim akan ditolak.
Akses anonim akan ditolak.
Akses anonim akan ditolak.
Cara menggunakan
Prasyarat
Di OSS, buat bucket dan unggah file yang ingin diproses ke bucket tersebut.
Buat dan sambungkan proyek IMM. Anda dapat menyambungkannya di konsol OSS atau dengan memanggil API. Proyek IMM harus berada di Wilayah yang sama dengan bucket.
Deteksi label gambar
Contoh berikut menunjukkan cara mendeteksi label menggunakan SDK umum. Sesuaikan kode dari contoh ini untuk SDK lainnya.
Python
Gunakan Python SDK versi 2.18.4 atau lebih baru.
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Dapatkan kredensial akses dari variabel lingkungan.
# Atur OSS_ACCESS_KEY_ID dan OSS_ACCESS_KEY_SECRET sebelum menjalankan kode ini.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Atur endpoint untuk wilayah tempat bucket berada.
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)
# Tentukan kunci objek. Sertakan path lengkap jika gambar tidak berada di direktori root,
# misalnya exampledir/example.jpg.
key = 'example.jpg'
process = 'image/labels'
try:
result = bucket.get_object(key, process=process)
image_labels = result.read().decode('utf-8')
print("Image labels:")
print(image_labels)
except oss2.exceptions.OssError as e:
print("Error:", e)Java
Gunakan Java SDK versi 3.17.4 atau 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 {
// Atur endpoint untuk wilayah tempat bucket berada.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
String region = "cn-hangzhou";
// Dapatkan kredensial akses dari variabel lingkungan.
// Atur OSS_ACCESS_KEY_ID dan OSS_ACCESS_KEY_SECRET sebelum menjalankan kode ini.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
String bucketName = "examplebucket";
// Tentukan kunci objek. Sertakan path lengkap jika gambar tidak berada di direktori root,
// misalnya exampledir/example.jpg.
String key = "example.jpg";
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
getObjectRequest.setProcess("image/labels");
OSSObject ossObject = ossClient.getObject(getObjectRequest);
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 {
ossClient.shutdown();
}
}
}Go
Gunakan Go SDK versi 3.0.2 atau lebih baru.
package main
import (
"fmt"
"io"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Dapatkan kredensial akses dari variabel lingkungan.
// Atur OSS_ACCESS_KEY_ID dan OSS_ACCESS_KEY_SECRET sebelum menjalankan kode ini.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Atur endpoint untuk wilayah tempat bucket berada.
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)
}
bucket, err := client.Bucket("examplebucket")
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Tentukan kunci objek. Sertakan path lengkap jika gambar tidak berada di direktori root,
// misalnya exampledir/example.jpg.
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("Image labels:", string(data))
}PHP
Gunakan PHP SDK versi 2.7.0 atau 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 {
// Dapatkan kredensial akses dari variabel lingkungan.
// Atur OSS_ACCESS_KEY_ID dan OSS_ACCESS_KEY_SECRET sebelum menjalankan kode ini.
$provider = new EnvironmentVariableCredentialsProvider();
// Atur endpoint untuk wilayah tempat bucket berada.
$endpoint = 'https://oss-cn-hangzhou.aliyuncs.com';
$bucket = 'examplebucket';
// Tentukan kunci objek. Sertakan path lengkap jika gambar tidak berada di direktori root,
// misalnya exampledir/example.jpg.
$key = 'example.jpg';
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"region" => "cn-hangzhou"
);
$ossClient = new OssClient($config);
$options[$ossClient::OSS_PROCESS] = "image/labels";
$result = $ossClient->getObject($bucket, $key, $options);
var_dump($result);
} catch (OssException $e) {
printf($e->getMessage() . "\n");
return;
}Dapatkan label menggunakan ambang batas default
Pengaturan ambang batas
Parameter thr tidak ditentukan, sehingga ambang batas default 0,7 berlaku.
Contoh pemrosesan
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: SignatureValueContoh respons
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"
}Dapatkan label menggunakan ambang batas tertentu
Pengaturan ambang batas
Parameter thr diatur ke 0,85.
Contoh pemrosesan
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: SignatureValueContoh respons
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"
}
...
]
}Parameter
Action: image/labels
Parameter permintaan
Parameter | Type | Required | Description | Example |
thr | float | No | Label yang memiliki nilai | 0,5 |
Tingkatkan nilai thr untuk hanya mengembalikan label dengan tingkat kepercayaan tinggi. Turunkan nilai thr untuk mengembalikan lebih banyak label.
Parameter respons
Untuk informasi selengkapnya tentang parameter respons, lihat DetectImageLabels - Detect labels in an image.
Penagihan
Deteksi label gambar memanggil IMM. Oleh karena itu, fitur ini menghasilkan item yang dapat ditagih untuk OSS dan IMM:
OSS: Untuk informasi harga, lihat Harga Object Storage Service.
API | Billable item | Description |
GetObject | GET requests | Anda dikenai biaya berdasarkan jumlah permintaan yang berhasil. |
GetObject | Outbound traffic over the internet | Jika Anda memanggil operasi GetObject menggunakan titik akhir publik (misalnya, titik akhir China (Hangzhou) oss-cn-hangzhou.aliyuncs.com) atau titik akhir percepatan (misalnya, oss-accelerate.aliyuncs.com), Anda dikenai biaya lalu lintas keluar melalui internet berdasarkan volume data. |
GetObject | Volume of retrieved Infrequent Access (IA) data | Jika data yang diambil adalah data Akses Jarang (IA), Anda dikenai biaya pengambilan data berdasarkan volume data yang diambil. |
GetObject | Volume of data retrieved by using real-time access of Archive objects | Jika Anda membaca objek Arsip dari bucket yang telah diaktifkan akses waktu nyata untuk objek Arsip, Anda dikenai biaya pengambilan data menggunakan akses waktu nyata untuk objek Arsip berdasarkan volume data yang diambil. |
GetObject | Transfer acceleration | Jika akselerasi transfer diaktifkan dan Anda menggunakan titik akhir percepatan untuk mengakses bucket Anda, Anda dikenai biaya akselerasi transfer berdasarkan volume data. |
HeadObject | GET requests | Anda dikenai biaya berdasarkan jumlah permintaan yang berhasil. |
IMM: Untuk informasi harga, lihat Item yang dapat ditagih IMM.
Mulai pukul 11.00 (UTC+8) pada 28 Juli 2025, harga layanan deteksi label gambar IMM tetap tidak berubah, tetapi item yang dapat ditagih diubah namanya dari ImageClassification menjadi ImageLabel. Untuk informasi selengkapnya, lihat Pengumuman penyesuaian penagihan IMM.
API | Billable item | Description |
DetectImageLabels | ImageLabel | Anda dikenai biaya berdasarkan jumlah permintaan yang berhasil. |