Jigsaw-VAD icon indicating copy to clipboard operation
Jigsaw-VAD copied to clipboard

dataset?

Open hjs2027864933 opened this issue 2 years ago • 26 comments

Hi, thanks a lot for your great work. “python main.py --dataset shanghaitech --val_step 100 --print_interval 20 --batch_size 192 --sample_num 9 --epochs 100 --static_threshold 0.2 The running_data : 2022-10-08-20-20-25 -------------val_step : 100 -------------print_interval : 20 -------------epochs : 100 -------------gpu_id : 0 -------------log_date : None -------------batch_size : 192 -------------static_threshold : 0.2 -------------sample_num : 9 -------------filter_ratio : 0.8 -------------checkpoint : None -------------dataset : shanghaitech -------------device : cuda:0 Traceback (most recent call last): File "main.py", line 211, in train(args) File "main.py", line 64, in train static_threshold=args.static_threshold) File "/data/hjs/JigsawVAD/dataset.py", line 63, in init self._load_data(file_list) File "/data/hjs/JigsawVAD/dataset.py", line 74, in _load_data l = os.listdir(self.data_dir + '/' + video_file) NotADirectoryError: [Errno 20] Not a directory: '/data/hjs/Datasets/shanghaitech/training/01_001.avi'” Hi, the above is the error I am getting when I try to train the model. I observed the code and found that the data in the training set is in video format, do I need to convert it to a frame-by-frame image format like in the test set? That is to say, the training set in the data set I downloaded is in video format, and the test set is in frame-by-frame image format. Or can you post the structure of your dataset so that it can also answer my question?

hjs2027864933 avatar Oct 08 '22 12:10 hjs2027864933

@hjs2027864933 You need a frame-by-frame extraction of the original video (.avi) for both training and testing and use our script (gen_patches.py) to generate spatio-temporal cubes (.npy format for each cube). For STC, you may download from here.

My dataset structure like shanghaitech/ --training/ ----01_001/ ------xxx.npy ----13_007/ --testing/ ----01_0014/ ------xxx.npy ----12_0175/

Hope it helps you.

gdwang08 avatar Oct 08 '22 13:10 gdwang08

@gdwang08 Thank you for your reply, I am currently extracting the video frame by frame in the training set, and the data in the test set is downloaded in the format of frame-by-frame images. Thanks again.

hjs2027864933 avatar Oct 08 '22 13:10 hjs2027864933

@gdwang08 Thank you for your great work. I'm total new here so may I ask you how to get start with your project. I've downloaded STC and I noticed that its structure is exactly different from yours, which means I need to transform it into your structure then I could run the main.py? According to the transofrm part, may you post the structure that can used in the script, Is it like:./training/01_001/001.jpg-xxx.jpg ? I'd very appreciate it if you could answer my question !

20220201yyds avatar Oct 15 '22 08:10 20220201yyds

@20220201yyds Correctly! You need to extract the video frames from the .avi videos from the downloaded STC before running gen_patches.py to generate cubes for training and testing. The extracted frames are structured as:

shanghaitech/ --training/ ----01_001/ ------000000.jpg ------000763.jpg ----13_007/ --testing/ ----01_0014/ ------000.jpg ------264.jpg ----12_0175/

Upon completion of cube extraction, you could start running main.py.

gdwang08 avatar Oct 15 '22 09:10 gdwang08

@gdwang08 I get you point well. Thank you very much for your quick respond!

20220201yyds avatar Oct 15 '22 09:10 20220201yyds

@gdwang08 Thank you for your help. “Load 330 videos 274515 frames, 144993 objects, excluding 773 inside objects and 0 small objects in 2.5824193954467773 s. [0:20/756] loss: 4.421163 t_loss: 2.217578 s_loss: 2.203584 time: 11.486290 [0:40/756] loss: 4.407185 t_loss: 2.203002 s_loss: 2.204183 time: 10.582257 [0:60/756] loss: 4.406521 t_loss: 2.209965 s_loss: 2.196556 time: 10.662058 ... ...” As shown above, does this mean normal training? I first extract the video in the training set as pictures frame by frame, then follow your script to get the cube, and then I can start training. I found that the directory for training data and test data needs to be the directory where the image files are stored, not the directory where the .npy files are stored.thanks again for your reply.

hjs2027864933 avatar Oct 16 '22 09:10 hjs2027864933

@hjs2027864933 The logs are correct for normal training. We have a function for loading .npy objects (line). We access the image directory only for acquiring the frame length for each video (line).

gdwang08 avatar Oct 16 '22 11:10 gdwang08

Traceback (most recent call last): File "D:/Pycharm/PyCharm Community Edition 2022.2.2/plugins/python-ce/helpers/pydev/pydevd.py", line 1496, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "D:\Pycharm\PyCharm Community Edition 2022.2.2\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\college\youben\Jigsaw-VAD-main\Jigsaw-VAD-main\main.py", line 214, in train(args) File "D:\college\youben\Jigsaw-VAD-main\Jigsaw-VAD-main\main.py", line 111, in train temp_loss = criterion(temp_logits, temp_labels) File "D:\Anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "D:\Anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\loss.py", line 1164, in forward return F.cross_entropy(input, target, weight=self.weight, File "D:\Anaconda3\envs\pytorch\lib\site-packages\torch\nn\functional.py", line 3014, in cross_entropy return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing) RuntimeError: size mismatch (got input: [2349], target: [145])

Well, I meet the above mistake when I try to train the model. It seems like 'temp_logits' 'temp_labels'is unmatched, how can I handle it or do you have any idea? I'd be very appreciate for your reply.

20220201yyds avatar Oct 18 '22 02:10 20220201yyds

Ps: I change gen_patches.py sample_num = 5, is that the reason?

20220201yyds avatar Oct 18 '22 02:10 20220201yyds

@20220201yyds If you strictly follow the gen_patches.py to generate cubes (sample_num = 9 for STC by default), you need to set sample_num=9 as well.

gdwang08 avatar Oct 18 '22 02:10 gdwang08

(smoothing: True): dataset = shanghaitech, auc = 0.8032474765565923 aver_result: [0.8661003289458111]
(smoothing: True): dataset = shanghaitech, auc = 0.7976571867015447 aver_result: [0.8660842922431914]
(smoothing: True): dataset = shanghaitech, auc = 0.8161432207664905 aver_result: [0.8834202595034952]
(smoothing: True): dataset = shanghaitech, auc = 0.8108976890409723 aver_result: [0.8757438713302407]
(smoothing: True): dataset = shanghaitech, auc = 0.7998620640342544 aver_result: [0.8682183844525357]
(smoothing: True): dataset = shanghaitech, auc = 0.8425006331868004 aver_result: [0.8983839794772231]

Above are my reproduced results, below are the results obtained using the model you provided, 81.6 and 84.3. This seems to be a bit of a gap, I wonder if this is normal? Also, it took me 38 hours to train the model, so I don't really want to train it multiple times.Your reply was very helpful to me, thanks again.

hjs2027864933 avatar Oct 18 '22 02:10 hjs2027864933

@hjs2027864933 The best performance is generally got in the middle of training ([60, 80] epochs in my case). According to my experiments, I get [83.5, 84.5] on average.

gdwang08 avatar Oct 18 '22 03:10 gdwang08

@gdwang08 Thanks for such a quick reply, the best result I got 81.6 came at epoch 80. If I have time, I will train a few more times. thanks again.

hjs2027864933 avatar Oct 18 '22 03:10 hjs2027864933

@gdwang08 I strictly follow your code but I still face the mistake bellow: Traceback (most recent call last): File "D:\Anaconda3\envs\pytorch\lib\site-packages\torch\utils\data_utils\worker.py", line 302, in worker_loop data = fetcher.fetch(index) File "D:\Anaconda3\envs\pytorch\lib\site-packages\torch\utils\data_utils\fetch.py", line 49, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\Anaconda3\envs\pytorch\lib\site-packages\torch\utils\data_utils\fetch.py", line 49, in data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\college\youben\Jigsaw-VAD-main\Jigsaw-VAD-main\dataset.py", line 134, in getitem obj = self.get_object(record["video_name"], record["frame"] - 10, 0) File "D:\college\youben\Jigsaw-VAD-main\Jigsaw-VAD-main\dataset.py", line 163, in get_object obj = np.load(os.path.join(video_dir, str(frame) + '' + str(obj_id) + '.npy')) # (3, 7, 64, 64) File "D:\Anaconda3\envs\pytorch\lib\site-packages\numpy\lib\npyio.py", line 390, in load fid = stack.enter_context(open(os_fspath(file), "rb")) FileNotFoundError: [Errno 2] No such file or directory: 'shanghaitech\testing\03_0061\228_0.npy'

And I search in the 03_0061 file but there is no '228_0.npy', like the picture bellow: image The same mistake happened in 'training' too, so how can I solve this problem? I'd be very appreciate for your reply.

20220201yyds avatar Oct 18 '22 13:10 20220201yyds

@20220201yyds I searched my corresponding folder and found that there is no 228_0.npy file, but I will not report an error. Hope this information can help you.

hjs2027864933 avatar Oct 19 '22 06:10 hjs2027864933

@hjs2027864933 Thanks for your reply,maybe I should check the main.py and dataset.py again.

20220201yyds avatar Oct 19 '22 06:10 20220201yyds

@gdwang08 Thank you for your reply, I am currently extracting the video frame by frame in the training set, and the data in the test set is downloaded in the format of frame-by-frame images. Thanks again.

Hello, I have the same problem as you, can you tell me how do you convert the '.avi' file in the dataset to '.npy'? I would appreciate your convenient answer.

summersnowfish avatar Oct 21 '22 10:10 summersnowfish

@summersnowfish First, you need to extract the frames from avi. files and structure the .jpg files as this. Then you could run gen_patches.py to generate .npy files.

gdwang08 avatar Oct 21 '22 11:10 gdwang08

Thank you for your reply, I know how to do it, thank you very much.

summersnowfish avatar Oct 21 '22 13:10 summersnowfish

Hello, sorry to bother you again. I'm a beginner. I'm having a bit of a problem running your code. I would like to ask you what is the function of the "shanghaitech_train_detect_result_yolov3.pkl" file? I downloaded the dataset and used a python script on the Internet to convert the file in .avi format to .jpg format. Then use your script to convert the .jpg format file to .npy format. But when the main program is running, a frame out of bounds error occurs (in the _load_data step). I'm puzzled by this. I would appreciate it if you could give advice in your busy schedule.

summersnowfish avatar Oct 24 '22 10:10 summersnowfish

@summersnowfish "shanghaitech_train_detect_result_yolov3.pkl" stores the frame-by-frame object detection results for STC by YOLOv3. You may first check if the number of extracted frames match the number of frame-level detection results for each video.

gdwang08 avatar Oct 24 '22 12:10 gdwang08

@summersnowfish I have also encountered an error of frame out of bounds before, you can try to change the directory of the training set and test set to the directory where the .jpg files are stored instead of the directory where the .npy files are stored.

hjs2027864933 avatar Oct 25 '22 03:10 hjs2027864933

@gdwang08 @hjs2027864933 Thank you for your reply. I know what went wrong. Thank you again.

summersnowfish avatar Oct 25 '22 06:10 summersnowfish

@gdwang08 Hello, thank you very much for your work. I'm having a little problem using your code. I extract frames from the downloaded ShanghaiTech dataset. And extracted the .npy file using your gen_patches.py script. Where should I use these .npy files in my code? I kindly ask for your guidance.

yangxcccscsa avatar Oct 26 '22 04:10 yangxcccscsa

@20220201yyds I met the same problem as you. How did you solve it? I would appreciate it if you could help me. FileNotFoundError: Caught FileNotFoundError in DataLoader worker process 0. Original Traceback (most recent call last): File "D:\ANACONDA\envs\torch\lib\site-packages\torch\utils\data_utils\worker.py", line 198, in worker_loop data = fetcher.fetch(index) File "D:\ANACONDA\envs\torch\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\ANACONDA\envs\torch\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\p_workspace\Jigsaw-VAD-main\Jigsaw-VAD-main\dataset.py", line 123, in getitem obj = self.get_object(record["video_name"], record["frame"], record["object"]) File "D:\p_workspace\Jigsaw-VAD-main\Jigsaw-VAD-main\dataset.py", line 152, in get_object obj = np.load(os.path.join(video_dir, str(frame) + '' + str(obj_id) + '.npy')) # (3, 7, 64, 64) File "D:\ANACONDA\envs\torch\lib\site-packages\numpy\lib\npyio.py", line 417, in load fid = stack.enter_context(open(os_fspath(file), "rb")) FileNotFoundError: [Errno 2] No such file or directory: 'shanghaitech\training\11_002\149_3.npy'

yqytomorrow avatar Apr 23 '23 02:04 yqytomorrow

@summersnowfish "shanghaitech_train_detect_result_yolov3.pkl" stores the frame-by-frame object detection results for STC by YOLOv3. You may first check if the number of extracted frames match the number of frame-level detection results for each video.

@gdwang08 Hello, thanks a lot for your great work. I would like to know how to generate shanghaitech_train_detect_result_yolov3.pkl? Or is there a code for generating .pkl for reference?

Smallwhite999 avatar May 12 '23 01:05 Smallwhite999