Pre Classification of Images using GPT 4o
This comprehensive guide demonstrates how to create a pre-classification task Agent that uses GPT-4 to automatically classify images and route them to specific annotation stages based on their classification. This approach is particularly useful when you have specialized annotators. Images with uncertain classifications are automatically added to the Archive for further review.
This guide makes the following assumptions:
- You have an active OpenAI subscription with an API key.
- Your images are stored in AWS.
STEP 1: Import your Images
Set Up AWS
Before you can do anything with the Encord platform and cloud storage, you need to configure your cloud storage to work with Encord. Once the integration between Encord and your cloud storage is complete, you can then use your data in Encord.
In order to integrate with AWS S3, you need to:
- Create a permission policy for your resources that allows appropriate access to Encord.
- Create a role for Encord and attach the policy so that Encord can access those resources.
- Activate Cross-origin resource sharing which allows Encord to access those resources from a web browser.
- Test the integration to make sure it works.
You have the following options to integrate AWS and Encord:
Create AWS Integration in Encord
In the Integrations section of the Encord platform, click +New integration to create a new integration.
Select AWS S3 at the top of the chooser.
Create JSON file for import
Create a JSON file based on the templates provided below. imageMetadata
is optional unless you are using a client-only access integration.
The title
field is optional. If omitted, the image file path and name are used as the default title. For example, if the file is located at https://encord-solutions-bucket.s3.eu-west-2.amazonaws.com/path/to/my/bucket/image23.mp4
, the title defaults to /path/to/my/bucket/image23.jpg
.
Key or Flag | Required? | Default value |
---|---|---|
”objectUrl” | Yes | |
”title” | No | The file’s path + title |
”imageMetadata” | No | |
”clientMetadata” | No | |
”createVideo” | No | false |
imageMetadata
must be specified when a Strict client-only access integration is used. In all other cases, imageMetadata
is optional, but including it significantly reduces import times.Create a Folder to Store Your Images
All files in Encord must be stored within folders. Therefore, you need to create a folder before uploading any data to Encord. To create a folder:
- Navigate to Files under the Index heading in the Encord platform.
- Click the + New folder button to create a new folder. A dialog to create a new folder appears.
-
Give the folder a meaningful name and description.
-
Click Create to create the folder. The folder is listed in Files.
Upload Your Images to Encord
- Navigate to Files section of Index in the Encord platform.
- Click + Upload files. A dialog appears.
- Select the folder you created in step 4.
- Click the Import from private cloud option.
- Select the integration you created in step 2 to add your cloud data.
STEP 2: Set Up Your Project
Create a Dataset
- Click the New dataset button in the Datasets section in Annotate.
- Give your Dataset a meaningful title and description. A clear title and description keeps your data organized.
- Click Create dataset to create the Dataset.
Attach files
- Navigate to the Datasets section under the Annotate heading.
- Click the Dataset you want to attach data to.
- Click +Attach existing files.
-
Select the folders containing the files you want to attach to the Dataset. To select individual files, double-click a folder to see its contents, and select the files you want to add to the Dataset.
-
Click Attach data to attach the selected files to the Dataset.
Create an Ontology
Create a new Ontology that includes:
-
A radio classification called “Animal” with two options: One called “Cat” the other called “Dog”.
-
Any other Objects you want to include in your Ontology.
Create Your Workflow template
Learn how to create Workflow templates here.
Create the following Workflow template by dragging the necessary components onto the canvas. For instructions on creating Workflows see our documentation here. Ensure your Agent node has the name “Agent 1”
Create a Project
- In the Encord platform, select Projects under Annotate.
- Click the + New annotation project button to create a new Project.
- Give the Project a meaningful title and description.
If you are part of an Organization, an optional Project tags drop-down is visible. Project tags are useful for categorizing and finding your Projects. Select as many tags as are relevant for your Project.
-
Click the Attach ontology button.
-
Select the Ontology you created previously from the list using the Select button.
-
Click OK to attach the Ontology to the Project.
-
Click the Attach datasets button.
-
Select the Dataset you created previously from the list using the Attach button.
- Click OK to attach the Dataset(s) to the Project.
- Click the Load from template button to use a Workflow template.
-
Select the template you want to use and click Load template.
-
Click Create project to finish creating the Project.
STEP 3: Configure Your Agent
-
Create a python file called
imagePreClassification.py
. -
Paste the following script into
imagePreClassification.py
replacing:<your_openai_api_key>
with your OpenAI API key.<private_key_path>
with the path to your private key.<project_hash>
with the hash of the Project you created in STEP 2.
- Save
imagePreClassification.py
.
STEP 4: Run your Agent
Run imagePreClassification.py
.
The script processes all images in the Dataset. If additional images are added, the script must be re-run to include them.
STEP 5: Start Labeling
Now your annotators can start annotating images.
See our guide on how to label here.
Flow Diagram
Was this page helpful?