training_extensions icon indicating copy to clipboard operation
training_extensions copied to clipboard

Design backend integration with RF Universe

Open leoll2 opened this issue 4 weeks ago • 5 comments

Write a design document for #6472 , describing how Geti's dataset import functionality could be extended with a mechanism to import datasets directly from Roboflow Universe.

The design should cover the following aspects:

  • Supported dataset formats and tasks
  • Required API changes
  • Authentication with RF Universe
  • Dependencies
  • Testing

It doesn't have to cover the UI part, which can be designed separately.

Bonus: the design could propose a generic dataset-provider interface, which can be later reused for other sources such as HuggingFace Datasets.

leoll2 avatar Nov 05 '26 07:11 leoll2

Hi @leoll2,

I looked through the dataset import code and think this can fit into the existing staging workflow. Here’s the approach I’d propose for #7910.

Import flow

getidata’s coco/io.py already detects Roboflow’s layout, where each split contains images and _annotations.coco.json. We should be able to reuse that loader, with fixtures to check that the exported annotations survive the full Geti import path.

I’d add a background job to resolve a Roboflow dataset version, download its archive, and place it in staging. From there, the client runs the existing prepare_dataset_for_import job and either import_dataset_to_project or import_dataset_as_new_project.

Keeping these steps separate lets users inspect the detected labels and configure label mapping before importing into a project.

Formats and tasks

I’d start with object detection through the coco export. Polygon instance segmentation through coco-segmentation could also be included once covered by conversion tests.

Classification needs a separate export path, so I’d leave it for a follow-up. Semantic segmentation, keypoints, oriented boxes, and video tracking are outside the first implementation.

The conversion tests should check labels, annotations, unannotated images, and train/valid/test membership. Unsupported mask representations should fail explicitly rather than silently become boxes or lose annotations.

API changes

A possible entry point is:

POST /api/staged_datasets:from-provider
{
  "source": {
    "provider": "roboflow_universe",
    "workspace": "workspace-slug",
    "project": "project-slug",
    "version": 3
  },
  "credentials": {
    "api_key": "<private-api-key>"
  }
}

The endpoint returns 202 Accepted with a JobView for a new stage_dataset_from_provider job. Its metadata contains the reserved staged_dataset_id and source identifiers, excluding credentials and signed download URLs.

Progress and cancellation use the existing job endpoints. The staged dataset becomes available once the download and archive validation finish. The backend picks the export format from the source task; the request requires an explicit version.

Authentication

There’s one detail in the worker runner that needs care: it calls model_dump_json() on job parameters before spawning the worker. Adding a SecretStr field alone would send the masked value. Adding a serializer that reveals it risks exposing the key through other parameter dumps.

I’d keep the credential outside the public job parameters and pass it through a private runtime context to the worker. That requires a runner change, so I’d like feedback on this part before committing to the approach.

The key is supplied per request, held only while needed, and excluded from logs, errors, and stored metadata. Roboflow API calls use bearer authentication; signed archive downloads use a client without that header. Saved credentials and OAuth can be follow-up work.

Provider interface and dependencies

For the reusable interface, I think two operations are enough initially: resolve() for source/version/export metadata and download() for producing a local archive. Staging and project writes remain outside the provider. Only the Roboflow implementation is registered initially.

My preference is a small REST adapter using an explicitly declared HTTP client such as httpx. It lets us control export polling, streaming, timeouts, and cancellation directly. I’m also open to using the Roboflow SDK if that’s preferred.

The backend manifest already contains Roboflow-related dependency overrides. I’d check the lockfile before changing dependencies and leave those overrides alone unless a change is necessary.

Failure handling and testing

Downloads go into a temporary directory and are only published to staging after validation. The job handles pending exports, bounded retries for transient failures, download/extraction limits, and cleanup on failure or cancellation. Archive paths and download redirects also need validation.

Invalid keys, inaccessible versions, and unsupported formats should produce specific errors through the existing job response. Project import is not retried automatically: the current importer creates items incrementally, so replaying a failed import could duplicate partial results.

Tests can use mocked HTTP responses and small Roboflow-layout fixtures for both project-import paths. I’d include regression checks for credential leakage, worker credential delivery, cancellation, split preservation, and the existing upload flow. A separate opt-in live test could verify the actual export/download API and that an imported dataset can be used for training.

andersendsa avatar Nov 10 '26 10:11 andersendsa

Hi @leoll2 can I start working on the implementation ?

andersendsa avatar Nov 16 '26 09:11 andersendsa

Hi Andersen, thanks for sharing your proposal.

I looked through the dataset import code and think this can fit into the existing staging workflow.

I agree that "dataset staging" would be the right place where to hook external dataset providers.

I’d start with object detection through the coco export. Polygon instance segmentation through coco-segmentation could also be included once covered by conversion tests. Classification needs a separate export path, so I’d leave it for a follow-up. Semantic segmentation, keypoints, oriented boxes, and video tracking are outside the first implementation.

COCO format sounds a good choice for object detection and instance segmentation. For classification, it'd be nice if we could already include it in this design: I did some experiments with RF Universe and discovered that if you download a classification dataset as "Folder structure", that format is equivalent/compatible with the YOLO-Cls format introduced in #7921. That means we have a viable technical path to support RF Universe classification datasets right away. For the other tasks you mention, I agree to not consider them.

A possible entry point is: POST /api/staged_datasets:from-provider

Route, request and response look good. API key in the POST request payload is also acceptable. One thing to note: the structure of source varies by provider, but I don't think it will be a problem because you can model it through a discriminator. The choice to create a new job type (vs reusing the current stage_dataset job) makes sense to me, since I expect most of the logic will be different whereas the prepare/import jobs should work out of the box, with little to no changes.

There’s one detail in the worker runner that needs care: it calls model_dump_json() on job parameters before spawning the worker.

Good catch. The API key should never be dumped to logs or jobs artifacts for security reasons, so I would agree with a small extension of the runner interface enabling a channel to send confidential data.

For the reusable interface, I think two operations are enough initially: resolve() for source/version/export metadata and download() for producing a local archive.

Sounds good, let's start this way and we'll add more methods later if needed

My preference is a small REST adapter using an explicitly declared HTTP client such as httpx. It lets us control export polling, streaming, timeouts, and cancellation directly. I’m also open to using the Roboflow SDK if that’s preferred.

In my opinion, it would be much easier and reliable to use roboflow instead of raw requests via httpx. In fact, Geti already depends on this package (through getitune (source, iirc because of RF-DETR support) so there's really no downside in reusing it for Universe dataset imports too.

leoll2 avatar Nov 16 '26 09:11 leoll2

Hi @andersendsa, feel free to create a doc in application/docs. You can use ome.md for reference.

It would be great to have some mocks for the UI as well, since it's a new flow which will require some interface extension.

For authentication, the serialization can be split into 2 flavors: standard SecretStr behavior which masks values by default, and the IPC variant. Example:

from pydantic import BaseModel, SecretStr, SerializationInfo, field_serializer

class JobParams(BaseModel):
    @staticmethod
    def _dump_secret(v: SecretStr | None, info: SerializationInfo) -> str | None:
        if v is None:
            return None
        ctx = info.context or {}
        return v.get_secret_value() if ctx.get("reveal_secrets") else "**********"

    def to_ipc_json(self) -> str:
        """Serialize params for transfer to the job child process, including secret values."""
        return self.model_dump_json(context={"reveal_secrets": True})

# concrete model
    @field_serializer("api_key", when_used="json")
    def _ser_api_key(self, v: SecretStr | None, info: SerializationInfo) -> str | None:
        return self._dump_secret(v, info)

# process_run.py
self._job.params.to_ipc_json(),

itallix avatar Nov 16 '26 09:11 itallix

Hi @itallix, @leoll2,

Thank you both for the detailed feedback and suggestions. I'll refine the design proposal to incorporate your recommendations and share an updated draft for review.

andersendsa avatar Nov 16 '26 10:11 andersendsa