Search⌘ K
AI Features

Image Classifier Using SDK - Uploading and Training the Model

Understand how to upload images with tags to an Azure Custom Vision project and train a custom image classifier model using the SDK. This lesson guides you through reading image files, assigning tags, uploading batches, and initiating model training, including tracking training status for building a functional image classification solution.

Let’s continue the implementation part. Just to recap, in the previous lesson, we’ve created the training and prediction client objects. We’ve also created a project and added the two image tags that we’re interested in.

Now, we’re going to upload the images with their tags to our Custom Vision project and then we’ll train our custom model.

Uploading the images with their tags

Now let’s upload the images and their corresponding tags to the Custom Vision project.

Python
base_image_location = "CourseAssets/ImageClassification/Images"
print("Adding images...")
image_list = []
for image_num in range(1, 11):
file_name = "hemlock_{}.jpg".format(image_num)
with open(base_image_location + "/Hemlock/" + file_name, "rb") as hemlock_image:
image_list.append(
ImageFileCreateEntry(
name = file_name,
contents = hemlock_image.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_location + "/Japanese_Cherry/" + file_name, "rb") as cherry_image:
image_list.append(
ImageFileCreateEntry(
name = file_name,
contents = cherry_image.read(),
tag_ids = [cherry_tag.id]
)
)
upload_result = trainer.create_images_from_files(
project.id,
ImageFileCreateBatch(images = image_list)
)
if not upload_result.is_batch_successful:
print("Image batch upload failed.")
for image in upload_result.images:
print("Image status: ", image.status)
else:
print("Imaged Added Successfully!!")
  • In line 1, we define the location of the “Images” folder present in our working directory.

  • In line 5, we define a list named image_list that will ...