abedidev / ResNet-TCN

40 stars 12 forks source link

Cannot train my own dataset #1

Closed StephenZhao1 closed 3 years ago

StephenZhao1 commented 3 years ago

I import your net and randomly generate a picture as follow.

data = torch.randn([1,3,40,40]) net = ResTCN() y = net.forward(data) print(y.shape)

But it give an error. x = self.resnet(data[:, t, :, :, :]) IndexError: too many indices for tensor of dimension 4

What can I do? change the data shape?I do not see you test demo.THX.

abedidev commented 3 years ago

The ResTCN is a hybrid neural network architecture for video analysis. The input to the network should be video, sequences of frames with this format,

inputs = torch.randn([batch_size, sequence_length, num_channels, frame_width, frame_height])

Please try a random video batch as input to the ResTCN, for instance:

import torch
from ResTCN import ResTCN
model = ResTCN().cuda()
inputs = torch.randn([16, 30, 3, 256, 256]).cuda()
outputs = model(inputs)

If you want to train the network with your own video dataset, first, the frames from each video file should be extracted using ffmpeg or OpenCV, then the frames of each video should be put in separate directories. Then the addresses of directories and the video labels should be written in a CSV file as I explained in readme. Then, the CSV file should be read by PyTorch DataLoader, using get_dataloader function. Then you can use the dataset in training iterations.