Custom Pascal VOC Dataset reader for PyTorch
Project description
Custom Pascal VOC PyTorch Module
This PyTorch module serves as a flexible dataset reader for custom datasets created using the Pascal VOC format. It is a modified version of the original Pascal VOC dataset reader provided by PyTorch's torchvision package. The primary enhancement is the removal of folder structure restrictions, allowing users to read datasets organized in any manner while still leveraging the Pascal VOC annotation structure.
Classes
The module includes two classes: VOCDetection
and VOCSegmentation
.
VOCDetection :
This class is designed for reading datasets following Pascal VOC Detection format.
VOCDetection(root: str, image_set: str = 'train', transform: Optional[Callable] = None,
target_transform: Optional[Callable] = None, transforms: Optional[Callable] = None)
Parameters:
- root (string): Root directory of the VOC Dataset.
- image_set (string, optional): Select the image_set to use,
"train"
,"val"
or"test"
. - transform (callable, optional): A function/transform that takes in a PIL image and returns a transformed version. E.g,
transforms.RandomCrop
. - target_transform (callable, required): A function/transform that takes in the target and transforms it.
- transforms (callable, optional): A function/transform that takes input sample and its target as entry and returns a transformed version.
VOCSegmentation
This class is tailored for reading datasets structured in the Pascal VOC Segmentation format.
VOCSegmentation(root: str, image_set: str = 'train', transform: Optional[Callable] = None,
target_transform: Optional[Callable] = None, transforms: Optional[Callable] = None)
Parameters:
- root (string): Root directory of the VOC Dataset.
- image_set (string, optional): Select the image_set to use,
"train"
,"val"
or"test"
. - transform (callable, optional): A function/transform that takes in a PIL image and returns a transformed version. E.g,
transforms.RandomCrop
. - target_transform (callable, optional): A function/transform that takes in the target and transforms it.
- transforms (callable, optional): A function/transform that takes input sample and its target as entry and returns a transformed version.
Installing
You can install the package from pypi using the following code:
pip install --update customVOC
Using customVOC
After installing the module, you can import either of the two classes: 'VOCDetection' and 'VOCSegmentation'.
from customVOC import VOCDetection
from customVOC import VOCSegmentation
Once imported, you can use these classes similarly to the ones from the torchvision package, without passing the year. When initializing, provide the root folder containing the dataset with one of the following subfolders: "train"
, "val"
, or "test"
depending on the dataset portion you are using.
The following example loads the training dataset and converts the image to a tensor using ToTensor()
:
from customVOC import VOCDetection
from torchvision.transforms import ToTensor
from torch.utils.data import DataLoader
# Create an instance of VOCDetection dataset.
voc_dataset = VOCDetection(root="datset_path",image_set="train", transform=ToTensor())
# Create a DataLoader for the VOCDetection dataset.
data_loader = DataLoader(voc_dataset, batch_size=4, shuffle=True, collate_fn=lambda batch: tuple(zip(*batch)))
[!TIP] The collate function is used to customize how batches are created from individual samples in the dataset.
[!NOTE]
- The package is an absolute copy of the original code, with modifications to the way of reading image and annotation files locations.
- The images and annotations files should be stored in the same folder, either train, val, or test, depending on what part of the dataset you have.
- Only VOCDetection has been tested on reading datasets.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file customVOC-0.0.1.tar.gz
.
File metadata
- Download URL: customVOC-0.0.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42a9178ab832f240420a452398d3935515dff54d6c563dd7b6f28e0f08b1d395 |
|
MD5 | 2deb8735dc0d9fd779578475abfe7adb |
|
BLAKE2b-256 | 49e70f911dc31b2ef280777f41b16b021580a99f78b64f78b3d5a78170147dd2 |
File details
Details for the file customVOC-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: customVOC-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9ec453da0fec8a6a78fa94d0fc41016529b0a6166d78f091deab2fe2fe28661 |
|
MD5 | dc8eb56f75c324edb5916e2482cef127 |
|
BLAKE2b-256 | cc2efb137d8f215f9b89eccbe7b8ec15344a8b8b68a7ecba281e8a555e2016cc |