Training and inference templates based on the D-FINE architecture.
Project description
Sinapsis D-FINE
Templates for training and inference with the D-FINE model
🐍 Installation • 🚀 Features • 📚 Usage example • 📙 Documentation • 🔍 License
The Sinapsis D-FINE module provides templates for training and inference with the D-FINE model, enabling advanced object detection tasks.
🐍 Installation
Install using your package manager of choice. We encourage the use of uv
Example with uv:
uv pip install sinapsis-dfine --extra-index-url https://pypi.sinapsis.tech
or with raw pip:
pip install sinapsis-dfine --extra-index-url https://pypi.sinapsis.tech
🚀 Features
Templates Supported
The Sinapsis D-FINE module provides two main templates for inference and training:
- DFINETraining: This module implements the training pipeline for the D-FINE model. It includes logic for initializing configuration, downloading weights and setting up the training solver.
- DFINEInference: Template designed to perform inference on a set of images using the different D-FINE architectures available.
🌍 General Attributes
Both templates share the following attributes:
config_file(str, required): Path to the model configuration file. Refer to the original repo for detailed instructions on using, creating and customizing these configuration files.pretrained_model(dict | None, optional): Specifies the size and variant of the pretrained model.device(Literal["cpu", "cuda"], required): Defines whether to run inference on CPU or CUDA.weights_path(str | None, optional): Path to a custom weights file, if provided. Defaults toNone.output_dir(str, optional): Directory where downloaded weights will be stored. Defaults to SINAPSIS_CACHE_DIR.
Specific Attributes
There are some attributes specific to the templates used:
DFINEInferencehas four additional attributes:threshold(float, required): Confidence score threshold for filtering detections.batch_inference(bool, optional): Whether to perform batch inference. Defaults toFalse.warmup_iterations(int, optional): Number of warm-up iterations to optimize model performance. Defaults to10.id2label(dict[int, str] | None, optional): Mapping of class indices to label strings. Required if using custom weights. Defaults toNone.
DFINETraininghas five additional attributes:training_mode(Literal["scratch", "tune"], required):"scratch"trains the model from scratch, while"tune"is meant to be used to fine-tune the model with provided or downloaded weights.seed(int | None, optional): Random seed for reproducibility. Defaults toNone.use_amp(bool, optional): Enables Automatic Mixed Precision (AMP) for improved performance. Defaults toFalse.print_rank(int, optional): Rank of the process for logging in distributed training. Defaults to0.print_method(Literal["builtin", "rich"], optional): Defines the logging method while training. Defaults to"builtin".
[!TIP] Use CLI command
sinapsis info --example-template-config TEMPLATE_NAMEto produce an example Agent config for the Template specified in TEMPLATE_NAME.
For example, for DFINEInference use sinapsis info --example-template-config DFINEInference to produce an example config like:
agent:
name: my_test_agent
templates:
- template_name: InputTemplate
class_name: InputTemplate
attributes: {}
- template_name: DFINEInference
class_name: DFINEInference
template_input: InputTemplate
attributes:
config_file: '/path/to/config.yml'
pretrained_model: null
device: 'cuda'
weights_path: null
output_dir: '/path/to/sinapsis/cache'
threshold: 0.5
warmup_iterations: 10
id2label: null
📚 Usage example
The following example demonstrates how to use the DFINEInference template for object detection. This setup processes a folder of images, runs inference using the D-FINE model, and saves the results, including detected bounding boxes.
Config
agent:
name: dfine_inference
description: "run inferences with D-FINE"
templates:
- template_name: InputTemplate
class_name: InputTemplate
attributes: {}
- template_name: FolderImageDatasetCV2
class_name: FolderImageDatasetCV2
template_input: InputTemplate
attributes:
data_dir: datasets/coco
- template_name: DFINEInference
class_name: DFINEInference
template_input: FolderImageDatasetCV2
attributes:
threshold: 0.5
config_file: artifacts/configs/dfine/dfine_hgnetv2_n_coco.yml
device: cuda
output_dir: ./artifacts/dfine_hgnetv2_n_coco
pretrained_model:
size: n
variant: coco
- template_name: BBoxDrawer
class_name: BBoxDrawer
template_input: DFINEInference
attributes:
overwrite: true
randomized_color: false
- template_name: ImageSaver
class_name: ImageSaver
template_input: BBoxDrawer
attributes:
root_dir: datasets
save_dir: output
extension: png
This configuration defines an agent and a sequence of templates to run object detection with D-FINE.
[!IMPORTANT] The FolderImageDatasetCV2, BBoxDrawer and ImageSaver correspond to sinapsis-data-readers, sinapsis-data-visualization and sinapsis-data-writers. If you want to use the example, please make sure you install the packages.
To run the config, use the CLI:
sinapsis run name_of_config.yml
📙 Documentation
Documentation for this and other sinapsis packages is available on the sinapsis website
Tutorials for different projects within sinapsis are available at sinapsis tutorials page
🔍 License
This project is licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the LICENSE file.
For commercial use, please refer to our official Sinapsis website for information on obtaining a commercial license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sinapsis_dfine-0.1.0.tar.gz.
File metadata
- Download URL: sinapsis_dfine-0.1.0.tar.gz
- Upload date:
- Size: 49.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e2b7b48544a163b5c8909d2e145258a5b36ed5aeb906e0c3f7943aee42fb431
|
|
| MD5 |
c720329e305fc45962ea988d535857a7
|
|
| BLAKE2b-256 |
103949202754cccdba9f6988dc7923992e20fbe42e2b25f4158b5da8b38b80ab
|
File details
Details for the file sinapsis_dfine-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sinapsis_dfine-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc557a40d6f75d91ff7858dec0b0cdb993bcbab3bfdbf18d174c07c1134d06b9
|
|
| MD5 |
72a2c525c4e7179f9b3262fa28862892
|
|
| BLAKE2b-256 |
f98e43ca05395acc715f1d4f85c6e400574757c0c2a053f27ab6a44fbdfc003c
|