Content classification
When you use the content classification feature, you can filter the response based on the level of confidence that the results match the labels you've specified in the request by specifying the threshold
parameter in the request. This allows you to narrow down a response obtained from the API service by retrieving only the most relevant results. The threshold
parameter can take one of the following values:
low
(this is the default value)medium
high
Note that the example on this page is specific to classifying a single video. However, the principles demonstrated are similar when classifying multiple videos.
Example
Although the example code in this guide is written in Python and Node.js the API is compatible with most programming languages, and you can also use Postman or other REST clients to send requests and view responses.
For a description of each field in the request and response, see the API Reference> Classify a video page.
Prerequisites
- You’re familiar with the concepts that are described on the Understand page.
- You’ve uploaded at least one video, and the API service has finished indexing it. For details, see the Uploading videos page.
Filter based on the level of confidence
The following example code specifies that the minimum level of confidence between your label and the matching video fragments shouldn't be lower than high
:
CLASSIFY_URL = f"{API_URL}/classify"
headers = {
"x-api-key": API_KEY
}
data = {
"conversation_option": "semantic",
"options": ["visual"],
"video_id": VIDEO_ID,
"threshold": "high",
"labels": [
{
"name": "Car shapes",
"prompts": [
"SUV",
"Hatchback",
"Crossover",
"Sedan",
"Coupe",
"Minivan",
"Station Wagon",
"Pickup Truck",
"Truck",
"Convertible"
]
}
]
}
response = requests.post(CLASSIFY_URL, headers=headers, json=data)
print (f'Status code: {response.status_code}')
pprint(response.json())
const CLASSIFY_URL = `${API_URL}/classify`
const data = {
"conversation_option": "semantic",
"options": ["visual"],
"video_id": VIDEO_ID,
"threshold": "high",
"labels": [
{
"name": "Car shapes",
"prompts": [
"SUV",
"Hatchback",
"Crossover",
"Sedan",
"Coupe",
"Minivan",
"Station Wagon",
"Pickup Truck",
"Truck",
"Convertible"
]
}
]
}
const resp = await axios.post(
CLASSIFY_URL,
data,
{
"headers": {
"x-api-key": API_KEY
}
}
)
const { data: response } = resp;
console.log(`Status code: ${resp.status}`)
console.log(JSON.stringify(response,null,4))
The output should look similar to the following one:
Status code: 200
{
"video_id": "63a09373ce36463e0199c8de",
"labels": [
{
"name": "Car shapes",
"max_score": 87.15,
"duration": 288.8906249999999,
"confidence": "high"
}
]
}
Note that, when classifying a video, the API service finds all video fragments that match the label you've specified in the request. For each video fragment found, the API service determines the level of confidence that the fragment matches the label. The max_score
field is determined by comparing the confidence scores of each fragment and selecting the highest one.
Updated 5 days ago