Skip to content

Instantly share code, notes, and snippets.

@sanjeevdwivedi
Last active March 23, 2018 03:24
Show Gist options
  • Save sanjeevdwivedi/210d83117b8c992207e5a8e969ecd76c to your computer and use it in GitHub Desktop.
Save sanjeevdwivedi/210d83117b8c992207e5a8e969ecd76c to your computer and use it in GitHub Desktop.
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
import os
import sys
import json, requests
import time
training_key = "5bd2f1fd171c427aa1009ff0304d5802" # from settings pane on customvision.ai
prediction_key = "c0bc732ba400470e936aef357942ad9c"
project_name = "blighthack"
tagname = ""
dowhat = "nothing"
# Check if the project with project_name exists and if not create ir
project_id = "a5835760-4363-47ef-b052-bbaeb06cd54d"
trainer = training_api.TrainingApi(training_key)
def upload_single_image_from_url(image_url, tag_name):
print('project id is: ' + project_id)
alltags = trainer.get_tags(project_id)
tag_id = None
for i in range(0, len(alltags.tags)):
if (alltags.tags[i].name == tag_name):
tagExists = True
tag_id = alltags.tags[i].id
break
if tag_id is not None:
trainer.create_images_from_urls(project_id, [ImageUrlCreateEntry(image_url, [tag_id])])
else:
print('No tag by name: ' + tag_name + " found")
upload_single_image_from_url('http://www.catster.com/wp-content/uploads/2017/11/A-Siamese-cat.jpg', 'boarded')
@sanjeevdwivedi
Copy link
Author

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

import os
import sys
import json, requests
import time

training_key = "5bd2f1fd171c427aa1009ff0304d5802" # from settings pane on customvision.ai
prediction_key = "c0bc732ba400470e936aef357942ad9c"

project_name = "blighthack"
tagname = ""

dowhat = "nothing"

Check if the project with project_name exists and if not create ir

project_id = "a5835760-4363-47ef-b052-bbaeb06cd54d"
trainer = training_api.TrainingApi(training_key)

def upload_single_image_from_url(image_url, tag_name):
print('project id is: ' + project_id)
alltags = trainer.get_tags(project_id)

tag_id = None
for i in range(0, len(alltags.tags)):
    if (alltags.tags[i].name == tag_name):
        tagExists = True
        tag_id = alltags.tags[i].id
        break

if tag_id is not None:
    trainer.create_images_from_urls(project_id, [ImageUrlCreateEntry(image_url, [tag_id])])
else:
    print('No tag by name: ' + tag_name + " found")

upload_single_image_from_url('http://www.catster.com/wp-content/uploads/2017/11/A-Siamese-cat.jpg', 'boarded')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment