前言
ONE-PEACE是一个图文音三模态通用表征模型,在语义分割、音文检索、音频分类和视觉定位几个任务都达到了新SOTA表现,在视频分类、图像分类图文检索、以及多模态经典benchmark也都取得了比较领先的结果。
快速调用
调用前准备
已开通服务并获得API-KEY:开通DashScope并创建API-KEY
已安装最新版SDK:安装DashScope SDK。
代码示例
API-KEY设置
export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY
在完成了上面的API-KEY的设置之后,就可以通过下面的示例代码提交请求了。
import dashscope
def image_call():
input = [{'image': 'https://dashscope.oss-cn-beijing.aliyuncs.com/images/256_1.png'},
]
result = dashscope.MultiModalEmbedding.call(model=dashscope.MultiModalEmbedding.Models.multimodal_embedding_one_peace_v1,
input=input,
auto_truncation=True)
print(result)
if __name__ == '__main__':
image_call()
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.embeddings.MultiModalEmbedding;
import com.alibaba.dashscope.embeddings.MultiModalEmbeddingItemImage;
import com.alibaba.dashscope.embeddings.MultiModalEmbeddingParam;
import com.alibaba.dashscope.embeddings.MultiModalEmbeddingResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import java.util.Arrays;
public class Main {
public static void imageEmbedding() throws ApiException, NoApiKeyException, UploadFileException {
MultiModalEmbedding embedding = new MultiModalEmbedding();
MultiModalEmbeddingItemImage image =
new MultiModalEmbeddingItemImage(
"https://dashscope.oss-cn-beijing.aliyuncs.com/images/256_1.png");
MultiModalEmbeddingParam param =
MultiModalEmbeddingParam.builder()
.model(MultiModalEmbedding.Models.MULTIMODAL_EMBEDDING_ONE_PEACE_V1)
.contents(Arrays.asList(image))
.build();
MultiModalEmbeddingResult result = embedding.call(param);
System.out.print(result);
}
public static void main(String[] args){
try {
imageEmbedding();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
示例输出
上面示例代码请求正常完成之后,将会收到如下示例的返回结果。
{
"status_code": 200,
"request_id": "4fe2cde6-ba37-973f-9db8-2cd74a908a9f",
"code": "",
"message": "",
"output": {
"embedding": [ # The embedding vector
-0.0200169887393713,
.,
.,
.,
]
},
"usage": {
"image": {
"measure": 1,
"weight": 1
},
"total_usage": 4,
"audio": {
"measure": 1,
"weight": 2
},
"text": {
"measure": 1,
"weight": 1
}
}
}
了解更多
有关ONE-PEACE多模态向量表征API的详细调用文档可前往API详情页面进行了解。
文档内容是否对您有帮助?