rainofmine / Face_Attention_Network

Pytorch implementation of face attention network
315 stars 55 forks source link

How to test a self trained model? #9

Open bestpower opened 5 years ago

bestpower commented 5 years ago

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?

ehp commented 5 years ago

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

bestpower commented 5 years ago

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 commented 5 years ago

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

ehp commented 5 years ago
  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
bestpower commented 5 years ago

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!

vladoski commented 4 years ago

@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?

ehp commented 4 years ago

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.

vladoski commented 4 years ago

@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?

ehp commented 4 years ago

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

raha-2020 commented 4 years ago

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