Giter Club home page Giter Club logo

yourselfdataloader's Introduction

YourselfDataloader

create your own dataloader format data from your own data

This time I put the jupyter notebook code for easy learning and edition, Once you confirm it is helpful, you can write as python lib

PyTorch DataLoader PyTorch DataLoader is a utility for loading data in PyTorch. It provides an iterator over a dataset, allowing for efficient batching, shuffling, and parallel loading of data, which can significantly accelerate the training process.

Features Dataset: A container for storing samples and their corresponding labels. Users need to inherit from torch.utils.data.Dataset and implement getitem and len methods for retrieving a single sample and the dataset length, respectively.

DataLoader: An iterator for loading a Dataset. It can be configured with the following parameters:

batch_size: The number of samples per batch shuffle: Whether to shuffle the data at the start of each epoch num_workers: The number of subprocesses to use for data loading drop_last: Whether to drop the last incomplete batch if its size is less than batch_size Sampler: Defines the strategy for sampling from the dataset. PyTorch provides several common Sampler types such as RandomSampler and SequentialSampler. You can also define your own custom Sampler to meet specific requirements.

Usage Define your Dataset class:

from torch.utils.data import Dataset

class MyDataset(Dataset):
    def __init__(self, data, labels):
        self.data = data
        self.labels = labels

    def __getitem__(self, index):
        # Return a single sample and its label
        return self.data[index], self.labels[index]

    def __len__(self):
        return len(self.data)

Create a DataLoader instance:

from torch.utils.data import DataLoader

dataset = MyDataset(data, labels)
dataloader = DataLoader(dataset, batch_size=32, shuffle=True, num_workers=4)

Create a DataLoader instance:

from torch.utils.data import DataLoader

dataset = MyDataset(data, labels)
dataloader = DataLoader(dataset, batch_size=32, shuffle=True, num_workers=4)

Iterate over the DataLoader:

for batch_data, batch_labels in dataloader:
    # Process the batch data
    ...

#or
for i, (imgs, labels) in enumerate(dataloaders['train']):
    # use your dataset by imgs and labels

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.