#๐Ÿ”’ Why am i getting incorrect readings from the model Trained Model, code error or bad model?

6 messages ยท Page 1 of 1 (latest)

quick imp
#

So im trying to implement a pre-trained model for arousal and valence, this is the model
https://github.com/face-analysis/emonet

model = EmoNet(n_expression=5)  
state_dict = torch.load('emonet\pretrained\emonet_5.pth', map_location='cpu')
model.load_state_dict(state_dict)
model.eval()

transform = transforms.Compose(#Simply transforming to tensor)

def preprocess_frame(frame):
   frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
   image = Image.fromarray(frame)
   image = transform(image).unsqueeze(0)
   return image

def analyze_emotion(frame):
   preprocessed_frame = preprocess_frame(frame)
   with torch.no_grad():
       output = model(preprocessed_frame)

       
       valence = output['valence'].item()
       arousal = output['arousal'].item()
       emotion_scores = output['expression'].squeeze(0)

       
       print(f'Raw valence: {output["valence"].item()}, Raw arousal: {output["arousal"].item()}')
       print(f'Emotion scores: {emotion_scores}')

       emotion = emotion_scores.argmax().item()
       print(f'Predicted Emotion: {emotion_labels[emotion]} (Index: {emotion})')

   return valence, arousal, emotion


emotion_labels = ["Neutral", "Happy", "Sad", "Surprise", "Fear"] 

# Emotion Plot
def setup_emotion_plot(ax):
   #Character waste


video_source = 0   
cap = cv2.VideoCapture(video_source)

if not cap.isOpened():
   print("Error: Could not open video source.")
   exit()


fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))


point = setup_emotion_plot(ax2)


plt.ion()   
while True:
   ret, frame = cap.read()
   if not ret:
       break

   valence, arousal, emotion = analyze_emotion(frame)

   
 
   update_emotion_plot(point, valence, arousal)

   
   frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)


   ax1.clear()
   ax1.imshow(frame_rgb)
   ax1.axis('off')

   fig.canvas.draw()
   plt.pause(0.001)

  
   if plt.waitforbuttonpress(timeout=0.001):
       break

cap.release()
plt.close()
GitHub

Official implementation of the paper "Estimation of continuous valence and arousal levels from faces in naturalistic conditions", Antoine Toisoul, Jean Kossaifi, Adrian Bulat, Geo...

red ploverBOT
#

@quick imp

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

quick imp
#

Somehow im always getting the same emotion and values revolving the same stuff

#

I can make whatever face and ill prolly end up with same result, emotion always happy

red ploverBOT
#

@quick imp

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.