Export¶
While Tables are designed to be used directly in model training, one might want to export the modified data into
a common format such as CSV or COCO, or to a custom format. This can be achieved by using the built-in exporters in the
CLI and Python API, the 3lc-tools package or
custom iteration.
Built-in exporters¶
Built-in exporters can be used through the Python API or CLI, and currently CSV, COCO and JSON are supported output formats.
Using Table.export()¶
To export a 3LC Table, you can use the table.export() method from the
tlc package to export.
import tlc
table = tlc.Table.from_url("path/to/3LC/Table")
table.export("path/to/output/folder/my_dataset.csv")
The example above will export a 3LC Table to a CSV file named my_dataset.csv in the output location you specified.
If you want to export a 3LC Table containing bounding boxes to the COCO format, you just need to use ājsonā as the fileās extension such as my_dataset.json.
Using the 3LC CLI¶
In a terminal (with the tlc Python Package installed), the command line tool can be invoked as follows:
3lc export path/to/table.json <output-path>
The output format will be deduced from the extension of <output-path> and the contents of the table, but can also be
explicitly specified using the --format option. For more details, use
3lc export --help
In-memory export¶
To export the data in a tlc.Table to a Pandas DataFrame, use
df_from_table = table.to_pandas()
This will return the rows of the Table in a Pandas dataframe.
Custom format¶
To export to a custom format, iterate over the tlc.Table directly and write
the data to your desired format. Here we assume you have a function my_export_fn that performs the necessary steps to
serialize and write the data.
table = Table.from_url(input_url)
my_table_dict = {"col1": [], "col2": []}
for sample in table:
my_table_dict["col1"] = sample[0]
my_table_dict["col2"] = sample[1]
my_export_fn(my_table_dict)
Exporting a Table to YOLO format using the tlc_tools package¶
To export a 3LC Table or a set of Tables (such as train and val Tables) containing bounding boxes to the YOLO format,
you will need another designated method in the tlc_tools package, because it will write out a number of files for
images, labels, and the YAML file instead of a single file. The tlc_tools Python package provides a set of
ready-to-use methods and functionalities at your disposal. You can follow the instructions in our public
GitHub repository to install it.
import tlc
from tlc_tools.yolo_export import export_to_yolo
train_table = tlc.Table.from_url("path/to/train/Table")
val_table = tlc.Table.from_url("path/to/val/Table")
export_to_yolo(
tables={
"train": train_table,
"val": val_table,
},
output_url="path/to/output/folder",
dataset_name="my_dataset",
image_strategy="copy",
)
In the export_to_yolo method, you can specify both the train and val Tables at once or just one single Table. The
value of the dataset_name will be the YAML fileās name. There are several options for the argument image_strategy.
The default is copy, which will copy all the images into the output folder. If you donāt want to copy the images, you
can specify it as ignore.