reab5555 commited on
Commit
71c6d95
·
verified ·
1 Parent(s): 62cd847

Update visualization.py

Browse files
Files changed (1) hide show
  1. visualization.py +13 -1
visualization.py CHANGED
@@ -9,6 +9,7 @@ import cv2
9
  from matplotlib.patches import Rectangle
10
  from utils import seconds_to_timecode
11
  from anomaly_detection import determine_anomalies
 
12
  import gradio as gr
13
 
14
  def plot_mse(df, mse_values, title, color='navy', time_threshold=3, anomaly_threshold=4):
@@ -209,7 +210,18 @@ def plot_posture(df, posture_scores, color='blue', anomaly_threshold=3):
209
 
210
  def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_voice, output_path, desired_fps, largest_cluster):
211
  # Filter the DataFrame to only include frames from the largest cluster
212
- df_largest_cluster = df[df['Cluster'] == largest_cluster]
 
 
 
 
 
 
 
 
 
 
 
213
  mse_embeddings = mse_embeddings[df['Cluster'] == largest_cluster]
214
  mse_posture = mse_posture[df['Cluster'] == largest_cluster]
215
  mse_voice = mse_voice[df['Cluster'] == largest_cluster]
 
9
  from matplotlib.patches import Rectangle
10
  from utils import seconds_to_timecode
11
  from anomaly_detection import determine_anomalies
12
+ from scipy import interpolate
13
  import gradio as gr
14
 
15
  def plot_mse(df, mse_values, title, color='navy', time_threshold=3, anomaly_threshold=4):
 
210
 
211
  def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_voice, output_path, desired_fps, largest_cluster):
212
  # Filter the DataFrame to only include frames from the largest cluster
213
+ df_largest_cluster = df[df['Cluster'] == largest_cluster]
214
+
215
+ # Interpolate mse_voice to match the length of df
216
+ x_voice = np.linspace(0, len(mse_voice)-1, len(mse_voice))
217
+ x_new = np.linspace(0, len(mse_voice)-1, len(df))
218
+ f = interpolate.interp1d(x_voice, mse_voice)
219
+ mse_voice_interpolated = f(x_new)
220
+
221
+ mse_embeddings = mse_embeddings[df['Cluster'] == largest_cluster]
222
+ mse_posture = mse_posture[df['Cluster'] == largest_cluster]
223
+ mse_voice = mse_voice_interpolated[df['Cluster'] == largest_cluster]
224
+
225
  mse_embeddings = mse_embeddings[df['Cluster'] == largest_cluster]
226
  mse_posture = mse_posture[df['Cluster'] == largest_cluster]
227
  mse_voice = mse_voice[df['Cluster'] == largest_cluster]