This how-to-guide shows you how to easily detect people in an image with Clarifai's Edge-Optimized Person Detector. The Edge-Optimized Person Detector is useful any time you need AI to identify people on lightweight edge devices.
For example, the Edge-Optimized Person Detector would detect the following regions of the image above, with the corresponding likelihood that each detection is, in fact, a person.
Getting Started
First things first. You will need to set up a Clarifai account and create an application. This how-to article shows you how to analyze color with Clarifai API and through Portal. If you would like to analyze color via API, you will also need to generate an API key.
Detecting people with Clarifai Portal
You can do almost anything that Clarifai can do with Clarifai Portal, and we work hard to make Portal the world's easiest interface for using AI. Detecting people with Portal is as simple as uploading your data, and setting up the right workflow.
Create your application and choose your base workflow
Simply log in to Clarifai Portal and create a new application. Select "General Detection" as your base workflow.
Navigate to Model Mode and create a new workflow
Next, we will want to create a new workflow that uses the celebrity model. Just navigate to Model Mode on the right hand sidebar and click "Create New Workflow" in the upper righthand corner of the screen.
Add the people "visual detector" to your workflow
Now we will add just one model to the work flow: the people "person-detection-edge". Be sure to select "clarifai" as the user in the lefthand dropdown menu. You can then filter your results by model type. Select "visual detector". Click "ADD" to add the model to your workflow, and then click "CREATE WORKFLOW"
Select your new "people" workflow as the app workflow
Now navigate to view your image in Explorer. In the righthand sidebar you can click the "APP WORKFLOW" tab, and click the gear icon. Finally select your new workflow, and view your predictions.
Identify people in a local image via API
Use the following Python snippet as an example of how to run a prediction on an image hosted on your local computer. For more details and information on working with predictions in our other client languages, please refer to our API documentation.
from clarifai_grpc.grpc.api import service_pb2, resources_pb2 from clarifai_grpc.grpc.api.status import status_code_pb2 # This is how you authenticate. metadata = (('authorization', 'Key {{YOUR_CLARIFAI_API_KEY}}'),) with open("{YOUR_IMAGE_FILE_LOCATION}", "rb") as f: file_bytes = f.read() request = service_pb2.PostModelOutputsRequest( model_id='23aa4f9c9767a2fd61e63c55a73790ad', inputs=[ resources_pb2.Input( data=resources_pb2.Data( image=resources_pb2.Image( base64=file_bytes ) ) ) ]) response = stub.PostModelOutputs(request, metadata=metadata) if response.status.code != status_code_pb2.SUCCESS: raise Exception("Request failed, status code: " + str(response.status.code)) for concept in response.outputs[0].data.concepts: print('%12s: %.2f' % (concept.name, concept.value))
Identify people in images hosted on the web via API
Here is an example of how to run a prediction on an image that is hosted on a URL. This snippet is in Python, but we offer support for many other client languages. Please refer to our API documentation for additional information.
from clarifai_grpc.grpc.api import service_pb2, resources_pb2 from clarifai_grpc.grpc.api.status import status_code_pb2 # This is how you authenticate. metadata = (('authorization', 'Key {{YOUR_CLARIFAI_API_KEY}}'),) request = service_pb2.PostModelOutputsRequest( model_id='23aa4f9c9767a2fd61e63c55a73790ad', inputs=[ resources_pb2.Input(data=resources_pb2.Data(image=resources_pb2.Image(url='{{YOUR_IMAGE_URL}}'))) ]) response = stub.PostModelOutputs(request, metadata=metadata) if response.status.code != status_code_pb2.SUCCESS: raise Exception("Request failed, status code: " + str(response.status.code)) for concept in response.outputs[0].data.concepts: print('%12s: %.2f' % (concept.name, concept.value))