Görüntü etiket algılama, bir görüntüdeki sahneler, nesneler ve olaylar gibi etiket bilgilerini tanımlar. Görüntülerinizi otomatik olarak etiketlemek için bu özelliği kullanın.
Kullanım senaryoları
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Kullanım senaryoları
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Kullanım senaryoları
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Kullanım senaryoları
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dikkat edilmesi gerekenler
Görüntü etiket algılama yalnızca JPG, PNG veya JPEG formatındaki görüntüleri destekler.
-
Görüntü boyutu için aşağıdaki sınırlar geçerlidir:
Görüntü boyutu 20 MB'ı aşamaz.
Görüntünün yüksekliği veya genişliği 30.000 pikseli aşamaz.
Görüntüdeki toplam piksel sayısı 250 milyonu aşamaz.
Görüntü etiket algılama, yalnızca
x-oss-processyöntemini kullanarak eşzamanlı işlemeyi destekler.Anonim erişim reddedilir.
Anonim erişim reddedilir.
Anonim erişim reddedilir.
Anonim erişim reddedilir.
Anonim erişim reddedilir.
Nasıl kullanılır
Ön koşullar
OSS'de bir paket oluşturun ve işlemek istediğiniz dosyaları pakete yükleyin.
Bir IMM projesi oluşturun ve iliştirin. Projeyi OSS konsolunda iliştirebilir veya bir API çağırarak iliştirebilirsiniz. IMM projesi, paket ile aynı bölgede bulunmalıdır.
Görüntü etiketlerini algılama
Aşağıdaki örneklerde yaygın SDK'lar kullanılarak etiketlerin nasıl algılanacağı gösterilmektedir. Diğer SDK'lar için bu örneklerdeki kodu uyarlayın.
Python
Python SDK 2.18.4 veya sonraki bir sürümü kullanın.
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Obtain access credentials from environment variables.
# Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Set the endpoint for the region where the bucket is located.
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)
# Specify the object key. Include the full path if the image is not in the root directory,
# for example, 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
Java SDK 3.17.4 veya sonraki bir sürümü kullanın.
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 the endpoint for the region where the bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
String region = "cn-hangzhou";
// Obtain access credentials from environment variables.
// Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
String bucketName = "examplebucket";
// Specify the object key. Include the full path if the image is not in the root directory,
// for example, 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
Go SDK 3.0.2 veya sonraki bir sürümü kullanın.
package main
import (
"fmt"
"io"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Obtain access credentials from environment variables.
// Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Set the endpoint for the region where the bucket is located.
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)
}
// Specify the object key. Include the full path if the image is not in the root directory,
// for example, 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
PHP SDK 2.7.0 veya sonraki bir sürümü kullanın.
<?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.
// Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
$provider = new EnvironmentVariableCredentialsProvider();
// Set the endpoint for the region where the bucket is located.
$endpoint = 'https://oss-cn-hangzhou.aliyuncs.com';
$bucket = 'examplebucket';
// Specify the object key. Include the full path if the image is not in the root directory,
// for example, 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;
}
Varsayılan eşik değerini kullanarak etiketleri alma
Eşik ayarı
thr parametresi belirtilmediğinden varsayılan eşik değeri olan 0,7 uygulanır.
İşleme örneği
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
Örnek yanıt
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"
}
Belirtilen bir eşik değerini kullanarak etiketleri alma
Eşik ayarı
thr parametresi 0,85 olarak ayarlanmıştır.
İşleme örneği
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
Örnek yanıt
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"
}
...
]
}
Parametreler
Eylem: image/labels
İstek parametreleri
|
|
|
|
|
|
|
|
|
|
|
|
Yalnızca yüksek güvenilirliğe sahip etiketleri döndürmek için thr değerini artırın. Daha fazla etiket döndürmek için thr değerini düşürün.
Yanıt parametreleri
Yanıt parametreleri hakkında daha fazla bilgi için bkz. DetectImageLabels - Bir görüntüde etiketleri algılama.
Faturalama
Görüntü etiket algılama IMM hizmetini çağırır. Bu nedenle hem OSS hem de IMM için faturalandırılabilir öğeler oluşur:
OSS: Fiyatlandırma bilgileri için bkz. Object Storage Service fiyatlandırması.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IMM: Fiyatlandırma bilgileri için bkz. IMM faturalandırılabilir öğeleri.
28 Temmuz 2025 tarihinde saat 11:00'den (UTC+8) itibaren IMM görüntü etiket algılama hizmetinin fiyatı değişmeyecek ancak faturalandırılabilir öğenin adı ImageClassification'tan ImageLabel'a değiştirilecektir. Daha fazla bilgi için bkz. IMM faturalandırma ayarlaması hakkında duyuru.
|
|
|
|
|
|
|
|