Upload 2 files
Browse files- app.py +1 -0
- pose_utils.py +23 -9
app.py
CHANGED
|
@@ -720,6 +720,7 @@ elif app_mode == 'Test Video Translation':
|
|
| 720 |
output_file = f"/tmp/techmatrix_output_{uuid.uuid4().hex}.{format_name}"
|
| 721 |
video_writer = None
|
| 722 |
weighted_predictions = {}
|
|
|
|
| 723 |
|
| 724 |
frame_idx = 0
|
| 725 |
|
|
|
|
| 720 |
output_file = f"/tmp/techmatrix_output_{uuid.uuid4().hex}.{format_name}"
|
| 721 |
video_writer = None
|
| 722 |
weighted_predictions = {}
|
| 723 |
+
frame_predictions = {} # Reset for each video session
|
| 724 |
|
| 725 |
frame_idx = 0
|
| 726 |
|
pose_utils.py
CHANGED
|
@@ -414,20 +414,34 @@ def create_bar_plot_visualization(image, predictions, title, orig_img):
|
|
| 414 |
title: Plot title
|
| 415 |
orig_img: Original image for sizing
|
| 416 |
"""
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
fig.canvas.draw()
|
| 428 |
|
| 429 |
# Convert plot to numpy array
|
| 430 |
plot_image = np.array(fig.canvas.renderer.buffer_rgba())[:, :, :3] # Remove alpha
|
|
|
|
| 431 |
|
| 432 |
# Combine image and plot vertically
|
| 433 |
combined_image = np.vstack((image, cv2.resize(plot_image, (image.shape[1], plot_image.shape[0]))))
|
|
|
|
| 414 |
title: Plot title
|
| 415 |
orig_img: Original image for sizing
|
| 416 |
"""
|
| 417 |
+
# Handle empty predictions case
|
| 418 |
+
if not predictions or len(predictions) == 0:
|
| 419 |
+
# Create a simple plot showing "No predictions available"
|
| 420 |
+
fig, ax = plt.subplots(figsize=(orig_img.shape[1]/100, orig_img.shape[0]/200), dpi=100)
|
| 421 |
+
ax.text(0.5, 0.5, 'No Predictions Available',
|
| 422 |
+
horizontalalignment='center', verticalalignment='center',
|
| 423 |
+
transform=ax.transAxes, fontsize=14)
|
| 424 |
+
ax.set_title(title)
|
| 425 |
+
ax.set_xlim(0, 1)
|
| 426 |
+
ax.set_ylim(0, 1)
|
| 427 |
+
ax.set_xticks([])
|
| 428 |
+
ax.set_yticks([])
|
| 429 |
+
else:
|
| 430 |
+
fig, ax = plt.subplots(figsize=(orig_img.shape[1]/100, orig_img.shape[0]/200), dpi=100)
|
| 431 |
+
plt.title(title)
|
| 432 |
+
|
| 433 |
+
# Create bar plot data
|
| 434 |
+
labels = list(predictions.keys())
|
| 435 |
+
probabilities = list(predictions.values())
|
| 436 |
|
| 437 |
+
# Create seaborn bar plot
|
| 438 |
+
sns.barplot(x=labels, y=probabilities, ax=ax)
|
| 439 |
+
|
| 440 |
fig.canvas.draw()
|
| 441 |
|
| 442 |
# Convert plot to numpy array
|
| 443 |
plot_image = np.array(fig.canvas.renderer.buffer_rgba())[:, :, :3] # Remove alpha
|
| 444 |
+
plt.close(fig) # Close to avoid memory leaks
|
| 445 |
|
| 446 |
# Combine image and plot vertically
|
| 447 |
combined_image = np.vstack((image, cv2.resize(plot_image, (image.shape[1], plot_image.shape[0]))))
|