Hi team!
While setting up the project locally to test the emotion detection pipeline, I audited the mvp.py script and the dependency tree. I noticed two areas where we can significantly improve local stability and hardware utilization.
Problem 1: MVP Pipeline Crash (ZeroDivisionError)
The mvp.py script is a great standalone tool for local testing without Firebase credentials. However, it currently lacks a safety net for edge cases. If cv2.VideoCapture fails to process any frames (e.g., the video file is missing, corrupted, or no faces are detected), the predictions array remains empty ([]).
When this empty array is passed to getPercentages(), the script crashes hard on line 60 because it attempts to divide by len(predictions) (which is 0):
'Angry': round((emotionCountMap["Angry"] / len(predictions) * 100), 2) # ZeroDivisionError
Additionally, main() accepts a video_path argument, but hardcodes video = cv2.VideoCapture("fv.mp4") internally, breaking dynamic video loading.
Problem 2: Hardware Utilization Bottleneck
Currently, the project strictly requires tensorflow-cpu = "^2.18.0" in both pyproject.toml and the Environment section of the README.md. This entirely locks out users with CUDA-enabled hardware from utilizing GPU acceleration, artificially slowing down local emotion analysis.
Proposed Solution
I have a local branch ready that addresses both issues simultaneously:
1. Pipeline Stability (mvp.py):
• Wired the dynamic video_path argument directly into the cv2.VideoCapture() call.
• Introduced an early-exit guard clause in getPercentages() to handle empty predictions safely:
if not predictions:
print("No predictions generated. Returning empty percentages.")
return {}
2. Hardware Optimization (pyproject.toml & README.md):
• Swapped tensorflow-cpu for the standard tensorflow package. The standard package natively utilizes GPUs if available, and automatically falls back to CPU if no GPU is found, making it strictly superior and universally compatible.
• Updated the README.md Environment section to reflect the removal of the CPU-only restriction.
Benefits
• Zero-Crash Local Testing: Developers can test edge-case videos (no faces, corrupt files) without crashing the Python process.
• Massive Speed Boost: Users with dedicated GPUs will see significantly faster frame inference times.
• Fully Backward Compatible: CPU-only users will experience no change in behavior due to TensorFlow's native fallback mechanism.
If this aligns with the project's development goals, please let me know if I have the green light to go ahead and open the PR!
cc: @jvJUCA @marcgc21 @KarinePistili
Hi team!
While setting up the project locally to test the emotion detection pipeline, I audited the
mvp.pyscript and the dependency tree. I noticed two areas where we can significantly improve local stability and hardware utilization.Problem 1: MVP Pipeline Crash (
ZeroDivisionError)The
mvp.pyscript is a great standalone tool for local testing without Firebase credentials. However, it currently lacks a safety net for edge cases. Ifcv2.VideoCapturefails to process any frames (e.g., the video file is missing, corrupted, or no faces are detected), thepredictionsarray remains empty ([]).When this empty array is passed to
getPercentages(), the script crashes hard on line 60 because it attempts to divide bylen(predictions)(which is 0):Additionally,
main()accepts avideo_pathargument, but hardcodesvideo = cv2.VideoCapture("fv.mp4")internally, breaking dynamic video loading.Problem 2: Hardware Utilization Bottleneck
Currently, the project strictly requires
tensorflow-cpu = "^2.18.0"in bothpyproject.tomland the Environment section of theREADME.md. This entirely locks out users with CUDA-enabled hardware from utilizing GPU acceleration, artificially slowing down local emotion analysis.Proposed Solution
I have a local branch ready that addresses both issues simultaneously:
1. Pipeline Stability (
mvp.py):• Wired the dynamic
video_pathargument directly into thecv2.VideoCapture()call.• Introduced an early-exit guard clause in
getPercentages()to handle empty predictions safely:2. Hardware Optimization (
pyproject.toml&README.md):• Swapped
tensorflow-cpufor the standardtensorflowpackage. The standard package natively utilizes GPUs if available, and automatically falls back to CPU if no GPU is found, making it strictly superior and universally compatible.• Updated the
README.mdEnvironment section to reflect the removal of the CPU-only restriction.Benefits
• Zero-Crash Local Testing: Developers can test edge-case videos (no faces, corrupt files) without crashing the Python process.
• Massive Speed Boost: Users with dedicated GPUs will see significantly faster frame inference times.
• Fully Backward Compatible: CPU-only users will experience no change in behavior due to TensorFlow's native fallback mechanism.
If this aligns with the project's development goals, please let me know if I have the green light to go ahead and open the PR!
cc: @jvJUCA @marcgc21 @KarinePistili