Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/adjust tcn coco saving #460

Merged
merged 43 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1989d18
change coco saving to use the annotation
josephvanpeltkw Oct 21, 2024
f3cf62a
Merge branch 'PTG-Kitware:master' into dev/adjust_tcn_coco_saving
josephvanpeltkw Oct 23, 2024
ccf8032
add a debug option to the TCN node in order to see the inputs it has …
josephvanpeltkw Oct 25, 2024
24b3080
adjust saving of coco output and add score
josephvanpeltkw Oct 25, 2024
a1e3bef
add collection of no activity classification
josephvanpeltkw Oct 25, 2024
6ef0d71
add a note about usage to the video/image to bag conversion script
josephvanpeltkw Oct 25, 2024
f242ea2
black formatting a clean copy error
josephvanpeltkw Oct 25, 2024
54e8104
check the frame number first before ignoring a frame (for playing bac…
josephvanpeltkw Oct 25, 2024
3650376
drop unneeded argument
josephvanpeltkw Oct 25, 2024
afec82d
change coco saving to add an image regardless of whether the activity…
josephvanpeltkw Oct 25, 2024
cc257d8
fix for beginning frame issue
josephvanpeltkw Oct 25, 2024
aec3eb1
simplify handling images that were already added
josephvanpeltkw Oct 25, 2024
4736376
cleanup debug input so it is easier to read in normal viewers
josephvanpeltkw Oct 28, 2024
81dc612
change the way that timestamps are saved to bags
josephvanpeltkw Oct 29, 2024
36d97d9
remove the need to check frame number now that converting videos to b…
josephvanpeltkw Oct 29, 2024
c40adfc
black formatting
josephvanpeltkw Oct 29, 2024
6105312
Incremental updates to train README for data and precursor data gener…
Purg Oct 21, 2024
412b8b7
Move TCN vectorization into the TCN package
Purg Oct 21, 2024
3d31631
Add colorlog dep to support TCN training
Purg Oct 22, 2024
c6a36f1
Minor dep order reorg, pin hydra-colorlog version like in tcn-hpl
Purg Oct 23, 2024
2f1c2a3
Updates to training README
Purg Oct 23, 2024
d8bff16
Fix archive extraction script
Purg Oct 23, 2024
502322e
Add final grep to probe helper script
Purg Oct 23, 2024
7fd0a26
Revert TensorRT Engine model usage
Purg Oct 24, 2024
21d4423
Update TCN related things to use common dataset and vector computation
Purg Oct 24, 2024
c2bc709
Update yolo v7 submodule for CLI updates
Purg Oct 25, 2024
1110b8c
Fix formatting
Purg Oct 25, 2024
ffb0d43
Finish documentation sentence
Purg Oct 25, 2024
7c4d693
Cache old configurations into an "old" directory for now
Purg Oct 25, 2024
65eb715
add a debug option to the TCN node in order to see the inputs it has …
josephvanpeltkw Oct 25, 2024
0839d1c
cleanup debug input so it is easier to read in normal viewers
josephvanpeltkw Oct 28, 2024
fd55d1f
Update TCN related things to use common dataset and vector computation
Purg Oct 24, 2024
59c5598
cleanup debug input so it is easier to read in normal viewers
josephvanpeltkw Oct 28, 2024
b6895f0
Update TCN related things to use common dataset and vector computation
Purg Oct 24, 2024
fe065ef
cleanup debug input so it is easier to read in normal viewers
josephvanpeltkw Oct 28, 2024
49319ff
Merge branch 'master' into dev/adjust_tcn_coco_saving
josephvanpeltkw Oct 29, 2024
64ae6c0
Merge branch 'PTG-Kitware:master' into dev/adjust_tcn_coco_saving
josephvanpeltkw Oct 29, 2024
7d5230e
fix for classes not in model
josephvanpeltkw Oct 29, 2024
ef38e74
Update ros/angel_system_nodes/angel_system_nodes/activity_classificat…
josephvanpeltkw Oct 30, 2024
a3ce112
remove unneeded code and change var name
josephvanpeltkw Oct 30, 2024
3441c18
change to collect image outside of try statement so it always collects
josephvanpeltkw Oct 30, 2024
c1f7fbb
Update ros/angel_system_nodes/angel_system_nodes/activity_classificat…
josephvanpeltkw Oct 30, 2024
db2820e
Update ros/angel_system_nodes/angel_system_nodes/activity_classificat…
josephvanpeltkw Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions angel_system/activity_classification/tcn_hpl/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,19 +464,29 @@ def collect(
raise RuntimeError(
"No video set before results collection. See `set_video` method."
)
packet = dict(
# get the global id for the image from the frame number

# add the image
img = dict(
video_id=self._vid,
frame_index=frame_index,
activity_pred=activity_pred,
activity_conf=list(activity_conf_vec),
)
if name is not None:
packet["name"] = name
img["name"] = name
if file_name is not None:
packet["file_name"] = file_name
img["file_name"] = file_name
if activity_gt is not None:
packet["activity_gt"] = activity_gt
self._dset.add_image(**packet)
img["activity_gt"] = activity_gt
josephvanpeltkw marked this conversation as resolved.
Show resolved Hide resolved
# save the gid from the image to link to the annot
gid = self._dset.add_image(**img)

# add the annotation
self._dset.add_annotation(
image_id=gid,
category_id=activity_pred,
score=activity_conf_vec[activity_pred],
prob=list(activity_conf_vec),
)

def write_file(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
# activity prediction for the "live" image will not occur until object
# detections are predicted for that frame.
PARAM_WINDOW_LEADS_WITH_OBJECTS = "window_leads_with_objects"
# Debug file saved out to the filesystem for understanding the node's
# inputs when it decides not to create an activity classification.
# the format will be csv with a list of the object detections and the pose
PARAM_DEBUG_FILE = "debug_file"


class NoActivityClassification(Exception):
Expand Down Expand Up @@ -148,6 +152,7 @@ def __init__(self):
(PARAM_TOPIC, "medical"),
(PARAM_POSE_REPEAT_RATE, 0),
(PARAM_WINDOW_LEADS_WITH_OBJECTS, False),
(PARAM_DEBUG_FILE, ""),
],
)
self._img_ts_topic = param_values[PARAM_IMG_TS_TOPIC]
Expand All @@ -166,6 +171,12 @@ def __init__(self):

self._window_lead_with_objects = param_values[PARAM_WINDOW_LEADS_WITH_OBJECTS]

self._debug_file = param_values[PARAM_DEBUG_FILE]
# clear the file if it exists (since we are appending to it)
if self._debug_file != "":
with open(self._debug_file, "w") as f:
f.write("")

self.topic = param_values[PARAM_TOPIC]
# Load in TCN classification model and weights
with SimpleTimer("Loading inference module", log.info):
Expand Down Expand Up @@ -649,12 +660,29 @@ def rt_loop(self):

self._activity_publisher.publish(act_msg)
except NoActivityClassification:
# collect the results if we are saving to coco file
if self._results_collector:
# Prepare output message
activity_msg = ActivityDetection()
# set the only needed items for collection
activity_msg.source_stamp_end_frame = window.frames[-1][0]
activity_msg.conf_vec = [0.0 for x in self._model.classes]
self._collect_results(activity_msg)
josephvanpeltkw marked this conversation as resolved.
Show resolved Hide resolved

# No ramifications, but don't publish activity message.
log.warn(
"Runtime loop window processing function did "
"not yield an activity classification for "
"publishing."
)
if self._debug_file != "":
# save the info for why this window was not processed
repr = window.__repr__()
with open(self._debug_file, "a") as f:
f.write(
f"timestamp: {self.get_clock().now().to_msg()}\n"
)
f.write(f"{repr}\n")

# This window has completed processing - record its leading
# timestamp now.
Expand Down
10 changes: 7 additions & 3 deletions ros/angel_utils/python/angel_utils/activity_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,17 @@ def queue_image(
# self.get_logger_fn().info(f"self.frames[-1][0] header stamp: {self.frames[-1][0]}")
with self.__state_lock:
# before the current lead frame?
if self.frames and time_to_int(img_header_stamp) <= time_to_int(
self.frames[-1][0]
if (
self.frames
and self.frames[-1][2] == image_frame_number
and time_to_int(img_header_stamp) <= time_to_int(self.frames[-1][0])
josephvanpeltkw marked this conversation as resolved.
Show resolved Hide resolved
):
self.get_logger_fn().warn(
f"Input image frame was NOT after the previous latest: "
f"(prev) {time_to_int(self.frames[-1][0])} "
f"!< {time_to_int(img_header_stamp)} (new)"
f"!< {time_to_int(img_header_stamp)} (new)\n"
f"frame number: {image_frame_number}\n"
f"prev frame number: {self.frames[-1][2]}"
)
return False
self.frames.append((img_header_stamp, img_mat, image_frame_number))
Expand Down
8 changes: 8 additions & 0 deletions ros/angel_utils/scripts/convert_video_to_ros_bag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#!/usr/bin/env python3
"""
Convert a video (mp4) or a series of images into a ROS bag.

Example running (inside ROS environment):
ros2 run angel_utils convert_video_to_ros_bag.py \
--video-fn video.mp4 \
--output-bag-folder ros_bags/new_bag
"""
import argparse
from glob import glob
from pathlib import Path
Expand Down
Loading