NO IMAGE

參考:
1、http://ai.baidu.com/docs#/ImageClassify-Python-SDK/top

2、http://blog.csdn.net/wc781708249/article/details/78558860


程式碼

# -*- coding: UTF-8 -*-  
from aip import AipImageClassify
# import cv2
# import matplotlib.pyplot as plt
# 定義常量  
APP_ID = '10376628'
API_KEY = 'nf66Tjv0NnbkzcodwqMzUuTp'
SECRET_KEY = 'fYv9H15VrwGnGerhGyxgOo4cOgAw2ypy'
# 初始化影象分類器  
imgClass=AipImageClassify(APP_ID, API_KEY, SECRET_KEY)
# 讀取圖片  
filePath = "1.jpg"
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
# 定義引數變數
options = {}
options["top_num"] = 5 # 輸出前5個可能性預測
# 呼叫動物分類器
result=imgClass.animalDetect(get_file_content(filePath),options)
# 呼叫汽車分類器
result=imgClass.carDetect(get_file_content(filePath),options)
print(result)

輸出結果:

{'log_id': 3322611835559934374, 'result': [{'score': '0.2834', 'name': '異國短毛貓'}, {'score': '0.159157', 'name': '美國硬毛貓'}, {'score': '0.109393', 'name': '美國短毛貓'}, {'score': '0.0743276', 'name': '歐洲短毛貓'}, {'score': '0.0557966', 'name': '馬恩島貓'}]}

附加

APP_ID、API_KEY、SECRET_KEY的獲取
參考:http://blog.csdn.net/wc781708249/article/details/78558860