microsoft / studentambassadors

This repository is for Microsoft Learn Student Ambassadors.
MIT License
130 stars 47 forks source link

Custom Vision module exercise buggy code #126

Open 0-BSCode opened 1 year ago

0-BSCode commented 1 year ago

Describe the bug

In the Exercise - Upload the data portion of the module, one of the options provided to upload the images is to use Python and the Custom Vision SDK to upload and tag images. In the section discussing this, there is a repo that we may clone so we can download the code right away instead of coding the upload script from scratch. However, executing the downloaded code results in errors. Furthermore, there are a number of discrepancies between the downloaded code and the code provided in the instructions.

To Reproduce

Steps to reproduce the behavior:

  1. Clone the repo mentioned in the instructions onto your local machine.
  2. Navigate to the local repository and unzip the bird-photos zip file in the project directory.
  3. Open the jupyter notebook file and replace the path provided in the os.chdir() function with the path to where your photos are stored.
  4. Replace the ENDPOINT and training_key variables with the endpoint and training key provided by your Custom Vision resource.
  5. Select the "Run All" cells option for the notebook.
  6. Error is encountered (invalid arguments)

Expected behavior

Images should be uploaded onto your created Custom Vision project and the model can be trained, published, and tested using the downloaded script.

Fix

  1. Update the CustomVisionTrainingClient function call in the "Create Custom Vision Project" section.
    # Provided code
    ENDPOINT = "<YourEndpointHere>"
    training_key = "<YourKeyHere>"
    trainer = CustomVisionTrainingClient(training_key, endpoint=ENDPOINT)
    # Functional code
    ENDPOINT = "<YourEndpointHere>"
    training_key = "<YourKeyHere>"
    credentials = ApiKeyCredentials(in_headers={"Training-key": training_key}) # Imported from msrest.authentication
    trainer = CustomVisionTrainingClient(ENDPOINT, credentials)
  2. Update the create_images_from_files function call under the uploadImageList function in the "uploadImageList function to upload list of images" section.
    # Provided code
    upload_result = trainer.create_images_from_files(project.id, images=image_list)
    upload_result = trainer.create_images_from_files(project_id=project.id, batch=ImageFileCreateBatch(images=image_list)) # ImageFileCreateBatch is imported from azure.cognitiveservices.vision.customvision.training.models
  3. Update the CustomVisionPredictionClient function call at the start of the "Test the published endpoint" section.
    # Provided code
    prediction_key = "<YourKeyHere>"
    endpoint = "https://<UpdateWithYourEndpoint>-prediction.cognitiveservices.azure.com/"
    base_image_url = "./"
    publish_iteration_name = "<YourIterationNameHere>"
    project_id = "<YourProjectIdHere>"
    predictor = CustomVisionPredictionClient(prediction_key, endpoint=endpoint)
    # Functional code
    prediction_key = "<YourKeyHere>"
    endpoint = "https://<UpdateWithYourEndpoint>-prediction.cognitiveservices.azure.com/"
    base_image_url = "./"
    publish_iteration_name = "<YourIterationNameHere>"
    project_id = "<YourProjectIdHere>"
    pCredentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key})
    predictor = CustomVisionPredictionClient(endpoint, pCredentials)

Desktop (please complete the following information):

Additional context

Attached below are the details elaborating on how I discovered the issues and how I came about fixing them.

Under the "Create Custom Vision Project" cell, we run into an error saying we got multiple values for the 'endpoint' argument upon initializing CustomVisionTrainingClient. Erroneous code from downloaded repo

Upon reviewing the instructions provided in the module, the following is the code that's supposed to be utilized, which is different from the downloaded code. Code provided by instructions

Updating the downloaded code to follow the code from the module results in the successful creation of a project. Error is fixed by following the code from the instructions

However, another issue is encountered in the "Loop thru tags and call each function..." cell which comes from a faulty function call under the uploadImageList function. Error from downloaded code due to faulty function call

Once again, another discrepancy is found between the function call from the downloaded code and the function call from the code provided in the instructions, the difference being the create_images_from_files function call. Code from instructions

However, changing this to the code provided by the instructions results in a different error. Another error is encountered

According to this issue, the issue can be fixed by updating the create_images_from_files function call. Doing so stops the error from occurring.


Student, Student Ambassador


BethanyJep commented 1 year ago

Wow, great work on debugging, I will work to ensure this is implemented.