Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing the trained models #9

Open
AbdulMoqeet opened this issue May 17, 2021 · 34 comments
Open

Testing the trained models #9

AbdulMoqeet opened this issue May 17, 2021 · 34 comments

Comments

@AbdulMoqeet
Copy link

Hello,

Thank you for sharing the code.

Once the network is trained using train.py, how to test the model?

Regards,
AM

@carolchenyx
Copy link

@AbdulMoqeet Dear AbdulMoqeet, I would like to ask a question about train.py. When I ran it , this line of the code(
torch.autograd.grad(dis_validation_loss, discriminator.parameters())) will raise the error({RuntimeError}invalid gradient at index 0 - got [1] but expected shape compatible with [1, 1]). Do you know how to fix it? Thank you.

@AbdulMoqeet
Copy link
Author

@carolchenyx I checked my code but couldn't get hint. I was facing similar errors but don't remember how I fixed them though.

Did you make any changes in the code? How's your data directory look like?

@carolchenyx
Copy link

@AbdulMoqeet I changed a little bit about the data process. The data directory is like (/media/hkuit104/24d4ed16-ee67-4121-8359-66a09cede5e7/AbnormalDetection/DATASET/SHT/testing/frames/).

@AbdulMoqeet
Copy link
Author

AbdulMoqeet commented Jun 10, 2021

It may be a problem of data loading.. My directory looks like videos\frames\08\08_003 where 08 is the Task number and '08_003' is video number. I am giving 'videos\frames' as an input.

@carolchenyx
Copy link

@AbdulMoqeet Oh, I see. Let me try it first. Super thanks for you quick reply.

@carolchenyx
Copy link

@AbdulMoqeet Dear AM, it seems will raise the same problem. I pushed the code I used in (https://github.com/carolchenyx/Few-shot-Scene-adaptive-Anomaly-Detection). I will be very grateful if you can help to check it. Thank you.
Traceback (most recent call last):
File "/media/hkuit104/24d4ed16-ee67-4121-8359-66a09cede5e7/AbnormalDetection/Few-shot-Scene-adaptive-Anomaly-Detection/train.py", line 269, in
main(k_shots, num_tasks, adam_betas, gen_lr, dis_lr, total_epochs, model_folder_path)
File "/media/hkuit104/24d4ed16-ee67-4121-8359-66a09cede5e7/AbnormalDetection/Few-shot-Scene-adaptive-Anomaly-Detection/train.py", line 199, in main
gen_grads = torch.autograd.grad(gen_validation_loss, generator.parameters())
File "/home/hkuit104/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/autograd/init.py", line 225, in grad
inputs, allow_unused, accumulate_grad=False)
RuntimeError: invalid gradient at index 0 - got [1] but expected shape compatible with [1, 1]

@AbdulMoqeet
Copy link
Author

@carolchenyx Added a pull request for working code. Changes are made in your code. Have fun!

@carolchenyx
Copy link

@AbdulMoqeet Great! Super thanks again.

@abhishekaich27
Copy link

abhishekaich27 commented Jun 27, 2021

@AbdulMoqeet @carolchenyx Can you share the folder structure of training videos? I have extracted the frames under folder name of videos. Below is the structure I have. Is this correct?

|- Training
    |-frames
         |- 01_001
         |- 01_002
         |- 01_003

This is the structure of the training videos (which by default in Shanghai-Tech, doesn't provide anomalies in training set.)

@AbdulMoqeet
Copy link
Author

@abhishekaich27 Yes, but that default structure didn't work for me. I had to change the directories structure.

My directory looks like \Training\frames\08\08_003*.jpg where 08 is the Task number, '08_003' is video number and *.jpg represent the video frames.

Let me know if the problem still persists.

@abhishekaich27
Copy link

Exactly @AbdulMoqeet. Does the Task number has some relation with Video number? e.g. 08 of 08_003? These first two digits have some particular meaning?

@AbdulMoqeet
Copy link
Author

Yes, all of the videos started from same numbers (e.g. 08 in 08_003) should be in the same folder named as 08.

Those particular two digits refer to task/scene number.

For Task 8:
\Training\frames\08\08_001\*.jpg
\Training\frames\08\08_002\*.jpg

For Task 7:
\Training\frames\07\07_001\*.jpg
\Training\frames\07\07_002\*.jpg

@abhishekaich27
Copy link

abhishekaich27 commented Jun 28, 2021

Thank you! I will restructure the folders this way then.

Do you think this is the new train-test split authors propose in the paper? Were you able to reproduce the results of the paper for the Shanghai-Tech dataset?

@AbdulMoqeet
Copy link
Author

I am not sure. I had to do reverse engineering to make this code work. So, by tracing the errors and codes, I came to that directory structure.

I never meant to reproduce the quantitative results. However, I check some of qualitative results, there were positive results that ensure that code is working fine. I had to use this code for some other industrial application (for experimental purpose) that I am working on.

@abhishekaich27
Copy link

Alright. I have emailed the authors regarding this dataset's training/testing split and one of the authors has replied to get back to me in a while. I will update here if I get anything concrete.

Thank you again for your kind help.

@abhishekaich27
Copy link

@AbdulMoqeet The author of the repo confirmed that the folder structure you have is correct.

@AbdulMoqeet
Copy link
Author

@abhishekaich27 Thanks a lot for the confirmation.

@BenedictGreen
Copy link

@AbdulMoqeet Hi, AbdulMoqeet. Thanks a lot for your conversation, my 'train.py' code is already running. Have you solved the problem of how to test the model?

@zugexiaodui
Copy link

Same question

@accountyangaaa
Copy link

@AbdulMoqeet Dear AbdulMoqeet, I would like to ask a question about train.py. When I ran it , this line of the code(
main(k_shots, num_tasks, adam_betas, gen_lr, dis_lr, total_epochs, model_folder_path) will raise the error(TypeError: add(): argument 'other' (position 1) must be Tensor, not BCELoss). Do you know how to fix it? Thank you.
Can you share your environment requirement?Thank you.

@AbdulMoqeet
Copy link
Author

@accountyangaaa Could you please run with default arguments? I have also shared a working code above. Check my answer to @carolchenyx Please share a screenshot.

@accountyangaaa
Copy link

@AbdulMoqeet Dear AbdulMoqeet, thanks a lot for your reply. I just ran the working code above. There is another error.
RuntimeError: CUDA out of memory. Tried to allocate 32.00 MiB (GPU 0; 4.00 GiB total capacity; 3.19 GiB already allocated; 0 bytes free; 28.04 MiB cached)
Do you know how to fix it? Thank you.
result

@carolchenyx
Copy link

carolchenyx commented Nov 23, 2021 via email

@accountyangaaa
Copy link

@carolchenyx Thanks a lot for your reply. Can I see your dataset structure

@accountyangaaa
Copy link

@carolchenyx Hi,below is the structure I have. Is this correct?
res

@carolchenyx
Copy link

@carolchenyx Hi,below is the structure I have. Is this correct? res

Hi, I think it's correct.

@dekathomas
Copy link

dekathomas commented Feb 16, 2022

Hello @AbdulMoqeet @carolchenyx, where do you know the version list of the dependencies? Have you got information to test the trained model? Thank you

@AbdulMoqeet
Copy link
Author

@dekathomas I did by trial & error.

For testing, I made changes in the given code by following the paper. You can modify the train code accordingly. I tested on my private dataset at that time and, the results were unsatisfactory.

@dekathomas
Copy link

Can you share to me the testing code you have made?

@AbdulMoqeet
Copy link
Author

Sorry, I am not allowed to do so :-(

@dekathomas
Copy link

Owh oke, no problem

@lzyuan168
Copy link

@AbdulMoqeet Hi are you able to provide a skeleton code for the test.py file without the sensitive information. Thanks

@AbdulMoqeet
Copy link
Author

@lzyuan168 Hi, I am sorry, I do not have access to those files anymore.

As it's been long time so I do not even remember about them. If I remember correctly, I used train file/conditions to set conditions in test file

@lzyuan168
Copy link

@AbdulMoqeet alright thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants