Azure Cognitive Services Computer Vision API

Category: AI + Machine Learning Views: 15,432 Replies: 18 Last reply: Today
AJ

Hello everyone,

I'm working on a project that involves analyzing images using Azure Cognitive Services Computer Vision API. I've successfully set up the resource and can make basic API calls, but I'm running into some issues with custom model training. Specifically, I'm trying to train a model to detect specific types of objects in medical imaging data. Has anyone had experience with fine-tuning the Computer Vision models or using custom image classification?

I've looked at the documentation, but some of the steps for data preparation and labeling seem a bit unclear. Any guidance or examples would be greatly appreciated!

Thanks in advance!

SM

Hi Alex,

I've done some work with custom image classification using Azure Custom Vision, which is a part of Cognitive Services. It's designed precisely for scenarios like yours where you need to detect custom objects. Are you using the general Computer Vision API directly for custom training, or have you explored the Custom Vision service?

The Custom Vision portal provides a user-friendly interface for uploading images, labeling them, training models, and evaluating performance. For data preparation, ensure your images are consistently sized (or the service handles resizing well) and that your labels are accurate and comprehensive. You can also export the trained model for use with other applications.

Let me know if you want to dive deeper into Custom Vision!

AJ

Hi Sarah,

Thanks for the quick reply! You're right, I think I was confusing the general Computer Vision API with the Custom Vision service. I'll definitely look into Custom Vision. The portal sounds much more streamlined for labeling and training.

My main challenge was the sheer volume of data and the specific nature of the medical images. I'm concerned about ensuring the model generalizes well. Do you have any tips for dealing with imbalanced datasets or using transfer learning effectively with Custom Vision?

SK

Hey Alex,

Regarding imbalanced datasets in Custom Vision, you can often mitigate this by oversampling the minority class (by duplicating images or using data augmentation) or undersampling the majority class. Custom Vision itself has some internal mechanisms to handle this, but it's good practice to pre-process your data.

For transfer learning, Custom Vision implicitly uses transfer learning from pre-trained models. When you create a project, you can choose a base model. Make sure to select the one that best suits your general domain (e.g., general object detection vs. specific medical imaging if available as a base). The service then fine-tunes this base model on your custom data.

Here’s a snippet of how you might use the SDK after training:


from azure.cognitiveservices.vision.customvision.prediction import CustomVisionClient
from azure.cognitiveservices.vision.customvision.prediction.models import ImageUrl

# Replace with your actual keys and endpoint
prediction_key = "YOUR_PREDICTION_KEY"
endpoint = "YOUR_ENDPOINT"
project_id = "YOUR_PROJECT_ID"
published_iteration_name = "YOUR_PUBLISHED_ITERATION_NAME"

predictor = CustomVisionClient(endpoint, prediction_key)

with open("path/to/your/image.jpg", "rb") as image_file:
    results = predictor.classify_image(project_id, published_iteration_name, image_file)

for prediction in results.predictions:
    print(f"{prediction.tag_name}: {prediction.probability:.2f}")
                    

Post a Reply