I'm trying to use Demographics Model https://www.clarifai.com/blog/socially-responsible-pixels-a-look-inside-clarifais-new-demographics-recognition-model.
But I'm confused because is Demographics a Model or a workflow?
I tried to search for Demographics in the Model Mode in my dashboard and it doesn't exist.
There is a Demographics workflow in the App Workflows, but when I access it I get an error notification. This might be why when I run the server to detect the image with Demographics, it results in 'Model does not exist' error.
A model with ID '6c276d1ee3cac072fad9d6d850b4a429' not found. Check the url of your request.
Here's the code, I'm using nodejs.
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key {MY_SECRET_KEY}");
const inputs = [
{
data: {
image: {
url:
"https://www.gannett-cdn.com/-mm-/b2b05a4ab25f4fca0316459e1c7404c537a89702/c=0-0-1365-768/local/-/media/2020/08/19/USATODAY/usatsports/GettyImages-1147443912.jpg?width=660&height=372&fit=crop&format=pjpg&auto=webp",
},
},
},
];
stub.PostModelOutputs(
{
workflow_id: "Demographics",
inputs,
},
metadata,
(err: any, response: any) => {
if (err) {
console.log("Error: " + err);
return;
}
console.log(response); // Model doesn't exist
}
);
Response Output
{
outputs: [],
status: {
stack_trace: [],
code: 21200,
description: 'Model does not exist',
details: "Model '' does not exist.",
percent_completed: 0,
time_remaining: 0,
req_id: 'a9575417a32a4e2597443f4b400be39b',
internal_details: ''
}
}
In short, yes, it is a workflow.
"Demographics" found in the App Workflows under the App Details page is a workflow. With workflows, the stub.PostWorkflowResults
and the service_pb2.PostWorkflowResultsRequest
should be used. Here is an example from the Clarifai website: https://docs.clarifai.com/api-guide/workflows/workflow-predict
Longer version: the demographics models (multicultural-appearance, gender-appearance, and age-appearance) are meant to be used with only images of faces. The face-detector (model_id: '6c276d1ee3cac072fad9d6d850b4a429') would draw bounding boxes around the faces within the query image, the Cropper would extract the portion within the bounding box and pass them as inputs into the three demographics models.
Using my account with a Community Plan (under 'Billing'), the 'Demographic" workflow is visible in my auto-generated first application. Below is a Python API call, using an app API_KEY as authorization metadata. I was able to retrieve meaningful results using a query image with a face present.
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', f'Key {API_KEY}'),)
# Call Workflow Predict API
post_workflow_results_response = stub.PostWorkflowResults(
service_pb2.PostWorkflowResultsRequest(
workflow_id="Demographics",
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=f"{QUERY_IMAGE_URL}"
)
)
)
]
),
metadata=metadata
)
# Display Results
results = post_workflow_results_response.results[0]
for output in results.outputs:
model = output.model
# Want appearance models results
if 'detector' not in model.name and 'Cropper' not in model.name:
print("Predicted concepts for the model `%s`" % model.name)
for concept in output.data.regions[0].data.concepts:
print("\t%s %.2f" % (concept.name, concept.value))