TypeError: create_images_from_files() missing 1 required positional argument: 'batch'

Lal Balaji Govind Krishna 1 Reputation point
2020-12-24T17:08:07.303+00:00

Hello there,

I am trying to upload images to custom vision portal using python.
but when i am running the below code it is always throwing TypeError: create_images_from_files() missing 1 required positional argument: 'batch'

My code :

print ("Creating project...")
project = trainer.create_project("Bird Classification")

print("Project created!")

import os
os.chdir(r'D:\Custom Vision Sample\bird_photos')
tags = [name for name in os.listdir('.') if os.path.isdir(name)]
print(tags)

def createTag(tag):
    result = trainer.create_tag(project.id, tag)
    print(f'{tag} create with id: {result}')
    return result.id

def createImageList(tag, tag_id):

    base_image_url = fr"D:/Custom Vision Sample/bird_photos/{tag}/"
    photo_name_list = os.listdir(base_image_url)
    image_list = []
    for file_name in photo_name_list:
        with open(base_image_url+file_name, "rb") as image_contents:
            image_list.append(ImageFileCreateEntry(name=base_image_url+file_name, contents=image_contents.read(), tag_ids=[tag_id]))
    return image_list


def uploadImageList(image_list):

        upload_result = trainer.create_images_from_files(project.id, 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)
        exit(-1)


for tag in tags:
    tag_id = createTag(tag)
    print(f"tag creation done with tag id {tag_id}")
    image_list = createImageList(tag, tag_id)
    print("image_list created with length " + str(len(image_list)))

    # Break list into lists of 25 and upload in batches
    for i in range(0, len(image_list), 25):
        batchofimages = image_list[i:i + 25]
        print(f'Upload started for batch {i} total items {len(batchofimages)} for tag {tag}...')
        uploadImageList(batchofimages)
        print(f"Batch {i} Image upload completed. Total uploaded {len(batchofimages)} for tag {tag}")
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.
235 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,623 questions
{count} votes