mamonraab / violance-detection-in-video-with-pytroch

MIT License
57 stars 17 forks source link

About loading the data #2

Closed jwhmicrsoft closed 3 years ago

jwhmicrsoft commented 3 years ago

I want to know the datas of the Class 'VideoDataset' is the path of the filefolder of the video file? And how to label those video? Would u like to show me the training code plz? thanks!

mamonraab commented 3 years ago

you just need to give it a pandas data frame that contain 2 col (the full file path of video , the label of that video) in my case there was 2 folders one for violence and the another for none-violence. I loop overtime store the files names with labels in pandas data frame and save it as csv for latter use

jwhmicrsoft commented 3 years ago

Ok thanks. One more question, I ran your Class 'VideoDataset' ,and load the csv, but there's an error:the variate 'label' is not defined, just like this here:

File "E:/violance-detection-in-video-with-pytroch-main/flaskapp/train.py", line 31, in getitem sample = {'video': torch.from_numpy(video), 'label': torch.from_numpy(label)} NameError: name 'label' is not defined

how to fix it?

jwhmicrsoft commented 3 years ago

Well... I replace the "torch.from_numpy(label)" as "self.datalocation.iloc[idx, 1]", then it works. But I still wanna know why u use the "torch.from_numpy(label)" code.

mamonraab commented 3 years ago

hello , if you check the main page it is a trtoural on how to build these staff so first i give skelton code than i give full code of the class which is

` from torch.utils.data import Dataset

class VideoDataset(Dataset): """Video dataset."""

def __init__(self, datas, timesep=30,rgb=3,h=120,w=120):
    """
    Args:
        datas: pandas dataframe contain path to videos files with label of them
        timesep: number of frames
        rgb: number of color channels
        h: height
        w: width

    """
    self.dataloctions = datas
    self.timesep,self.rgb,self.h,self.w = timesep,rgb,h,w

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

def __getitem__(self, idx):
    if torch.is_tensor(idx):
        idx = idx.tolist()
    video = capture(self.dataloctions.iloc[idx, 0],self.timesep,self.rgb,self.h,self.w)
    sample = {'video': torch.from_numpy(video), 'label': torch.from_numpy(np.asarray(self.dataloctions.iloc[idx, 1]))}

    return sample

`

jwhmicrsoft commented 3 years ago

Got it. Thanks!