Code Monkey home page Code Monkey logo

mslearn-ai-vision's Introduction

mslearn-ai-vision

Lab files for Azure AI Vision modules

mslearn-ai-vision's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mslearn-ai-vision's Issues

The Analyze Operation under Computer Vision APIs (2023-10-01) is not supported with the current subscription key and pricing tier OpenAI.S0.

When trying to go trough https://microsoftlearning.github.io/mslearn-ai-vision/Instructions/Exercises/01-analyze-images.html from https://learn.microsoft.com/en-gb/training/modules/analyze-images/5-exercise-computer-vision

I'm getting:

Mac-Studio:image-analysis USER$ dotnet run images/street.jpg

Analyzing images/street.jpg 

The Analyze Operation under Computer Vision APIs (2023-10-01) is not supported with the current subscription key and pricing tier OpenAI.S0.
Status: 401 (Access Denied)
ErrorCode: 401

Content:
{"error":{"code":"401","message": "The Analyze Operation under Computer Vision APIs (2023-10-01) is not supported with the current subscription key and pricing tier OpenAI.S0."}}

Headers:
apim-request-id: REDACTED
Strict-Transport-Security: REDACTED
X-Content-Type-Options: REDACTED
WWW-Authenticate: AzureApiManagementKey realm="https://XXX.openai.azure.com/computervision",name="Ocp-Apim-Subscription-Key",type="header"
Date: Sun, 26 May 2024 20:40:03 GMT
Content-Length: 178
Content-Type: application/json

created AI resource Region is "East US" and Pricing tier is "Standard S0" as stated in the instruction.

Python - Module + Attribute Error - Face Detection Azure AI SDK - 04-face-service

Detecting faces in an Image - The Issue

For reference to the specific exercise being done, please see the following. For reference to the detect-people.py file being executed, please see:

from dotenv import load_dotenv
import os
from array import array
from PIL import Image, ImageDraw
import sys
import time
from matplotlib import pyplot as plt
import numpy as np

# import namespaces
import azure.ai.vision as sdk

def main():
    global cv_client

    try:
        # Get Configuration Settings
        load_dotenv()
        ai_endpoint = os.getenv('AI_SERVICE_ENDPOINT')
        ai_key = os.getenv('AI_SERVICE_KEY')

        # Get image
        image_file = 'images/people.jpg'
        if len(sys.argv) > 1:
            image_file = sys.argv[1]

        # Authenticate Azure AI Vision client
        cv_client = sdk.VisionServiceOptions(ai_endpoint, ai_key)
        
        # Analyze image
        AnalyzeImage(image_file, cv_client)

    except Exception as ex:
        print(ex)


def AnalyzeImage(image_file, cv_client):
    print('\nAnalyzing', image_file)

    # Specify features to be retrieved (PEOPLE)
    analysis_options = sdk.ImageAnalysisOptions()
    
    features = analysis_options.features = (
        sdk.ImageAnalysisFeature.PEOPLE
    )    

    # Get image analysis
    image = sdk.VisionSource(image_file)
        
    image_analyzer = sdk.ImageAnalyzer(cv_client, image, analysis_options)
        
    result = image_analyzer.analyze()
        
    if result.reason == sdk.ImageAnalysisResultReason.ANALYZED:
        # Get people in the image
        if result.people is not None:
            print("\nPeople in image:")
            
            # Prepare image for drawing
            image = Image.open(image_file)
            fig = plt.figure(figsize=(image.width/100, image.height/100))
            plt.axis('off')
            draw = ImageDraw.Draw(image)
            color = 'cyan'
            
            for detected_people in result.people:
                # Draw object bounding box if confidence > 50%
                if detected_people.confidence > 0.5:
                    # Draw object bounding box
                    r = detected_people.bounding_box
                    bounding_box = ((r.x, r.y), (r.x + r.w, r.y + r.h))
                    draw.rectangle(bounding_box, outline=color, width=3)
                
                    # Return the confidence of the person detected
                    print(" {} (confidence: {:.2f}%)".format(detected_people.bounding_box, detected_people.confidence * 100))
                        
            # Save annotated image
            plt.imshow(image)
            plt.tight_layout(pad=0)
            outputfile = 'detected_people.jpg'
            fig.savefig(outputfile)
            print('  Results saved in', outputfile)
        
    else:
        error_details = sdk.ImageAnalysisErrorDetails.from_result(result)
        print(" Analysis failed.")
        print("   Error reason: {}".format(error_details.reason))
        print("   Error code: {}".format(error_details.error_code))
        print("   Error message: {}".format(error_details.message))

if __name__ == "__main__":
    main()

When I execute the Python command:

python detect-people.py

or in my case:

python3 detect-people.py

I receive the following error:
module 'azure.ai.vision' has no attribute 'VisionServiceOptions'

Related to issues from the code input for Authentication of the SDK at

 # import namespaces
 import azure.ai.vision as sdk

Attempting to Diagnose the Issue

I execute detect-people.py in my zsh shell from the folder that I cloned the repository. I've gone into my file path where Python is located to locate the frame work and all I can find are the Python modules related to Azure AI 102 Modules for Analyze Images Exercise 1, which are azure.ai.vision.imageanalysis modules. I opened that configuration file and compared it to how the detect-people.py file configures authentication for Azure and I literally cannot find an azure.ai.vision module configuration file - my vision folder goes straight to a subsequent imageanalysis folder. Therefore, where my Python interpreter attempts to authenticate the SDK for access to the "VisionServiceOptions" features, it cannot. The authentication of the SDK is supposed to occur here:

# Authenticate Azure AI Vision client
cv_client = sdk.VisionServiceOptions(ai_endpoint, ai_key)

I have compared the configuration file from azure.ai.vision.imageanalysis to see if I can make something analogous to that to gain access to the 'VisionServiceOptions' features, but then I look into my actual folders and see no code for 'VisionServiceOptions', so even if I rewrote the script to pull from 'imageanalysis', I wouldn't have any 'VisionServiceOptions' features to do the face detection. I've also searched to see if the Face Detection features may be named something different so I pull something different from azure.ai.vision/sdk

Examining Correlation with an Open and Related Issue

In a previous issue that was raised, I'm unsure if the issue with installing 'azure-ai-vision' is the root of the issue. When attempting to execute pip install azure-ai-vision==0.15.1b1, I receive the following:

ERROR: Could not find a version that satisfies the requirement azure-ai-vision==0.15.1b1 (from versions: none)
ERROR: No matching distribution found for azure-ai-vision==0.15.1b1

In another raised issue that is still open (#10), I agreed, at the time, with the original poster that the solution may be to use the command:

pip install azure-ai-vision-imageanalysis

However, I believe only being able to execute this command successfully may be why I'm experiencing the problem that I'm having at the moment - I never installed the VisionServiceOptions. Please help, I have a deadline to complete my training in this within a week!

Custom models in 02-image-classification fail due to dataset corruption

Classify images with a Azure AI Vision custom model

Create a custom model training project

Navigate to Custom models on the left, and select Train a new model. Use the following settings:

Name of model: classifyfruit
Model type: Image classification
Choose training dataset: training_images
Leave the rest as default, and select Train model

This fails immediately due to dataset corruption [p1].

[p1]

image

Wrong example code - Lab02 Face Detection

There is a piece of code that is in the laboratory that is wrong for the C# language as shown in print.

image

With this error, the application cannot be compiled, generating a terrible experience for the user

Notes on Exercises/01-analyze-images.html

Exercises/01-analyze-images.html:

  • Running the code on non-Windows systems (even WSL) will fail with The type initializer for 'Gdip' threw an exception.. This is the full stack trace:

    System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
     ---> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.
       at System.Drawing.SafeNativeMethods.Gdip.<>c.<.cctor>b__2_0(String _, Assembly _, Nullable`1 _)
       at System.Runtime.InteropServices.NativeLibrary.LoadLibraryCallbackStub(String libraryName, Assembly assembly, Boolean hasDllImportSearchPathFlags, UInt32 dllImportSearchPathFlags)
       at System.Drawing.SafeNativeMethods.Gdip.<GdiplusStartup>g____PInvoke|32_0(IntPtr* __token_native, StartupInputEx* __input_native, StartupOutput* __output_native)
       at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInputEx& input, StartupOutput& output)
       at System.Drawing.SafeNativeMethods.Gdip..cctor()
    
  • Background removal does not accept the parameter passed to dotnet run because the URL to images/building.jpg is hard-coded.

Python version of 04-face-service.md needs update to use ImageAnalysisClient

The instruction needs an update to use the newer azure-ai-vision-imageanalysis library instead of azure-ai-vision (Python code).

I propose the following updates for the Python code:

Prepare to use the Azure AI Vision SDK

....
Python

```
pip install azure-ai-vision-imageanalysis
```

Detect faces in an image

Python

from dotenv import load_dotenv
import os
from PIL import Image, ImageDraw
import sys

from matplotlib import pyplot as plt

# Import namespaces
from azure.ai.vision.imageanalysis import ImageAnalysisClient
from azure.core.credentials import AzureKeyCredential
from azure.ai.vision.imageanalysis.models import VisualFeatures




def main():
    global cv_client

    try:
        # Get Configuration Settings
        load_dotenv()
        ai_endpoint = os.getenv('AI_SERVICE_ENDPOINT')
        ai_key = os.getenv('AI_SERVICE_KEY')

        # Get image
        image_file = 'images/people.jpg'
        if len(sys.argv) > 1:
            image_file = sys.argv[1]

        # Authenticate Azure AI Vision client
        cv_client = ImageAnalysisClient(ai_endpoint, AzureKeyCredential(ai_key))    
        
        # Analyze image
        AnalyzeImage(image_file, cv_client)

    except Exception as ex:
        print(ex)


def AnalyzeImage(image_file, cv_client:ImageAnalysisClient):
    print('\nAnalyzing', image_file)

    
    # Get image analysis
    with open(image_file, "rb") as f:
        image_data = f.read()

    result = cv_client.analyze(image_data=image_data, visual_features= [
        VisualFeatures.PEOPLE
    ])
        

    # Get people in the image
    if result.people is not None:
        print("\nPeople in image:")
        
        # Prepare image for drawing
        image = Image.open(image_file)
        fig = plt.figure(figsize=(image.width/100, image.height/100))
        plt.axis('off')
        draw = ImageDraw.Draw(image)
        color = 'cyan'
        
        for detected_people in result.people.list:
            # Draw object bounding box if confidence > 50%
            if detected_people.confidence > 0.5:
                # Draw object bounding box
                r = detected_people.bounding_box
                bounding_box = ((r.x, r.y), (r.x + r.width, r.y + r.height))
                draw.rectangle(bounding_box, outline=color, width=3)
            
                # Return the confidence of the person detected
                print(" {} (confidence: {:.2f}%)".format(detected_people.bounding_box, detected_people.confidence * 100))
                    
        # Save annotated image
        plt.imshow(image)
        plt.tight_layout(pad=0)
        outputfile = 'detected_people.jpg'
        fig.savefig(outputfile)
        print('  Results saved in', outputfile)
    
    else:
        print(" Analysis failed.")

if __name__ == "__main__":
    main()

Contradicting Code On 01 For Python

In the Python code, the comment is written as follows:

Import namespaces

While in the instructions, both the online website instructions and the virtual lab instructions, the code is as follows:

import namespaces

Exercise "Extract custom entities" - clarification needed due to UI updates

In Step 2, when provisioning the resource, it should be clarified that the resource name is "Language" or "Language Service" and not "Azure AI Language Service", at least this is what the Azure Portal currently shows.

image

Additionally, the feature to enable custom classification is labeled under "custom features" as "Custom text classification, Custom named entity recognition, Custom summarization, Custom sentiment analysis & Custom Text Analytics for health" and there is no "asking about Additional features".
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.