Face_Attention_Network icon indicating copy to clipboard operation
Face_Attention_Network copied to clipboard

How to test a self trained model?

Open bestpower opened this issue 6 years ago • 10 comments

According to the readme, I have trained a model and got a new model file *.pt, but in this project I didn't find the codes to test the model. I tried to input a image into the model and output some errors. So can you provide an example code to test the self trained model?

bestpower avatar Aug 16 '19 08:08 bestpower

Hello, for testing call evaluate method from csv_eval.py. For detection look at my detector script: https://github.com/rainofmine/Face_Attention_Network/pull/8/files#diff-b59bb88a6684acf7d00c6dc58b3a41cc

ehp avatar Aug 16 '19 12:08 ehp

Thank you for your answer. I used the detector script, and input my parameters, but it always run error: "Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #2 'other", I have transfer the model and image into the cuda type, but the error happened still, how to solve it?

bestpower avatar Aug 19 '19 08:08 bestpower

My running Env: ubuntu 16.04 python 3.5.2 pytorch 0.4.1 torchvision 0.2.0 cuda 9.2 cudnn 7.4.2

bestpower avatar Aug 19 '19 08:08 bestpower

  1. try your model with my fork https://github.com/ehp/Face_Attention_Network (see https://github.com/rainofmine/Face_Attention_Network/pull/8 what is different)
  2. post full stacktrace, not only error message

ehp avatar Aug 19 '19 17:08 ehp

I have solved it, In detector.py script: 1、I tried to modify 35st line to "scores = scores.cpu().numpy()" and 37st line to "boxes = boxes.cpu().numpy() / scale". 2、About model cuda type, I tried to modify 61st line to "model = model.to(torch.device('cuda'))" After the three lines modifies above, the script could run normally. Thank you!

bestpower avatar Aug 20 '19 06:08 bestpower

@bestpower I have the same problem but what you've did doesn't work for me.

@ehp also I tried to use your fork to train the model but I get the same error:

Traceback (most recent call last):
  File "train.py", line 218, in <module>
    main()
  File "train.py", line 161, in main
    classification_loss, regression_loss, mask_loss = retinanet([img_data, annot_data])
  File "/home/vlad/Projects/Face_Attention_Network/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/vlad/Projects/Face_Attention_Network/venv/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 121, in forward
    return self.module(*inputs[0], **kwargs[0])
  File "/home/vlad/Projects/Face_Attention_Network/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/vlad/Projects/Face_Attention_Network/model_level_attention.py", line 310, in forward
    clc_loss, reg_loss = self.focalLoss(classification, regression, anchors, annotations)
  File "/home/vlad/Projects/Face_Attention_Network/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/vlad/Projects/Face_Attention_Network/losses.py", line 166, in forward
    targets = targets / torch.Tensor([[0.1, 0.1, 0.2, 0.2]])
RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #2 'other'

Do you know why this happens?

vladoski avatar Apr 24 '20 13:04 vladoski

Hello, one tensor is in gpu memory and second in ram (for cpu). Fix is easy - append .cpu() to tensor on line 166 and maybe also to stack on line 163 in losses.py.

ehp avatar Apr 24 '20 15:04 ehp

@ehp okay, so doing .cpu() moves the tensor in ram. But doing that means that I'm not able to train the model on the GPU right?

vladoski avatar Apr 25 '20 12:04 vladoski

I dont understand your question - something is computed on cpu but the main training is done on gpu. Just look at the code.

ehp avatar Apr 26 '20 07:04 ehp

Hi, @rainofmine @ehP How to run and use and csv_eval.py to get the evaluation mAP for a test dataset??

raha-2020 avatar May 13 '20 09:05 raha-2020