RandomSplitsTable
Introduction
RandomSplitsTable
widget in Supervisely allows users to create random splits of their data for training, validation, and testing purposes. The widget enables users to define the percentage of data they want to allocate to each split, and then randomly assigns images or annotations to each split. This widget is particularly useful for machine learning projects, as it allows users to easily manage their training, validation, and testing data without having to manually split the data themselves. RandomSplitsTable
widget provides a flexible and convenient way for users to organize their data splits, and can be customized to match the requirements of their project. RandomSplitsTable
widget is a valuable tool for improving the accuracy and efficiency of machine learning projects that require data splits.
Function signature
RandomSplitsTable(
items_count,
start_train_percent=80,
disabled=False,
widget_id=None,
)

Parameters
items_count
int
Number of items to split
start_train_percent
int
Start %
to split items
disabled
bool
Disable widget
widget_id
str
ID of the widget
items_count
Determine number of items to split.
type: int
random_splits_table = RandomSplitsTable(items_count=777)

start_train_percent
Determine start %
to split items. If start_train_percent
not in range [1; 99] raise ValueError
.
type: int
default value: 80
random_splits_table = RandomSplitsTable(
items_count=100,
start_train_percent=10,
)

disabled
Disable widget.
type: bool
default value: False
random_splits_table = RandomSplitsTable(
items_count=100,
disabled=True,
)

widget_id
ID of the widget.
type: str
default value: None
Methods and attributes
get_splits_counts()
Returns the result of separating items { "total": <int>, "train": <int>, "val": <int>}
.
Mini App Example
You can find this example in our Github repository:
ui-widgets-demos/tables/005_random_splits_table/src/main.py
Import libraries
import os
import supervisely as sly
from supervisely.app.widgets import Card, Container, RandomSplitsTable
from dotenv import load_dotenv
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance:
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()
Prepare items count
project_id = sly.env.project_id()
project = api.project.get_info_by_id(project_id)
items_count = project.items_count
Initialize RandomSplitsTable
widget
RandomSplitsTable
widgetrandom_splits_table = RandomSplitsTable(
items_count=items_count,
start_train_percent=40,
)
Create Button
and Text
widgets
Button
and Text
widgetsbutton = Button("Button")
text = Text()
Create 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.
card = Card(
title="Random Splits Table",
content=Container([random_splits_table, button, text]),
)
layout = Container(widgets=[card])
Create app using layout
Create an app object with layout parameter.
app = sly.Application(layout=layout)
Add function to control widget from code
@button.click
def show_split_settings():
text.text = random_splits_table.get_splits_counts()

Last updated
Was this helpful?