Medha Sawhney
commited on
Commit
·
380fa1d
1
Parent(s):
c38c5c1
debug output video error with no tracks
Browse files- MEMTrack/src/GenerateVideo.py +6 -2
- MEMTrack/src/TrackingAnalysis.py +1 -0
- app.py +24 -4
MEMTrack/src/GenerateVideo.py
CHANGED
@@ -10,12 +10,16 @@ def create_video(data_dir, image_dir, video_name,fps, all_image_path=None, all_i
|
|
10 |
plotted_images = natsorted(os.listdir(image_dir))
|
11 |
images = plotted_images
|
12 |
sample_image_dir = image_dir
|
|
|
|
|
|
|
|
|
13 |
if all_images:
|
14 |
all_images_list = natsorted(os.listdir(all_image_path))
|
15 |
images = all_images_list
|
16 |
sample_image_dir = all_image_path
|
17 |
-
|
18 |
-
|
19 |
img_sample = cv2.imread(os.path.join(sample_image_dir,images[0]))
|
20 |
print(images[0])
|
21 |
print(img_sample.shape)
|
|
|
10 |
plotted_images = natsorted(os.listdir(image_dir))
|
11 |
images = plotted_images
|
12 |
sample_image_dir = image_dir
|
13 |
+
if len(images) == 0:
|
14 |
+
all_images = True
|
15 |
+
print("Turning to all images as no tracked images")
|
16 |
+
|
17 |
if all_images:
|
18 |
all_images_list = natsorted(os.listdir(all_image_path))
|
19 |
images = all_images_list
|
20 |
sample_image_dir = all_image_path
|
21 |
+
|
22 |
+
|
23 |
img_sample = cv2.imread(os.path.join(sample_image_dir,images[0]))
|
24 |
print(images[0])
|
25 |
print(img_sample.shape)
|
MEMTrack/src/TrackingAnalysis.py
CHANGED
@@ -166,6 +166,7 @@ def analyse_tracking(video_num, min_track_length=60, custom_test_dir=None, data_
|
|
166 |
|
167 |
|
168 |
track_id_details = groupby_trackid(tracking_data_filtered)
|
|
|
169 |
num_frames, num_fragments, fragment_lengths, skipped_frames, track_id_filtered_length =analyze_track_preds(track_id_details,filter_length=True,min_con_length=min_track_length)
|
170 |
|
171 |
try:
|
|
|
166 |
|
167 |
|
168 |
track_id_details = groupby_trackid(tracking_data_filtered)
|
169 |
+
track_id_unfiltered_length = track_id_details
|
170 |
num_frames, num_fragments, fragment_lengths, skipped_frames, track_id_filtered_length =analyze_track_preds(track_id_details,filter_length=True,min_con_length=min_track_length)
|
171 |
|
172 |
try:
|
app.py
CHANGED
@@ -79,6 +79,8 @@ def download_and_unzip_google_drive_file(file_id, output_path, unzip_path):
|
|
79 |
with zipfile.ZipFile(output_path, 'r') as zip_ref:
|
80 |
zip_ref.extractall(unzip_path)
|
81 |
|
|
|
|
|
82 |
|
83 |
# @spaces.GPU()
|
84 |
def doo(video, tiff_stack, images, fps, min_track_length, progress=gr.Progress()):
|
@@ -161,11 +163,16 @@ def doo(video, tiff_stack, images, fps, min_track_length, progress=gr.Progress()
|
|
161 |
progress(2 / 3, desc=f"Tracking {2}/{3}")
|
162 |
folder_path = analyse_tracking(video_num=video_num, min_track_length=min_track_length, data_feature_path=feature_data_path, data_root_path=final_data_dir, plot=True)
|
163 |
progress(3 / 3, desc=f"Tracking {3}/{3}")
|
|
|
164 |
output_video1 = gen_tracking_video(video_num=video_num, fps=fps, data_path=feature_data_path)
|
|
|
165 |
output_video2 = gen_tracking_video(video_num=video_num, fps=fps, data_path=feature_data_path, all_images=True)
|
166 |
-
|
|
|
|
|
167 |
shutil.copy(output_video1, final_videos[0])
|
168 |
shutil.copy(output_video2, final_videos[1])
|
|
|
169 |
print(output_video1)
|
170 |
print(final_videos)
|
171 |
|
@@ -173,7 +180,7 @@ def doo(video, tiff_stack, images, fps, min_track_length, progress=gr.Progress()
|
|
173 |
tracking_preds = find_and_return_csv_files(folder_path, search_pattern)
|
174 |
|
175 |
|
176 |
-
return final_videos[0], final_videos[1], tracking_preds
|
177 |
|
178 |
|
179 |
|
@@ -207,15 +214,28 @@ if __name__ == "__main__":
|
|
207 |
# Common sliders for all inputs
|
208 |
fps_slider = gr.Slider(minimum=1, maximum=100, step=1, value=60, label="Output Video FPS")
|
209 |
track_length_slider = gr.Slider(minimum=0, maximum=1000, step=1, value=60, label="Minimum Track Length Threshold")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
with gr.Column():
|
211 |
outputs = [
|
212 |
gr.Video(label="Tracked Video (tracked frames)"),
|
213 |
gr.Video(label="Tracked Video (all frames)"),
|
|
|
214 |
gr.Files(label="CSV Data")
|
215 |
]
|
216 |
|
217 |
-
|
218 |
-
submit_button = gr.Button("Process Input")
|
219 |
submit_button.click(
|
220 |
fn=doo,
|
221 |
inputs=[video_input, tiff_input, image_input, fps_slider, track_length_slider],
|
|
|
79 |
with zipfile.ZipFile(output_path, 'r') as zip_ref:
|
80 |
zip_ref.extractall(unzip_path)
|
81 |
|
82 |
+
def clear_form():
|
83 |
+
return None, None, None, 60, 60 # Resetting inputs and sliders to default or empty states
|
84 |
|
85 |
# @spaces.GPU()
|
86 |
def doo(video, tiff_stack, images, fps, min_track_length, progress=gr.Progress()):
|
|
|
163 |
progress(2 / 3, desc=f"Tracking {2}/{3}")
|
164 |
folder_path = analyse_tracking(video_num=video_num, min_track_length=min_track_length, data_feature_path=feature_data_path, data_root_path=final_data_dir, plot=True)
|
165 |
progress(3 / 3, desc=f"Tracking {3}/{3}")
|
166 |
+
# Generate video with tracked frames only at the given filter threshold
|
167 |
output_video1 = gen_tracking_video(video_num=video_num, fps=fps, data_path=feature_data_path)
|
168 |
+
# Generate video with all frames at the given filter threshold
|
169 |
output_video2 = gen_tracking_video(video_num=video_num, fps=fps, data_path=feature_data_path, all_images=True)
|
170 |
+
# Generate video with all frames with all tracks, so no filter threshold
|
171 |
+
output_video3 = gen_tracking_video(video_num=video_num, fps=fps, data_path=feature_data_path, all_images=True)
|
172 |
+
final_videos = [os.path.basename(output_video1), os.path.basename(output_video2), os.path.basename(output_video3)]
|
173 |
shutil.copy(output_video1, final_videos[0])
|
174 |
shutil.copy(output_video2, final_videos[1])
|
175 |
+
shutil.copy(output_video3, final_videos[2])
|
176 |
print(output_video1)
|
177 |
print(final_videos)
|
178 |
|
|
|
180 |
tracking_preds = find_and_return_csv_files(folder_path, search_pattern)
|
181 |
|
182 |
|
183 |
+
return final_videos[0], final_videos[1], final_videos[2], tracking_preds
|
184 |
|
185 |
|
186 |
|
|
|
214 |
# Common sliders for all inputs
|
215 |
fps_slider = gr.Slider(minimum=1, maximum=100, step=1, value=60, label="Output Video FPS")
|
216 |
track_length_slider = gr.Slider(minimum=0, maximum=1000, step=1, value=60, label="Minimum Track Length Threshold")
|
217 |
+
|
218 |
+
# Submit and Clear buttons
|
219 |
+
submit_button = gr.Button("Submit")
|
220 |
+
clear_button = gr.Button("Clear")
|
221 |
+
|
222 |
+
|
223 |
+
clear_button.click(
|
224 |
+
fn=clear_form,
|
225 |
+
inputs=[],
|
226 |
+
outputs=[video_input, tiff_input, image_input, fps_slider, track_length_slider]
|
227 |
+
)
|
228 |
+
|
229 |
with gr.Column():
|
230 |
outputs = [
|
231 |
gr.Video(label="Tracked Video (tracked frames)"),
|
232 |
gr.Video(label="Tracked Video (all frames)"),
|
233 |
+
gr.Video(label="Tracked Video (all frames, all tracks)"),
|
234 |
gr.Files(label="CSV Data")
|
235 |
]
|
236 |
|
237 |
+
|
238 |
+
# submit_button = gr.Button("Process Input")
|
239 |
submit_button.click(
|
240 |
fn=doo,
|
241 |
inputs=[video_input, tiff_input, image_input, fps_slider, track_length_slider],
|