simet.datasets.no_class_image_dataset¶
simet.datasets.no_class_image_dataset ¶
NoClassImageDataset ¶
NoClassImageDataset(root, transform=None, target_transform=None)
Bases: VisionDataset
Unlabeled image dataset loaded from a folder tree.
Recursively scans the root directory for image files and returns samples
as (image, target) pairs where the target is always 0 (dummy label).
Useful for feature extraction, self-supervised preprocessing, or inference
pipelines that expect a Dataset interface without class folders.
Supported extensions (case-insensitive): .jpg, .jpeg, .png,
.bmp, .tiff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path | str
|
Root directory to scan recursively for images. |
required |
transform
|
Callable | None
|
Optional transform applied to each PIL image (after RGB conversion).
Typical usage is a torchvision transform pipeline producing a |
None
|
target_transform
|
Callable | None
|
Accepted for API parity with |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
image_paths |
list[Path]
|
Absolute paths to all discovered image files under |
Notes
- Directory traversal is recursive via
Path.rglob('*'). - File extension matching is case-insensitive.
- The returned target is the integer
0; downstream code should ignore or replace it if labels are not needed. - If you need a tensor target or to apply
target_transform, consider wrapping this dataset or subclassing and overriding__getitem__.
Example
ds = NoClassImageDataset("data/images", transform=my_tfms) len(ds) > 0 True x, y = ds[0] int(y) 0
Initialize the dataset; see class docstring for parameter details.
Source code in simet/datasets/no_class_image_dataset.py
54 55 56 57 58 59 60 61 62 | |
__getitem__ ¶
__getitem__(idx)
Load and return the (image, target) pair at index idx.
The image is opened with PIL and converted to RGB, then transform is
applied if provided. The target is the constant integer 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
Index of the sample to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Image | Tensor, int]
|
tuple[PIL.Image.Image | torch.Tensor, int]:
Transformed image (or raw PIL image if no transform) and the dummy target |
Source code in simet/datasets/no_class_image_dataset.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
__len__ ¶
__len__()
Return the number of images discovered under root.
Source code in simet/datasets/no_class_image_dataset.py
82 83 84 | |