Hello
I want to label all my images according to their file names. Therefore I used a python code but it gave an error like this:
Error labeling image: YC 3817 - 3.246 kgIm.jpg. Error message: {"error":{"code":"401","message": "The Analyze Image Operation under Computer Vision API (v3.0) is not supported with the current subscription key and pricing tier Custom_Vision.Training.S0."}}
Here was my code:
import requests
import os
# Define the endpoint, key, and project ID
endpoint = "https://[HIDDEN].cognitiveservices.azure.com/"
key = "[HIDDEN]"
project_id = "[HIDDEN]"
# Define the resource ID
resource_id = "/subscriptions/[HIDDEN]/resourceGroups/Ya/providers/Microsoft.CognitiveServices/accounts/[HIDDEN]"
# Define the path to the image directory
image_dir = "C:\Users\[HIDDEN]"
# Create a list to store the results
results = []
# Loop through all the images in the directory
for filename in os.listdir(image_dir):
if filename.endswith(".jpg"):
with open(os.path.join(image_dir, filename), "rb") as image_file:
image_data = image_file.read()
headers = {
"Ocp-Apim-Subscription-Key": key,
"Content-Type": "application/octet-stream",
"Prediction-Key": key,
"Project-Id": project_id,
"Resource-Id": resource_id
}
response = requests.post(endpoint + "vision/v3.0/analyze?visualFeatures=Categories,Description,Tags", headers=headers, data=image_data)
# Check if the request was successful
if response.status_code == 200:
results.append(response.json())
else:
print("Error labeling image: " + filename + ". Error message: " + response.text)
# Print the results
print(results)