Roboflow Docs
DashboardResourcesProducts
  • Product Documentation
  • Developer Reference
  • Changelog
  • Developer Tools
  • Authentication
    • Find Your Roboflow API Key
    • Scoped API Keys
    • Workspace and Project IDs
  • Command Line Interface (CLI)
    • Using the CLI
    • Install and Set Up the CLI
    • List Workspaces and Projects
    • Download a Dataset
    • Upload a Dataset
    • Run a Model on an Image
  • REST API
    • Using the REST API
    • Authenticate with the REST API
    • List Workspaces and Projects
  • Search Images in a Dataset
  • Create a Project
  • Get a Project and List Versions
  • Manage Project Folders
  • List Image Batches
  • Create and List Annotation Jobs
  • Manage Images
    • Upload an Image
    • Get Details About an Image
    • Delete an Image from a Dataset
    • Upload an Annotation
    • Search for an Image
    • List, Add, and Remove Image Tags
  • Versions
    • View a Version
  • Export Data
  • Annotation Insights
    • Annotation Insights (Legacy Endpoint)
  • Model Monitoring
    • Retrieve Statistics About Deployed Models in a Workspace
    • Attach Metadata to an Inference
  • Python SDK
    • Using the Python SDK
  • Authenticate with the Python SDK
  • List Workspaces
  • List Projects and Versions
  • Create a Project
  • Create a Dataset Version
  • Train a Model
  • Upload a Dataset
  • Search for an Image
  • iOS SDK
    • Using the iOS SDK
Powered by GitBook
On this page

Was this helpful?

  1. Manage Images

Search for an Image

You can search for images hosted on Roboflow using the Python SDK and REST API.

To search for images hosted on Roboflow, make POST request to the following API endpoint:

https://api.roboflow.com/:workspace/:project/search

Here is an example request to the API:

curl -X POST "https://api.roboflow.com/my-workspace/my-project-name/search?api_key=$ROBOFLOW_API_KEY" \
-H 'Content-Type: application/json' \
--data \
'{
    "like_image": "image_id",
    "in_dataset": true,
    "limit": 125,
}'

This endpoint accepts the following values in the POST body:

{
     // when provided, provides results sorted by semantic similarity
     "like_image": string,
     
     // when provided, provides results sorted by semantic similarity
     "prompt": string,
     
     // defaults to 0
     "offset": int,
     
     // default to 50 (max: 250)
     "limit": int,
     
     // when present, filters images that have the provided tag
     "tag": string,
     
     // when present, filters images that have the provided class name
     "class_name": string,
     
     // when present, filters images that are in the provided project
     "in_dataset": string,
     
     // when present, returns only images that are in any batch
     "batch": boolean
     
     // when present, returns only images present in the provided batch
     "batch_id": string
     
     // specify the fields to return, defaults to ["id", "created"]
     // options are ["id", "name", "annotations", "labels", "split", "tags", "owner", "embedding", "created"]
     "fields": string[]
}

The search API will return a response with the following structure. The values available will vary depending on the additional fields you have specified:

{
    "offset": 0,
    "total": 292,
    "results": [
        {
            "id": "image123",
            "name": "humpbackwhale.jpg",
            "owner": "owner123",
            "annotations": {
                "count": 5,
                "classes": {
                    "whale": 1,
                    "fish": 4
                }
            },
            "labels": [],
            "tags": [
                "cam_x13"
            ]
        }
        // ... etc.
    ]
}

To search for images using the Python SDK, use the search_all() method. The method accepts a prompt value, which is the search query you want to send to Roboflow.

See the search filter documentation for more information on advanced filters supported in searches.

import roboflow

roboflow.login()

rf = roboflow.Roboflow()

project = rf.project("PROJECT_ID")

records = []

for page in project.search_all(
    prompt="mug",
    like_image = image_id,
    offset = 0,
    limit = 100,
    tag = "tag",
    class_name = "class_name",
    in_dataset = True,
    batch = False,
    batch_id = "batch_id",
    fields = ["id", "created", "name", "labels"],
):
    records.extend(page)

print(len(records))

PreviousUpload an AnnotationNextList, Add, and Remove Image Tags

Last updated 17 hours ago

Was this helpful?