RaivoKoot / Video-Dataset-Loading-Pytorch

Generic PyTorch dataset implementation to load and augment VIDEOS for deep learning training loops.
BSD 2-Clause "Simplified" License
447 stars 43 forks source link

Problems with batch size #22

Closed JonasNasimzada closed 7 months ago

JonasNasimzada commented 7 months ago

Hello, first of all thank u for this nice video DataLoader.

I want to implement this into my project but currently I encounter into problems. Like u described I preprocessed my video into frames and created the .txt file. If u want now to load into my project I get a RuntimeError : RuntimeError: Expected 3D (unbatched) or 4D (batched) input to conv2d, but got input of size: [125, 5, 3, 224, 224] The 125 is my batch size, 5 my num_segments, and so on.

I tried to reshape my video batch like this: batch_size, frames, channels, height, width = video.shape video = video.reshape(batch_size * frames, channels, height, width) But then I get problems with my labels in the batch: ValueError: Target size (torch.Size([64, 1])) must be the same as input size (torch.Size([320, 1]))

Do u know how to fix it or did I do sth wrong?

here's my code- part I am currently using:

def train_dataloader(self):
    preprocess = Compose([
        ImglistToTensor(),
        RandomResizedCrop(224, scale=(0.8, 1.0)),
        RandomHorizontalFlip(),
        RandomRotation(degrees=15),
        ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1),
        Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
    ])
    dataset = VideoFrameDataset(
        root_path=self.video_path_prefix,
        annotationfile_path=self.annotation_file_train,
        num_segments=5,
        frames_per_segment=1,
        imagefile_template='frame_{:04d}.jpg',
        transform=preprocess,
        test_mode=False
    )
    loader = torch.utils.data.DataLoader(
        dataset=dataset,
        batch_size=self.batch_size,
        shuffle=True,
        num_workers=self.num_worker,
        pin_memory=True
    )

Thanks in advance :)