使用Azure Custom Vision自定义视觉对濒危鸟类进行分类

 

 

如果仅仅用来预测,可以使用如下函数。

 

桌面端的预测程序

from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClient
from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient
from azure.cognitiveservices.vision.customvision.training.models import ImageFileCreateBatch, ImageFileCreateEntry, Region
from msrest.authentication import ApiKeyCredentials
import os, time, uuid

'''
ENDPOINT = "PASTE_YOUR_CUSTOM_VISION_TRAINING_ENDPOINT_HERE"
training_key = "PASTE_YOUR_CUSTOM_VISION_TRAINING_SUBSCRIPTION_KEY_HERE"
prediction_key = "PASTE_YOUR_CUSTOM_VISION_PREDICTION_SUBSCRIPTION_KEY_HERE"
prediction_resource_id = "PASTE_YOUR_CUSTOM_VISION_PREDICTION_RESOURCE_ID_HERE"
'''
# Replace with valid values
ENDPOINT = "https://birdcustom0609.cognitiveservices.azure.com/"
training_key = "c9192ddfe8d8411d8bfaa72ae1e4741e"
prediction_key = "c58af1aa063b455b892836b2dbae9d27"
prediction_resource_id = "birdcustom0609-prediction"


credentials = ApiKeyCredentials(in_headers={"Training-key": training_key})
trainer = CustomVisionTrainingClient(ENDPOINT, credentials)
prediction_credentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key})
predictor = CustomVisionPredictionClient(ENDPOINT, prediction_credentials)

publish_iteration_name = "Iteration1"

credentials = ApiKeyCredentials(in_headers={"Training-key": training_key})
trainer = CustomVisionTrainingClient(ENDPOINT, credentials)
base_image_location = os.path.join (os.path.dirname(__file__), "Images")
projectID = "0568b68f-5b92-43e7-9449-741bcb343c12"

# Now there is a trained endpoint that can be used to make a prediction
prediction_credentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key})
predictor = CustomVisionPredictionClient(ENDPOINT, prediction_credentials)

#with open(os.path.join (base_image_location, "Test/test_image.jpg"), "rb") as image_contents:BX7vjSt8KMtcBHyisvcSPK-1200-80.jpg
with open(os.path.join (base_image_location, "Test/BX7vjSt8KMtcBHyisvcSPK-1200-80.jpg"), "rb") as image_contents:
    results = predictor.classify_image(
        projectID, publish_iteration_name, image_contents.read())

    # Display the results.
    for prediction in results.predictions:
        print("\t" + prediction.tag_name +
              ": {0:.2f}%".format(prediction.probability * 100))

 

相关材料:

 使用自定义视觉对濒危鸟类进行分类

https://docs.microsoft.com/zh-cn/learn/modules/cv-classify-bird-species/5-deploy-model

 

快速入门:使用自定义视觉客户端库或 REST API 创建图像分类项目

https://docs.microsoft.com/zh-cn/azure/cognitive-services/Custom-Vision-Service/quickstarts/image-classification?tabs=visual-studio&pivots=programming-language-python

 

微软MVP精选 | 1小时快速搭建基于Azure Custom Vision和树莓派的鸟类识别应用

https://mp.weixin.qq.com/s/VaM89abLmUnhpxI3o_TPHQ

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值