Spaces:
Sleeping
Sleeping
File size: 1,216 Bytes
68f9b9e 9b06d51 68f9b9e 9b06d51 68f9b9e 9b06d51 b197185 9b06d51 68f9b9e 9b06d51 68f9b9e 9b06d51 68f9b9e 9b06d51 68f9b9e 9b06d51 68f9b9e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import os
import sys
from types import ModuleType
# Set Keras backend to torch
os.environ["KERAS_BACKEND"] = "torch"
import keras
import cv2
import numpy as np
# Monkey-patch tensorflow.keras for fer
tf = ModuleType("tensorflow")
sys.modules["tensorflow"] = tf
sys.modules["tensorflow.keras"] = keras
tf.keras = keras
import keras.models
import keras.layers
sys.modules["tensorflow.keras.models"] = keras.models
sys.modules["tensorflow.keras.layers"] = keras.layers
tf.keras.models = keras.models
tf.keras.layers = keras.layers
from fer import FER
def test_fer():
try:
print("Initializing FER detector (with torch backend patch)...")
detector = FER(mtcnn=False)
# Create a blank image
img = np.zeros((100, 100, 3), dtype=np.uint8)
# Add a white circle
cv2.circle(img, (50, 50), 30, (255, 255, 255), -1)
print("Testing FER detector...")
emotions = detector.detect_emotions(img)
print(f"Result: {emotions}")
print("SUCCESS: FER is working with torch backend!")
except Exception as e:
print(f"FER error: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
test_fer()
|