-
Notifications
You must be signed in to change notification settings - Fork 1
/
CVapi.py
25 lines (21 loc) · 1.21 KB
/
CVapi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from azure.cognitiveservices.vision.customvision.training import training_api
from azure.cognitiveservices.vision.customvision.training.models import ImageUrlCreateEntry
from azure.cognitiveservices.vision.customvision.prediction import prediction_endpoint
from azure.cognitiveservices.vision.customvision.prediction.prediction_endpoint import models
projectid = '############'
# Replace with a valid key
training_key = "###########"
prediction_key = "##################"
trainer = training_api.TrainingApi(training_key)
predictor = prediction_endpoint.PredictionEndpoint(prediction_key)
iteration = trainer.train_project(projectid)
results = predictor.predict_image(projectid, open("m.jpg", mode="rb").read(), iteration.id)
# Alternatively, if the images were on disk in a folder called Images alongside the sample.py, then
# they can be added by using the following.
#
# Open the sample image and get back the prediction results.
# with open("Images\\test\\test_image.jpg", mode="rb") as test_data:
# results = predictor.predict_image(project.id, test_data.read(), iteration.id)
# Display the results.
for prediction in results.predictions:
print ("\t" + prediction.tag + ": {0:.2f}%".format(prediction.probability * 100))