Skip to content

Commit

Permalink
Merge pull request #170 from Azure-Samples/pafarley-updates
Browse files Browse the repository at this point in the history
rename var
  • Loading branch information
PatrickFarley authored Oct 26, 2020
2 parents 294717c + deb85d2 commit 6f9068e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
# </snippet_tags>

# <snippet_upload>
base_image_url = "<path to repo directory>/cognitive-services-python-sdk-samples/samples/vision/"
base_image_location = "<path to repo directory>/cognitive-services-python-sdk-samples/samples/vision/"

print("Adding images...")

image_list = []

for image_num in range(1, 11):
file_name = "hemlock_{}.jpg".format(image_num)
with open(base_image_url + "images/Hemlock/" + file_name, "rb") as image_contents:
with open(base_image_location + "images/Hemlock/" + file_name, "rb") as image_contents:
image_list.append(ImageFileCreateEntry(name=file_name, contents=image_contents.read(), tag_ids=[hemlock_tag.id]))

for image_num in range(1, 11):
file_name = "japanese_cherry_{}.jpg".format(image_num)
with open(base_image_url + "images/Japanese Cherry/" + file_name, "rb") as image_contents:
with open(base_image_location + "images/Japanese Cherry/" + file_name, "rb") as image_contents:
image_list.append(ImageFileCreateEntry(name=file_name, contents=image_contents.read(), tag_ids=[cherry_tag.id]))

upload_result = trainer.create_images_from_files(project.id, ImageFileCreateBatch(images=image_list))
Expand Down Expand Up @@ -88,7 +88,7 @@
prediction_credentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key})
predictor = CustomVisionPredictionClient(ENDPOINT, prediction_credentials)

with open(base_image_url + "images/Test/test_image.jpg", "rb") as image_contents:
with open(base_image_location + "images/Test/test_image.jpg", "rb") as image_contents:
results = predictor.classify_image(
project.id, publish_iteration_name, image_contents.read())

Expand Down
8 changes: 4 additions & 4 deletions python/CustomVision/ObjectDetection/CustomVisionQuickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

# <snippet_upload>
# Update this with the path to where you downloaded the images.
base_image_url = "<path to repo directory>/cognitive-services-python-sdk-samples/samples/vision/"
base_image_location = "<path to repo directory>/cognitive-services-python-sdk-samples/samples/vision/"

# Go through the data table above and create the images
print ("Adding images...")
Expand All @@ -98,14 +98,14 @@
x,y,w,h = fork_image_regions[file_name]
regions = [ Region(tag_id=fork_tag.id, left=x,top=y,width=w,height=h) ]

with open(base_image_url + "images/fork/" + file_name + ".jpg", mode="rb") as image_contents:
with open(base_image_location + "images/fork/" + file_name + ".jpg", mode="rb") as image_contents:
tagged_images_with_regions.append(ImageFileCreateEntry(name=file_name, contents=image_contents.read(), regions=regions))

for file_name in scissors_image_regions.keys():
x,y,w,h = scissors_image_regions[file_name]
regions = [ Region(tag_id=scissors_tag.id, left=x,top=y,width=w,height=h) ]

with open(base_image_url + "images/scissors/" + file_name + ".jpg", mode="rb") as image_contents:
with open(base_image_location + "images/scissors/" + file_name + ".jpg", mode="rb") as image_contents:
tagged_images_with_regions.append(ImageFileCreateEntry(name=file_name, contents=image_contents.read(), regions=regions))

upload_result = trainer.create_images_from_files(project.id, ImageFileCreateBatch(images=tagged_images_with_regions))
Expand Down Expand Up @@ -135,7 +135,7 @@
# Now there is a trained endpoint that can be used to make a prediction

# Open the sample image and get back the prediction results.
with open(base_image_url + "images/Test/test_od_image.jpg", mode="rb") as test_data:
with open(base_image_location + "images/Test/test_od_image.jpg", mode="rb") as test_data:
results = predictor.detect_image(project.id, publish_iteration_name, test_data)

# Display the results.
Expand Down

0 comments on commit 6f9068e

Please sign in to comment.