av-savchenko / face-emotion-recognition

Efficient face emotion recognition in photos and videos
Apache License 2.0
654 stars 124 forks source link

QUestion about inference #3

Closed DaddyWesker closed 3 years ago

DaddyWesker commented 3 years ago

Hello.

THanks for your code. I've tried to run your code on webcam and for that i've needed to load model properly from pretrained weights. I've took a look into your train_emotions-pytorch and sought that you're loading model as

model=timm.create_model('tf_efficientnet_b0_ns', pretrained=False)
model.classifier=torch.nn.Identity()
model.load_state_dict(torch.load('../models/pretrained_faces/state_vggface2_enet0_new.pt'))

Then you're adding model.classifier=nn.Sequential(nn.Linear(in_features=1280, out_features=num_classes)) and training your model. If i got it right, you're providing pre-trained weights at the models/affectnet_emotions folder. But question is, how to load them? I've thought it should be something like this

model=timm.create_model('tf_efficientnet_b0_ns', pretrained=False)
model.classifier=nn.Sequential(nn.Linear(in_features=1280, out_features=8))
model.load_state_dict(torch.load('../models/affectnet_emotions/enet_b0_8_best_afew.pt'))

But no, i've got an error. AttributeError: 'EfficientNet' object has no attribute 'copy'. So my guess is wrong then. Should i load it some different way? THanks in advance.

av-savchenko commented 3 years ago

You do not need to create emotion model from scratch. Please try to load the whole model using the following code model = torch.load('../models/affectnet_emotions/enet_b0_8_best_afew.pt') model.eval()

There is an example in file train_emotions-pytorch.ipynb, where similar code is used but variable PATH is used

вт, 3 авг. 2021 г., 10:42 DaddyWesker @.***>:

Hello.

THanks for your code. I've tried to run your code on webcam and for that i've needed to load model properly from pretrained weights. I've took a look into your train_emotions-pytorch and sought that you're loading model as

model=timm.create_model('tf_efficientnet_b0_ns', pretrained=False) model.classifier=torch.nn.Identity() model.load_state_dict(torch.load('../models/pretrained_faces/state_vggface2_enet0_new.pt'))

Then you're adding model.classifier=nn.Sequential(nn.Linear(in_features=1280, out_features=num_classes)) and training your model. If i got it right, you're providing pre-trained weights at the models/affectnet_emotions folder. But question is, how to load them? I've thought it should be something like this

model=timm.create_model('tf_efficientnet_b0_ns', pretrained=False) model.classifier=nn.Sequential(nn.Linear(in_features=1280, out_features=8)) model.load_state_dict(torch.load('../models/affectnet_emotions/enet_b0_8_best_afew.pt'))

But no, i've got an error. AttributeError: 'EfficientNet' object has no attribute 'copy'. So my guess is wrong then. Should i load it some different way? THanks in advance.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/HSE-asavchenko/face-emotion-recognition/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFZQMVH6WDWUGIQF3UNJXKLT26MURANCNFSM5BOIGCHQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

DaddyWesker commented 3 years ago

Hm. THanks. It works. Strange, i thought it won't work without model class with just "torch.load". But i guess i won't comply about that =)