Official Python package for working with the Roboflow computer vision platform API
—
Dataset version management including downloads, exports, training, and deployment of specific dataset versions. Versions represent snapshots of a dataset with specific preprocessing and augmentation settings applied.
Interface for managing individual dataset versions and their associated operations.
class Version:
def __init__(self, version_data, project_info, model_format, api_key, name, local=None):
"""
Initialize version object.
Parameters:
- version_data: dict - Version information from API
- project_info: dict - Parent project information
- model_format: str - Preferred model format
- api_key: str - Roboflow API key
- name: str - Version name/identifier
- local: str, optional - Local path for version data
"""
# Properties
model: InferenceModel # Associated trained model for inferenceDownload dataset versions in various formats for local development and training.
def download(self, model_format=None, location=None, overwrite: bool = False):
"""
Download the dataset version in specified format.
Parameters:
- model_format: str, optional - Format to download ("yolov8", "yolov5", "pascal_voc", "coco", "tfrecord", "createml", "darknet", "pytorch", "tensorflow", "clip")
- location: str, optional - Download directory path (default: current directory)
- overwrite: bool - Whether to overwrite existing files (default: False)
Returns:
Dataset - Dataset object with location information
"""Export dataset versions to different formats without downloading.
def export(self, model_format=None):
"""
Export dataset in specified format.
Parameters:
- model_format: str, optional - Export format ("yolov8", "yolov5", "pascal_voc", "coco", etc.)
Returns:
bool or None - Export success status
"""Train machine learning models on specific dataset versions.
def train(self, speed=None, model_type=None, checkpoint=None, plot_in_notebook=False):
"""
Train a model on this dataset version.
Parameters:
- speed: str, optional - Training speed ("fast", "medium", "slow")
- model_type: str, optional - Model architecture ("yolov8n", "yolov8s", "yolov8m", "yolov8l", "yolov8x")
- checkpoint: str, optional - Checkpoint to resume training from
- plot_in_notebook: bool - Whether to display training plots in notebook (default: False)
Returns:
InferenceModel - Trained model ready for inference
"""Deploy trained models to production environments.
def deploy(self, model_type: str, model_path: str, filename: str = "weights/best.pt"):
"""
Deploy a trained model to production.
Parameters:
- model_type: str - Type of model being deployed
- model_path: str - Path to model files
- filename: str - Model filename within the path (default: "weights/best.pt")
Returns:
None - Deployment is asynchronous
"""The download operation returns a Dataset object with location information.
class Dataset:
location: str # Path where dataset was downloadedimport roboflow
rf = roboflow.Roboflow(api_key="your_api_key")
project = rf.workspace().project("my-project")
version = project.version(1)
# Download in YOLO format
dataset = version.download("yolov8")
print(f"Dataset downloaded to: {dataset.location}")
# Download to specific location
dataset = version.download(
model_format="pascal_voc",
location="/path/to/my/datasets",
overwrite=True
)
# Download in COCO format
dataset = version.download("coco")# Train with default settings
model = version.train()
# Train with specific configuration
model = version.train(
speed="medium",
model_type="yolov8s",
plot_in_notebook=True
)
# Use trained model for inference
prediction = model.predict("/path/to/test/image.jpg")# Export without downloading
export_success = version.export("yolov8")
if export_success:
print("Export completed successfully")# Deploy a trained model
version.deploy(
model_type="yolov8",
model_path="/path/to/trained/model",
filename="best.pt"
)The version supports multiple dataset formats:
"yolov8", "yolov5", "yolov7", "darknet""pascal_voc", "coco", "tfrecord""pytorch", "tensorflow""createml" (for iOS)"clip" (for CLIP embeddings)Training supports various YOLO model architectures:
"yolov8n", "yolov8s", "yolov8m", "yolov8l", "yolov8x""yolov5n", "yolov5s", "yolov5m", "yolov5l", "yolov5x"Dataset versions contain metadata about:
Version operations can encounter various errors:
try:
dataset = version.download("invalid_format")
except ValueError as e:
print(f"Invalid format: {e}")
try:
model = version.train(model_type="invalid_model")
except RuntimeError as e:
print(f"Training failed: {e}")Once training is complete, models are automatically available for inference:
# Train model
model = version.train()
# Immediate inference
prediction = model.predict("image.jpg")
# Or access model later via version.model property
model = version.model
prediction = model.predict("another_image.jpg")Install with Tessl CLI
npx tessl i tessl/pypi-roboflow