EurekaPotato commited on
Commit
0eaa475
·
verified ·
1 Parent(s): 4e33549

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. handler.py +19 -10
  2. requirements.txt +1 -0
handler.py CHANGED
@@ -64,16 +64,25 @@ class EmotionCNN:
64
  from skimage.transform import resize
65
  mel_resized = resize(mel_spec_norm, (224, 224), mode="constant")
66
  except ImportError:
67
- # Fallback: simple nearest-neighbor resize with numpy
68
- mel_resized = np.array(
69
- [np.interp(np.linspace(0, mel_spec_norm.shape[1]-1, 224),
70
- np.arange(mel_spec_norm.shape[1]), row)
71
- for row in np.interp(
72
- np.linspace(0, mel_spec_norm.shape[0]-1, 224),
73
- np.arange(mel_spec_norm.shape[0]),
74
- np.arange(mel_spec_norm.shape[0])
75
- ).astype(int).__iter__()]
76
- ) if mel_spec_norm.size > 0 else np.zeros((224, 224))
 
 
 
 
 
 
 
 
 
77
 
78
  try:
79
  from matplotlib import cm
 
64
  from skimage.transform import resize
65
  mel_resized = resize(mel_spec_norm, (224, 224), mode="constant")
66
  except ImportError:
67
+ # Fallback: resizing with numpy interpolation (nearest neighbor for rows, linear for cols)
68
+ target_h, target_w = 224, 224
69
+ source_h, source_w = mel_spec_norm.shape
70
+
71
+ if source_h > 0 and source_w > 0:
72
+ # 1. Resize height (rows)
73
+ row_indices = np.linspace(0, source_h - 1, target_h).astype(int)
74
+ # Select rows (nearest neighbor)
75
+ temp = mel_spec_norm[row_indices, :]
76
+
77
+ # 2. Resize width (cols)
78
+ mel_resized = np.zeros((target_h, target_w), dtype=mel_spec_norm.dtype)
79
+ x_source = np.arange(source_w)
80
+ x_target = np.linspace(0, source_w - 1, target_w)
81
+
82
+ for i in range(target_h):
83
+ mel_resized[i, :] = np.interp(x_target, x_source, temp[i, :])
84
+ else:
85
+ mel_resized = np.zeros((224, 224))
86
 
87
  try:
88
  from matplotlib import cm
requirements.txt CHANGED
@@ -15,3 +15,4 @@ fastapi==0.95.2
15
  uvicorn==0.22.0
16
  python-multipart==0.0.6
17
  huggingface_hub>=0.19.0
 
 
15
  uvicorn==0.22.0
16
  python-multipart==0.0.6
17
  huggingface_hub>=0.19.0
18
+ scikit-image>=0.21.0