Image Service Content Moderation

Meryln Peter 25 Reputation points
2023-10-09T10:14:14.85+00:00

Hi Team,

I work for retail client where I will be uploading images like products on shelves you have to moderate the images based on the content classification. Any Azure AI service is there and please recommend any Python code. Any leads that will be appreciated.

Regards,

Meryln

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,645 questions
0 comments No comments
{count} votes

Accepted answer
  1. Janarthanan S 700 Reputation points
    2023-10-25T13:41:28.08+00:00

    Hi @Meryln Peter

    Since you work for retail client especially products on shelves images in order to moderate the images use Computer Vision and Content Safety service.

    The Product Recognition APIs let you analyze photos of shelves in a retail store. You can detect the presence of products and get their bounding box coordinates. Use it in combination with model customization to train a model to identify your specific products.

    Please find detailed documentation for computer vision product on shelves

    https://learn.microsoft.com/en-us/azure/ai-services/computer-vision/concept-shelf-analysis

    In order to moderate the content on images use detailed documentation

    https://learn.microsoft.com/en-us/azure/ai-services/content-safety/overview

    Please find sample python code to moderate the image content on the product on the shelves.

    def analyze_image():
        # [START analyze_image]
        
        import os
        from azure.ai.contentsafety import ContentSafetyClient
        from azure.core.credentials import AzureKeyCredential
        from azure.core.exceptions import HttpResponseError
        from azure.ai.contentsafety.models import AnalyzeImageOptions, ImageData
    
        key = os.environ["CONTENT_SAFETY_KEY"]
        endpoint = os.environ["CONTENT_SAFETY_ENDPOINT"]
        image_path = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "./sample_data/image.jpg"))
    
        # Create an Content Safety client
        client = ContentSafetyClient(endpoint, AzureKeyCredential(key))
    
        # Build request
        with open(image_path, "rb") as file:
            request = AnalyzeImageOptions(image=ImageData(content=file.read()))
    
        # Analyze image
        try:
            response = client.analyze_image(request)
        except HttpResponseError as e:
            print("Analyze image failed.")
            if e.error:
                print(f"Error code: {e.error.code}")
                print(f"Error message: {e.error.message}")
                raise
            print(e)
            raise
    
        if response.hate_result:
            print(f"Hate severity: {response.hate_result.severity}")
        if response.self_harm_result:
            print(f"SelfHarm severity: {response.self_harm_result.severity}")
        if response.sexual_result:
            print(f"Sexual severity: {response.sexual_result.severity}")
        if response.violence_result:
            print(f"Violence severity: {response.violence_result.severity}")
    
        # [END analyze_image]
    
    
    if __name__ == "__main__":
        analyze_image()
    

    Please try out these steps with your data and check if it works. Hope this answer helps you with solution! Please comment below if you need any assistance on the same. Happy to help!

    Regards,

    Janarthanan S

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. VasaviLankipalle-MSFT 15,956 Reputation points
    2023-10-09T22:10:16.6033333+00:00

    Hello @Meryln Peter , Thanks for using Microsoft Q&A Platform.

    As we know the Azure AI Vision Image Analysis service can extract a wide variety of visual features from the images. I would suggest going through the product recognition APIs which let you analyze photos of shelves in a retail store https://learn.microsoft.com/en-us/azure/ai-services/computer-vision/concept-shelf-analysis

    Here is the python GitHub sample code related to the product recognition: https://github.com/Azure-Samples/cognitive-service-vision-model-customization-python-samples/blob/8809aac5c5762c751de39c4a853e8e9bf7612be7/cognitive_service_vision_model_customization_python_samples/models/product_recognition_model.py

    Please review these and see if that fits your use case.

    I hope this helps.

    Regards,
    Vasavi

    -Please kindly accept the answer and vote 'yes' if you feel helpful to support the community, thanks.

    0 comments No comments