Skip to content

tejas004s/Object-detection-and-instance-segmentation

Repository files navigation

# 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 torchvision

Dataset Structure

The dataset should be structured as follows:

PennFudanPed/
├── PNGImages/
│   ├── image1.png
│   ├── image2.png
│   └── ...
└── PedMasks/
    ├── image1.png
    ├── image2.png
    └── ...

Usage

To use the dataset, follow these steps:

  1. 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
  2. Create an instance of the dataset:

    dataset = PennFudanDataset('path/to/PennFudanPed')
  3. Create a DataLoader:

    data_loader = DataLoader(dataset, batch_size=2, shuffle=True, num_workers=4)
  4. Iterate over the data:

    for images, targets in data_loader:
        if images is None or targets is None:
            continue
        print(images.shape, targets)

Class Description

PennFudanDataset

  • __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.

Main Function

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.

Handling Missing Files

The implementation includes checks to handle missing image or mask files, providing warnings in case any files are not found.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages