ntsc207 commited on
Commit
86b060d
·
verified ·
1 Parent(s): 76c31e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -10
app.py CHANGED
@@ -11,6 +11,7 @@ import cv2
11
  import numpy as np
12
  import matplotlib.pyplot as plt
13
  import threading
 
14
 
15
  should_continue = True
16
 
@@ -107,33 +108,62 @@ def yolov9_inference(model_id, img_path=None, vid_path=None, tracking_algorithm
107
  plt.tight_layout() # Ensure the entire plot fits into the figure area
108
  #ax.set_facecolor('#D3D3D3')
109
  elif output_extension.lower() in vid_extensions:
110
- output_video = output_path # Load the video file here
111
  output_image = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  plt.style.use("ggplot")
113
  fig, ax = plt.subplots(figsize=(10, 6))
114
- #for label in labels:
115
- #df_label = frame_counts_df[frame_counts_df['label'] == label]
116
- sns.lineplot(ax = ax, data = frame_counts_df, x = 'frame', y = 'count', hue = 'label', palette=palette,linewidth=2.5)
117
-
118
  ax.set_title('Count of Labels over Frames', fontsize=20, pad=20) # Increase padding for the title
119
  ax.set_xlabel('Frame', fontsize=16) # Increase font size
120
  ax.set_ylabel('Count', fontsize=16) # Increase font size
121
  ax.tick_params(axis='x', labelsize=12) # Increase label size for x-axis
122
  ax.tick_params(axis='y', labelsize=12) # Increase label size for y-axis
123
-
124
  # Add grid but make it lighter and put it behind bars
125
  ax.grid(True, linestyle=':', linewidth=0.6, color='gray', alpha=0.6)
126
  ax.set_axisbelow(True)
127
-
128
  # Change the background color to a lighter shade
129
  ax.set_facecolor('#F0F0F0')
130
-
131
  # Add a legend with a smaller font size
132
  ax.legend(fontsize=10)
133
-
134
- plt.tight_layout() # Ensure the entire
 
 
135
  return output_image, output_video, fig
136
 
 
137
  def app():
138
  img = Image.open('./img_examples/classes.png')
139
  img = img.resize((410, 260), Image.Resampling.LANCZOS)
 
11
  import numpy as np
12
  import matplotlib.pyplot as plt
13
  import threading
14
+ from scipy.interpolate import make_interp_spline
15
 
16
  should_continue = True
17
 
 
108
  plt.tight_layout() # Ensure the entire plot fits into the figure area
109
  #ax.set_facecolor('#D3D3D3')
110
  elif output_extension.lower() in vid_extensions:
111
+ output_video = output_path
112
  output_image = None
113
+
114
+ # Interpolation preprocessing
115
+ interpolated_data = []
116
+
117
+ labels = frame_counts_df['label'].unique()
118
+ for label in labels:
119
+ df_label = frame_counts_df[frame_counts_df['label'] == label]
120
+
121
+ # Sort data by frame to ensure smooth interpolation
122
+ df_label = df_label.sort_values('frame')
123
+
124
+ # Original data points
125
+ x = df_label['frame']
126
+ y = df_label['count']
127
+
128
+ # Create spline interpolation
129
+ x_smooth = np.linspace(x.min(), x.max(), 500)
130
+ spline = make_interp_spline(x, y, k=3) # Cubic spline interpolation
131
+ y_smooth = spline(x_smooth)
132
+
133
+ # Append the smoothed data to the list
134
+ interpolated_data.append(pd.DataFrame({'frame': x_smooth, 'count': y_smooth, 'label': label}))
135
+
136
+ # Concatenate all interpolated data into a single DataFrame
137
+ interpolated_df = pd.concat(interpolated_data)
138
+
139
  plt.style.use("ggplot")
140
  fig, ax = plt.subplots(figsize=(10, 6))
141
+
142
+ # Plot using Seaborn
143
+ sns.lineplot(ax=ax, data=interpolated_df, x='frame', y='count', hue='label', palette=palette, linewidth=2.5)
144
+
145
  ax.set_title('Count of Labels over Frames', fontsize=20, pad=20) # Increase padding for the title
146
  ax.set_xlabel('Frame', fontsize=16) # Increase font size
147
  ax.set_ylabel('Count', fontsize=16) # Increase font size
148
  ax.tick_params(axis='x', labelsize=12) # Increase label size for x-axis
149
  ax.tick_params(axis='y', labelsize=12) # Increase label size for y-axis
150
+
151
  # Add grid but make it lighter and put it behind bars
152
  ax.grid(True, linestyle=':', linewidth=0.6, color='gray', alpha=0.6)
153
  ax.set_axisbelow(True)
154
+
155
  # Change the background color to a lighter shade
156
  ax.set_facecolor('#F0F0F0')
157
+
158
  # Add a legend with a smaller font size
159
  ax.legend(fontsize=10)
160
+
161
+ plt.tight_layout() # Ensure the entire plot is visible
162
+
163
+ # Return the figure, output_image, and output_video
164
  return output_image, output_video, fig
165
 
166
+
167
  def app():
168
  img = Image.open('./img_examples/classes.png')
169
  img = img.resize((410, 260), Image.Resampling.LANCZOS)