Step 2: Creating Hub Datasets Manually
Creating and storing Hub Datasets manually
Creating Hub datasets is simple, you have full control over connecting your source data (files, images, etc.) to specific tensors in the Hub Dataset.
Let's follow along with the example below to create our first dataset. First, download and unzip the small classification dataset below called animals dataset.
The dataset has the following folder structure:
Now that you have the data, you can create a Hub Dataset and initialize its tensors. Running the following code will create Hub dataset inside of the ./animals_hub
folder.
Specifying htype
and dtype
is not required, but it is highly recommended in order to optimize performance, especially for large datasets. Usedtype
to specify the numeric type of tensor data, and usehtype
to specify the underlying data structure. More information on htype can be found here.
Next populate data in the tensors using the following code:
ds.images.append(load(path))
is functionally equivalent to ds.image.append(PIL.Image.fromarray(path))
. However, the hub.load()
method is significantly faster because it does not decompress and recompress the image if the compression matches thesample_compression
for that tensor. Further details are available in Understanding Compression.
Creating Tensor Hierarchies - Coming Soon
Often it's important to create tensors hierarchically, because information between tensors may be inherently coupled—such as bounding boxes and their corresponding labels. Hierarchy can be created using the following lines of code:
For more detailed information regarding accessing datasets and their tensors, check out the next section.
Last updated