Links

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()

Create Project

1
rf.create_project("project name", "project-type", "project-license", "annotation-group")
create_project() creates a project of your desired project_name (required argument) in your chosen and authenticated Roboflow Workspace, with your selected project type (required argument).
Available project_type options:
  1. 1.
    object-detection
  2. 2.
    classification
  3. 3.
    instance-segmentation
  4. 4.
    semantic-segmentation
For those in Public workspaces, or Community workspaces with public projects, the project_license (required argument) is set based on chosen preference.
annotation (required argument) provides an option to specify the annotation group you would like to associate with the project during the project creation flow.
Example Usage:
Object Detection Project Created with create_project()
Note: setting a project_license is optional. It will default to CC BY 4.0 for public projects. Project licenses are set for public projects since they are available to view or download by others in the global computer vision community on Roboflow Universe.
1
from roboflow import Roboflow
2
3
# authenticate and choose your workspace
4
rf = Roboflow(api_key="API_KEY")
5
workspace = rf.workspace("YOUR_WORKSPACE")
6
7
# creating an object detection project
8
workspace.create_project(project_name="Defect Detection and Location", "object-detection", project_license="", annotation="defectDetection")
9
10
# creating a single-label classification project
11
workspace.create_project(project_name="Defect Severity Classification", project_type="object-detection", project_license="", annotation="defectSeverity")
12
13
# creating a multi-label classification project
14
workspace.create_project(project_name="Defect Type and Severity Classification", project_type="classification", project_license="", annotation="defectTypeSeverity")
15
16
# creating an instance segmentation project
17
workspace.create_project(project_name="Defect Size Estimation", project_type="instance-segmentation", project_license="", annotation="defectSizeEst")
18
19
# creating a semantic segmentation project
20
workspace.create_project(project_name="Robot Path Planning - Defect Monitor", project_type="semantic-segmentation", project_license="", annotation="defectPathPlan")
core/workspace.py
1
def create_project(self, project_name, project_type, project_license, annotation):
2
data = {
3
"name": project_name,
4
"type": project_type,
5
"license": project_license,
6
"annotation": annotation,
7
}

Generate

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 and Download

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"]
};

Train

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.