bklynhlth / openwillis

Python library for digital measurement of health
Other
16 stars 8 forks source link

Emotional Expressivity NaN #152

Open joshwongg opened 1 day ago

joshwongg commented 1 day ago

Hi,

I've been trying to run the emotional expressivity function, however, all my results come up with "NaN". I've tested to see if the files open, as well as the video quality, and it is all fine. There is no error message that occurs when I am running the code either. I'm running the code below through miniconda.

import openwillis as ow
import tensorflow as tf
import pandas as pd

physical_devices = tf.config.list_physical_devices('GPU')
if physical_devices:
    tf.config.experimental.set_memory_growth(physical_devices[0], True)

filepath = r"C:\Users\jjsw972\OneDrive - The University of Newcastle\Desktop\joshtrialwatch.mp4"
baseline_filepath = r"C:\Users\jjsw972\OneDrive - The University of Newcastle\Desktop\joshtrialsuppress.mp4"

framewise, summary = ow.emotional_expressivity(
    filepath=filepath,
    baseline_filepath=baseline_filepath
)

print("Framewise:", framewise)
print("Summary:", summary)

if isinstance(framewise, pd.DataFrame):
    framewise.to_csv(r"C:\Users\jjsw972\OneDrive - The University of Newcastle\Desktop\Framewise_Emotional_Expressitivity.csv", index=False)
if isinstance(summary, pd.DataFrame):
    summary.to_csv(r"C:\Users\jjsw972\OneDrive - The University of Newcastle\Desktop\Summary_Emotional_Expressitivity.csv", index=False)

Any help is greatly appreciated! Thanks :)

GeorgeEfstathiadis commented 1 day ago

When running the code if an error occurred you should see an error message starting with 'Error in facial emotion calculation...'. The fact that you don't suggests that maybe the machine running it quits for some reason which is harder to debug; do you find that to be the case? You could check it by running the code in Python line-by-line and see if it exits Python or the terminal when running the emotional_expressivity function.

Additionally you can try this code, to ensure the issue doesn't come from Deepface running it on a single frame of your video:

import cv2
import pandas as pd
from deepface import DeepFace

cap = cv2.VideoCapture(filepath)
ret, img = cap.read()

if not ret:
    raise ValueError("Error: Couldn't read the video.")

img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

face_analysis = DeepFace.analyze(img_path=img_rgb, actions=['emotion'])
emotions = face_analysis[0]['emotion']

print(face_analysis)
print(emotions)