Image datasets for Pytorch.
Project description
torch image dataset
Install:
pip install torch-image-dataset
Datasets for image classification
AdvanceImageFolder
Use case:
- keep track of pseudolabels (read/update).
- load full dataset into RAM to speed up training when disk memory access is slow.
- easy subsetting/splitting keeping the possibility to update and read pseudolabels.
Import:
from imagedataset import AdvanceImageFolder
It is a subclass of torchvision.datasets.ImageFolder so it asks for a dataset structure in the form:
root\
class1\
img1
img2
...
class2\
img1
img2
...
...
The dataset is initialized by indicating the root directory.
As ImageFolder it is possible to indicate the transorm for inputs and for targets. Additionally, the name of the dataset can be indicated and it is possible to load just a subset of the dataset. load_percentage specifies the percentage of images to load (randomly picked without repetitions) or indices can be used to select specific indices of the dataset.
dataset = AdvanceImageFolder(root="path/to/mydataset/",
name="incredible_dataset",
transform=None,
target_transform=None,
load_percentage=1.,
indices=None)
The return type of the dataset is types.SimpleNamespace with the following fields:
- image
- id
- index
- label
- pseudolabel
For example you can:
item = dataset.__getitem__(0)
image = item.image
label = item.label
pseudolabel = item.pseudolabel
...
To use a dataloader it is possible to use:
loader = dataset.dataloader(batch_size=10)
Actually the dataloader function accepts the same arguments as torch.utils.data.DataLoader and returns a proper DataLoader with the appropriate collate_fn for batching.
To subset a dataset:
my_subset = dataset.subset(indices=[0,1,2], ids=None)
It is possible to select the indices or the ids of images. The indices are the positions of images in the sequence from 0 to len(dataset)-1. Ids are initialized as indices but they are kept constant while subsetting and splitting and, for this reason, it is possible to get the index of an image in the original dataset.
To split a dataset:
train_d, val_d, test_d = dataset.random_split(percentages=[0.5, 0.3, 0.2])
To drop a random part of the dataset, let say we want to keep just 50% of dataset:
dataset = datset.random_split(percentages=[0.5])
To load the dataset into RAM just use:
dataset.load_ram()
And if you want to release the allocated memory while keeping the dataset:
dataset.clean_ram()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torch-image-dataset-0.0.2.tar.gz.
File metadata
- Download URL: torch-image-dataset-0.0.2.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b74d028b989085e1effadc92e26a86d9a72e4487c9897d57fff45aa861ec9e99
|
|
| MD5 |
6a243e294b74960df8bdb5838eb93ed5
|
|
| BLAKE2b-256 |
436df1a4e68e10472530dc8a35b8fb7f1c08409ebebd4eaa0ba19c1fcea7b6d3
|
File details
Details for the file torch_image_dataset-0.0.2-py3-none-any.whl.
File metadata
- Download URL: torch_image_dataset-0.0.2-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4f53c670981d8522877697c943db85009f427a01695f076dfd0d559fc2b1434
|
|
| MD5 |
756bbfe8d890ded2054dd36d9f1f3184
|
|
| BLAKE2b-256 |
035772cfd3cd1e7aaef7fbe901d074a920ce19bb8c22421ef31181f771421f62
|