Platform Actions
Generate dataset versions, export them, and train models as you would in the Roboflow web application.
In the same way you can utilize the Roboflow UI, you can generate dataset versions, export them in various formats, and train models on on new dataset versions in the Roboflow Python package. This functionality is useful if you are building Roboflow actions into a pipeline that is programmatically training new models in an active learning loop.

In summary:
from roboflow import Roboflow
rf = Roboflow(api_key="API_KEY")
project = rf.workspace("YOUR_WORKSPACE").project("YOUR_PROJECT")
#generate new version
new_version = project.generate_version()
version = project.version(new_version)
#export version
version.export("coco")
#download version
version.download("coco")
#train version
version.train()
#train project (generates new version and trains it)
project.train()
project.generate_version(settings={})
Settings, a python dict with augmentation and preprocessing keys and specifications for generation. These settings mirror capabilities available via the Roboflow UI.
For an exhaustive example:
{
"augmentation": {
"bbblur": { "pixels": 1.5 },
"bbbrightness": { "brighten": true, "darken": false, "percent": 91 },
"bbcrop": { "min": 12, "max": 71 },
"bbexposure": { "percent": 30 },
"bbflip": { "horizontal": true, "vertical": false },
"bbnoise": { "percent": 50 },
"bbninety": { "clockwise": true, "counter-clockwise": false, "upside-down": false },
"bbrotate": { "degrees": 45 },
"bbshear": { "horizontal": 45, "vertical": 45 },
"blur": { "pixels": 1.5 },
"brightness": { "brighten": true, "darken": false, "percent": 91 },
"crop": { "min": 12, "max": 71 },
"cutout": { "count": 26, "percent": 71 },
"exposure": { "percent": 30 },
"flip": { "horizontal": true, "vertical": false },
"hue": { "degrees": 180 },
"image": { "versions": 32 },
"mosaic": true,
"ninety": { "clockwise": true, "counter-clockwise": false, "upside-down": false },
"noise": { "percent": 50 },
"rgrayscale": { "percent": 50 },
"rotate": { "degrees": 45 },
"saturation": { "percent": 50 },
"shear": { "horizontal": 45, "vertical": 45 }
},
"preprocessing": {
"auto-orient": true,
"contrast": { "type": "Contrast Stretching" },
"filter-null": { "percent": 50 },
"grayscale": true,
"isolate": true,
"remap": { "original_class_name": "new_class_name" },
"resize": { "width": 200, "height": 200, "format": "Stretch to" },
"static-crop": { "x_min": 10, "x_max": 90, "y_min": 10, "y_max": 90 },
"tile": { "rows": 2, "columns": 2 }
}
}
Returns: The version number that is being generated
"""
export()
zips your dataset in the specified format. download()
pulls your dataset from the Roboflow servers to where your python code is executing.export()
and download()
accept the following formats based on your project type:validFormats = {
"object-detection": [
"clip",
"coco",
"createml",
"darknet",
"multiclass",
"tensorflow",
"tfrecord",
"voc",
"yolokeras",
"yolov4pytorch",
"yolov4scaled",
"yolov5-obb",
"yolov5pytorch",
"yolov7pytorch",
"mt-yolov6",
"retinanet",
"benchmarker"
],
"classification": ["folder", "clip"],
"multilabel-classification": ["multiclass", "folder", "clip"],
"instance-segmentation": [
"coco-segmentation",
"clip",
"coco",
"createml",
"darknet",
"multiclass",
"tensorflow",
"tfrecord",
"voc",
"yolokeras",
"yolov4pytorch",
"yolov4scaled",
"yolov5-obb",
"yolov5pytorch",
"yolov7pytorch",
"mt-yolov6",
"retinanet",
"benchmarker"
],
"semantic-segmentation": ["coco-segmentation", "png-mask-semantic"]
};
You can
train()
at the project level and the version level, to invoke Roboflow's training procedures. Training at the project level generates a new version and trains it. train()
accepts speed=
"fast"
or "accurate"
and you can pass the version URL in checkpoint
to start training from a previous version if desired. For example, for the dataset https://universe.roboflow.com/joseph-nelson/bccd/dataset/4, joseph-nelson/bccd/dataset/4
.
Last modified 2mo ago