EfficientNet-PyTorch icon indicating copy to clipboard operation
EfficientNet-PyTorch copied to clipboard

Test with single image gives different result in each runtime

Open gihunsong opened this issue 3 years ago • 9 comments

Hi all,

I pretrained myself using EfficientNet B0 with 5 classes, and..

Now I have been loaded using below code:

model = EfficientNet.from_pretrained('efficientnet-b0', weight_path = './weights_path/model.pt', num_classess=5) and i'm using model.eval(), and with torch.no_grad() also.

In a single test phase, i tried two times inference using below code:

outputs = model(inputs) print(outputs) outputs = model(inputs) print(outputs) both outputs printing gives same result but,

If i run again, it gives different result.

Maybe i'm missing something in weight loading part but I couldn't get guess easily.

Please help me, regards.

gihunsong avatar Sep 30 '21 06:09 gihunsong

running on cpu and gpu also gives same situation..

gihunsong avatar Sep 30 '21 07:09 gihunsong

It seems like, setting seeds give same result for each time, but i'm trying to use same input (single image) so.. it's not understandable..

gihunsong avatar Sep 30 '21 07:09 gihunsong

@gihunsong Even I am facing the same issue.

rkakash59 avatar Oct 01 '21 07:10 rkakash59

@gihunsong you can try : model = EfficientNet.from_name('efficientnet-b0', num_classes=5) model.load_state_dict(weights_path)

rkakash59 avatar Oct 01 '21 07:10 rkakash59

@gihunsong you can try : model = EfficientNet.from_name('efficientnet-b0', num_classes=5) model.load_state_dict(weights_path)

@rkakash59 do you mean that you solved the problem that i mentiond using your suggestion?

gihunsong avatar Oct 01 '21 07:10 gihunsong

@gihunsong that was a suggestion.

I missed model.eval() during inference so l was getting inconsistent results. Now I am getting consistent results.

rkakash59 avatar Oct 02 '21 06:10 rkakash59

@gihunsong that was a suggestion.

I missed model.eval() during inference so l was getting inconsistent results. Now I am getting consistent results.

@rkakash59 Thanks for your reply.

Could you share your a .py file that you have been using model.eval() part? It'll be helpful for me..

Because I am also using model.eval() in inference but it gives different result every time when i load model and do inference.

gihunsong avatar Oct 02 '21 09:10 gihunsong

@rkakash59 I'm still struggling in this issue.

you suggested the below code: model = EfficientNet.from_name('efficientnet-b0', num_classes=5) model.load_state_dict(weights_path)

could you share your code more in detail upper part of your suggested code?

gihunsong avatar Oct 21 '21 03:10 gihunsong

So weird that no one can explain this issue. My code worked normally with 2 classes but It had problem with 5 classes

ndcuong91 avatar Jul 08 '22 07:07 ndcuong91