TrainValSplits
Introduction
TrainValSplits widget in Supervisely is a tool that helps with the creation of training and validation datasets. The widget allows for easy splitting of the original dataset into training and validation sets based on customizable parameters such as percentage split or based on datasets or specific tag. TrainValSplits helps improve the performance of machine learning models by ensuring that they are trained on diverse and representative data.
Function signature
TrainValSplits(
project_id=None,
project_fs=None,
random_splits=True,
tags_splits=True,
datasets_splits=True,
widget_id=None,
collections_splits=False,
)
Parameters
project_id
int
Input Project ID
project_fs
str
Path to input Project on local host
random_splits
bool
Shuffle data and split with defined probability
tags_splits
bool
Images should have assigned train or val tag
datasets_splits
bool
Select one or several datasets for every split
widget_id
str
ID of the widget
collections_splits
bool
If True, allows to split data into train and validation sets based on selected collections within the project.
project_id
Determine input Project ID.
type: int
default value: None
project_fs
Determine path to input Project on local host.
type: str
default value: None

random_splits
Shuffle data and split with defined probability.
type: bool
default value: true

tags_splits
Images should have assigned train or val tag.
type: bool
default value: true

datasets_splits
Select one or several datasets for every split.
type: bool
default value: true

widget_id
ID of the widget.
type: str
default value: None
collections_splits
Allows to split data into train and validation sets based on the provided collections.
type: bool
default value: False
Methods and attributes
get_splits()
Return result train/val split.
disable()
Disable widget.
enable()
Enable widget.
set_project_id_for_collections()
Sets the project ID and updates available collections for train and validation splits.
get_train_collections_ids()
Returns a list of collection IDs selected for the training split.
get_val_collections_ids()
Returns a list of collection IDs selected for the validation split.
set_collections_splits()
Sets the collections (by their IDs) to be used for the training and validation splits when using the "collections" split method.
set_collections_splits_by_ids()
Set for the specified split (train or val) sets the provided collection IDs.
Mini App Example
You can find this example in our Github repository:
supervisely-ecosystem/ui-widgets-demos/controls/006_train_val_splits/src/main.py
Import libraries
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance:
Prepare project_id, download project and create project_fs
Initialize TrainValSplits widget
TrainValSplits widgetInitialize Button and Text widget we will use
Button and Text widget we will useCreate app layout
Prepare a layout for app using Card widget with the content parameter and place widget that we've just created in the Container widget.
Create app using layout
Create an app object with layout parameter.
Add function to control widgets from python code

Last updated
Was this helpful?