reab5555 commited on
Commit
632f19a
·
verified ·
1 Parent(s): ab7a94a

Update visualization.py

Browse files
Files changed (1) hide show
  1. visualization.py +10 -12
visualization.py CHANGED
@@ -241,28 +241,26 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
241
  mse_voice = np.interp(np.linspace(0, len(mse_voice) - 1, total_frames),
242
  np.arange(len(mse_voice)), mse_voice)
243
 
 
244
  mse_embeddings_norm = (mse_embeddings - np.min(mse_embeddings)) / (np.max(mse_embeddings) - np.min(mse_embeddings))
245
  mse_posture_norm = (mse_posture - np.min(mse_posture)) / (np.max(mse_posture) - np.min(mse_posture))
246
  mse_voice_norm = (mse_voice - np.min(mse_voice)) / (np.max(mse_voice) - np.min(mse_voice))
247
 
248
- combined_mse = np.zeros((3, total_frames))
249
  combined_mse[0] = mse_embeddings_norm
250
  combined_mse[1] = mse_posture_norm
251
  combined_mse[2] = mse_voice_norm
252
 
 
253
  cdict = {
254
- 'red': [(0.0, 0.0, 0.0),
255
- (1.0, 1.0, 1.0)],
256
- 'green': [(0.0, 1.0, 1.0),
257
- (1.0, 0.0, 0.0)],
258
- 'blue': [(0.0, 1.0, 1.0),
259
- (1.0, 0.0, 0.0)]
260
  }
261
-
262
  custom_cmap = LinearSegmentedColormap('custom_cmap', segmentdata=cdict, N=256)
263
 
264
  fig, ax = plt.subplots(figsize=(width/100, 2))
265
- im = ax.imshow(combined_mse, aspect='auto', cmap=custom_cmap, extent=[0, total_frames, 0, 3])
266
  ax.set_yticks([0.5, 1.5, 2.5])
267
  ax.set_yticklabels(['Face', 'Posture', 'Voice'])
268
  ax.set_xticks([])
@@ -273,7 +271,7 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
273
 
274
  if hasattr(ax, 'line'):
275
  ax.lines.pop(0)
276
- ax.axvline(x=frame_count, color='r', linewidth=2)
277
 
278
  canvas = FigureCanvasAgg(fig)
279
  canvas.draw()
@@ -304,8 +302,8 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
304
  final_clip = VideoClip(combine_video_and_heatmap, duration=video.duration)
305
  final_clip = final_clip.set_audio(video.audio)
306
 
307
- # Write the final video
308
- final_clip.write_videofile(heatmap_video_path, codec='libx264', audio_codec='aac', fps=video.fps)
309
 
310
  # Close the video clips
311
  video.close()
 
241
  mse_voice = np.interp(np.linspace(0, len(mse_voice) - 1, total_frames),
242
  np.arange(len(mse_voice)), mse_voice)
243
 
244
+ # Normalize the MSE values
245
  mse_embeddings_norm = (mse_embeddings - np.min(mse_embeddings)) / (np.max(mse_embeddings) - np.min(mse_embeddings))
246
  mse_posture_norm = (mse_posture - np.min(mse_posture)) / (np.max(mse_posture) - np.min(mse_posture))
247
  mse_voice_norm = (mse_voice - np.min(mse_voice)) / (np.max(mse_voice) - np.min(mse_voice))
248
 
249
+ combined_mse = np.full((3, total_frames), np.nan)
250
  combined_mse[0] = mse_embeddings_norm
251
  combined_mse[1] = mse_posture_norm
252
  combined_mse[2] = mse_voice_norm
253
 
254
+ # Create custom colormap
255
  cdict = {
256
+ 'red': [(0.0, 0.5, 0.5), (1.0, 1.0, 1.0)],
257
+ 'green': [(0.0, 0.5, 0.5), (1.0, 0.0, 0.0)],
258
+ 'blue': [(0.0, 0.5, 0.5), (1.0, 0.0, 0.0)],
 
 
 
259
  }
 
260
  custom_cmap = LinearSegmentedColormap('custom_cmap', segmentdata=cdict, N=256)
261
 
262
  fig, ax = plt.subplots(figsize=(width/100, 2))
263
+ im = ax.imshow(combined_mse, aspect='auto', cmap=custom_cmap, extent=[0, total_frames, 0, 3], vmin=0, vmax=1)
264
  ax.set_yticks([0.5, 1.5, 2.5])
265
  ax.set_yticklabels(['Face', 'Posture', 'Voice'])
266
  ax.set_xticks([])
 
271
 
272
  if hasattr(ax, 'line'):
273
  ax.lines.pop(0)
274
+ ax.axvline(x=frame_count, color='blue', linewidth=2)
275
 
276
  canvas = FigureCanvasAgg(fig)
277
  canvas.draw()
 
302
  final_clip = VideoClip(combine_video_and_heatmap, duration=video.duration)
303
  final_clip = final_clip.set_audio(video.audio)
304
 
305
+ # Write the final video with progress bar
306
+ final_clip.write_videofile(heatmap_video_path, codec='libx264', audio_codec='aac', fps=video.fps, progress_bar=progress)
307
 
308
  # Close the video clips
309
  video.close()