How to use aliases when creating a Table#
An alias is simply a text string that represents a part of a path to an object. Aliases can help you share 3LC runs and Tables across machines without needing to move large amounts of bulk data. For details about aliases, please visit the Sharing 3LC Tables and Runs page. If you want to incorporate aliases into your 3LC Tables, you need to set up the aliases before you create the Tables.
You can set up aliases in the config.yaml file, which is located at %LocalAppData%\3LC\3LC\config.yaml
for Windows.
For other Operating Systems, please see the page Default File Locations. Under the aliases
section in the YAML file, you set an alias like this below, assuming that the Cifar-10 data is located in
C:/Users/Adam/my_data/Cifar-10-data/
.
aliases:
CIFAR10_DATA: C:/Users/Adam/my_data/Cifar-10-data/
You can also set up aliases through environment variables. Environment variables with the prefix TLC_ALIAS_
will be
picked up during initialization of the tlc
module. To define an alias equivalent to the example above, you might for
instance run:
export TLC_ALIAS_CIFAR10_DATA="C:/Users/Adam/my_data/Cifar-10-data/"
If an image’s absolute path is C:/Users/Adam/my_data/Cifar-10-data/train/image_1.jpg
, the aliased path for this image
will be <CIFAR10_DATA>/train/image_1.jpg
. All image URLs will be stored with the aliased paths in the 3LC Table. When
you share this project with others, they need to specify where the corresponding bulk data is located on their
system by setting up the same alias on their system.
Registering aliases#
In addition to setting up aliases ahead of script execution, you can also register aliases programmatically. The following snippet shows how to register aliases programmatically:
import tlc
tlc.register_url_alias("CIFAR10_DATA", "C:/Users/Adam/my_data/Cifar-10-data/")
Applying aliases to paths#
The following snippet shows how to apply and resolve aliases manually:
import tlc
my_path = "C:/Users/Adam/my_data/Cifar-10-data/train/image_1.jpg"
aliased_path = tlc.Url(my_path).apply_aliases()
# tlc.Url("<CIFAR10_DATA>/train/image_1.jpg")
unaliased_path = aliased_path.expand_aliases()
# tlc.Url("C:/Users/Adam/my_data/Cifar-10-data/train/image_1.jpg")