Annotation uploaded not showing up on Custom Vision

Rishi Khemka 60 Reputation points
2024-05-28T04:51:23.0466667+00:00

Hi im using the below python code to upload my images and annotation to azure custom vision studio

from azure.cognitiveservices.vision.customvision.training.models import Region, ImageFileCreateEntry, ImageFileCreateBatch

def upload_images_and_annotations(trainer, project_id, images, annotations, tags):

successfully_uploaded = 0

for (filename, image), (ann_filename, annotation) in zip(images, annotations):

if filename != ann_filename:

if successfully_uploaded == 76:

print(image)

print(f"Skipping {filename} as it does not match annotation filename {ann_filename}")

continue

_, img_encoded = cv2.imencode('.jpg', (image * 255).astype('uint8')) # Convert back to original scale for encoding

img_bytes = img_encoded.tobytes()

regions = []

for obj in annotation.findall('object'):

label = obj.find('name').text

if label in tags: # Ensure the annotation matches one of the tags

bndbox = obj.find('bndbox')

xmin = int(bndbox.find('xmin').text)

ymin = int(bndbox.find('ymin').text)

xmax = int(bndbox.find('xmax').text)

ymax = int(bndbox.find('ymax').text)

width = (xmax - xmin) / image.shape[1]

height = (ymax - ymin) / image.shape[0]

left = xmin / image.shape[1]

top = ymin / image.shape[0]

regions.append(Region(

tag_id=tags[label].id,

left=left,

top=top,

width=width,

height=height

))

if regions:

try:

image_entry = ImageFileCreateEntry(name=filename, contents=img_bytes, regions=regions)

upload_result = trainer.create_images_from_files(project_id, ImageFileCreateBatch(images=[image_entry]))

if upload_result.is_batch_successful:

print(f"Successfully uploaded {filename}")

successfully_uploaded += 1

else:

print(f"Failed to upload {filename}: {upload_result}")

except Exception as e:

print(f"Error uploading {filename}: {e}")

print(f"Successfully uploaded {successfully_uploaded} images out of {len(images)}")

Now im able to see the uploaded images on the vision portal with tags in each but im not able to hover over the tag and see the exact bounding box of my object

User's image

but if i manually upload to the studio and draw bounding box around the object of my need, then after i save & close - when i review the image the hovering on tag shows the exact bounding box of the object, why this discrepancy?

Azure AI Custom Vision
Azure AI Custom Vision
An Azure artificial intelligence service and end-to-end platform for applying computer vision to specific domains.
249 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.