ImageFolder#
- class deeptrack.sources.folder.ImageFolder(root)#
Bases:
Source
Data source for images organized in a directory structure.
This class assumes that the images are organized in a directory structure where:
- ```bash
root/dog/xxx.png root/dog/xxy.png root/[…]/xxz.png
root/cat/123.png root/cat/nsdf3.png root/[…]/asd932_.png
The first level of directories (e.g., dog, cat) is used as labels for the images, and the images are expected to have file extensions included in known_extensions.
Parameters#
- pathlist
List of paths to the image files.
- labellist
List of corresponding labels for each image.
- label_namelist
List of category names corresponding to each label.
Methods#
- classeslist
Returns a list of unique class names (category names).
- __init__(root: str)
Initializes the ImageFolder instance by scanning the directory structure.
- __len__()
Returns the total number of images in the dataset.
- get_category_name(path: str, directory_level: int)
Retrieves the category name (directory name) for the given image path at a specific directory level.
- label_to_name(label: int)
Converts a label index to the corresponding category name.
- name_to_label(name: str)
Converts a category name to the corresponding label index.
- split(*splits: str)
Splits the dataset into subsets based on the folder structure. The first folder name in the path will be used to define the split.
Attributes Summary
Methods Summary
get_category_name
(path, directory_level)label_to_name
(label)name_to_label
(name)split
(*splits)Split the dataset into subsets.
Attributes Documentation
- classes#
Methods Documentation
- get_category_name(path, directory_level)#
- label_to_name(label)#
- name_to_label(name)#
- split(*splits: str)#
Split the dataset into subsets.
The splits are defined by the names of the first folder in the path of each image. For example, if the dataset contains images in the following structure:
```bash root/A/dog/xxx.png root/A/dog/xxy.png root/A/[…]/xxz.png
root/B/cat/123.png root/B/cat/nsdf3.png root/B/[…]/asd932_.png ```
Then the dataset can be split into two subsets, one containing all images in the A folder and one containing all images in the B folder.
Parameters#
- splitsstr
The names of the categories to split into.