# PennFudan Dataset Loader
This project provides a custom dataset class for loading the Penn-Fudan Pedestrian Dataset using PyTorch's `Dataset` and `DataLoader` classes. The dataset contains images and segmentation masks for pedestrian detection.
## Overview
The `PennFudanDataset` class allows you to load images and corresponding masks from the dataset, applying any specified transformations. This is particularly useful for training deep learning models for object detection and segmentation tasks.
## Installation
Make sure you have the following packages installed:
```bash
pip install torch torchvisionThe dataset should be structured as follows:
PennFudanPed/
├── PNGImages/
│ ├── image1.png
│ ├── image2.png
│ └── ...
└── PedMasks/
├── image1.png
├── image2.png
└── ...
To use the dataset, follow these steps:
-
Import the necessary modules:
from torch.utils.data import DataLoader from your_script import PennFudanDataset # replace 'your_script' with the name of your Python file
-
Create an instance of the dataset:
dataset = PennFudanDataset('path/to/PennFudanPed')
-
Create a
DataLoader:data_loader = DataLoader(dataset, batch_size=2, shuffle=True, num_workers=4)
-
Iterate over the data:
for images, targets in data_loader: if images is None or targets is None: continue print(images.shape, targets)
__init__(self, root, transforms=None): Initializes the dataset. Takes the root directory of the dataset and optional transforms.__getitem__(self, idx): Returns the image and target (mask, bounding boxes, etc.) for a given index.__len__(self): Returns the total number of images in the dataset.
The main() function demonstrates how to create a dataset and a data loader, and it prints the shape of the loaded images and their targets.
The implementation includes checks to handle missing image or mask files, providing warnings in case any files are not found.
This project is licensed under the MIT License - see the LICENSE file for details.
This dataset and code were inspired by the Penn-Fudan Pedestrian Dataset, which can be found here.
### Notes:
- Replace `your_script` in the usage section with the actual name of your Python file.
- Adjust the paths and any other details according to your project structure and requirements.