mlvbench.stimuli.textures¶
Texturization utilities.
TextureDataset
¶
load_textures(name, seed)
¶
Load a texture dataset and return train, val, and test subsets.
If not done already, this will download and extract the dataset. The textures are split into train, val, and test subsets (80%/10%/10%).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the textures dataset. Only "dtd" is supported. |
required |
seed
|
int
|
Random seed for splitting the dataset into train, val, and test subsets. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Subset]
|
A dictionary of subsets with keys "train", "val", and "test". |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset name is not supported. |
texturize(region_map, texture_dataset, rng)
¶
Fill each region in a region map with a unique random texture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region_map
|
ndarray
|
Integer-labeled region map of shape |
required |
texture_dataset
|
Dataset
|
Dataset of PIL Images. Each item must be a PIL Image that will be resized to match the region map dimensions. Must contain at least as many items as there are unique regions. |
required |
rng
|
Generator
|
NumPy random number generator for reproducibility. Two calls with
the same RNG state but different numbers of regions N and M will
assign the same texture to the first |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
RGB image as uint8 NumPy array of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of unique regions exceeds the dataset size. |