Closed jwhmicrsoft closed 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
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?
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.
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
`
Got it. Thanks!
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!