av-savchenko / face-emotion-recognition

Efficient face emotion recognition in photos and videos
Apache License 2.0
687 stars 127 forks source link

AttributeError: 'EfficientNet' object has no attribute 'act1' #23

Closed JimReno closed 2 years ago

JimReno commented 2 years ago

Thank you chenko for the great work! I tried to use effifientNet model to predict facial emotions. I used code from test_hsemotion_package.ipynb. I downloaded the xx.pt file from the models folder and load it from a local directory. The model loaded well. But an error occurs when executing fer.predict_emotions(frame,logits=True) Here is my code.

import os
import numpy as np
import matplotlib.pyplot as plt
import cv2
from PIL import Image
import torch
from hsemotion.facial_emotions import HSEmotionRecognizer

import torch

use_cuda = torch.cuda.is_available()
device = 'cuda' if use_cuda else 'cpu'

model_path='../models/affectnet_emotions/enet_b2_8_best.pt'

fer=HSEmotionRecognizer(model_name=model_path,device=device)
# model = torch.load(model_path, map_location=torch.device('cpu'))

fpath='../test_images/0_alamy_adoration_emotion_2_22.jpg'
frame_bgr = cv2.imread(fpath)
plt.figure(figsize=(5, 5))
frame = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
plt.axis('off')
plt.imshow(frame)

emotion, scores=fer.predict_emotions(frame,logits=True)
plt.figure(figsize=(3, 3))
plt.axis('off')
plt.imshow(frame)
plt.title(emotion)

The error is:

raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'EfficientNet' object has no attribute 'act1'

My timm version is 0.4.5. Any idea on how to solve this issue?

sunggukcha commented 2 years ago

15

The issue above may help you.

Regards, Sungguk Cha

JimReno commented 2 years ago

15 The issue above may help you.

Regards, Sungguk Cha

Thank you gukcha for the lighting speed reply. I have installed timm==0.6.7. Sine this issue has been solved. I will close this issue.