Skip to content

Commit

Permalink
Replace gifs for videos on demos (#177)
Browse files Browse the repository at this point in the history
* Regenerated detectron2 videos

Had to change some params and add a new demo script for the video
without tracking

* Updated mmdetection video

* Updated yolov5 videos

* Updated yolov4 video

* Updated alphapose video

* Updated camera_motion videos

* Updated reid video

* Changes to reid and keypoints-bboxes demos

Had to modify them so that we can reproduce the videos

* Updated keypoints and bboxes video

* Update openpose video

* Changed detectron video

Dropped comparison and kept just one of the videos

* Updated ylov7 video

* Changes to yolov7 demo

Use bbox by default and remove paths

* Fixed apt update on some dockerfiles

* Removed the new script for detectron video

* Updated yolov5 video

Kept only one of the videos and changed demo to not draw the paths
  • Loading branch information
javiber committed Sep 12, 2022
1 parent 780d73b commit f466291
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 55 deletions.
2 changes: 1 addition & 1 deletion demos/alphapose/README.md
Expand Up @@ -26,4 +26,4 @@ This example modifies AlphaPose's original `writer.py` file, integrating a few l

This produces the following results:

![Norfair AlphaPose demo](../../docs/videos/alphapose.gif)
https://user-images.githubusercontent.com/3588715/189143865-c22630d4-d60a-422b-b21e-9b8637e83ec2.mp4
6 changes: 3 additions & 3 deletions demos/camera_motion/README.md
Expand Up @@ -13,11 +13,11 @@ Keep in mind that the estimation of the camera movement works best with a static

This method only works for camera pans and tilts.

<img src="/docs/videos/pan_tilt.png" alt="Pan and tilt" width="350px">
<img src="/docs/img/pan_tilt.png" alt="Pan and tilt" width="350px">

For an example of results, see the following videos. On the left, the tracker lost the person 4 times (as seen by the increasing id, and the color of the bounding box changing). However, on the right the tracker is able to maintain the tracked object throughout the video:

![Tracking an object with Norfair, with and without camera stabilization.](/docs/videos/camera_stabilization.gif)
https://user-images.githubusercontent.com/3588715/189200533-6fb3031f-8f03-4116-afc8-bd3ec4265119.mp4

> Videos generated using command `python demo.py --transformation none --draw-objects --track-boxes --id-size 1.8 --distance-threshold 200 --save <video>.mp4` and `python demo.py --transformation translation --fixed-camera-scale 2 --draw-objects --track-boxes --id-size 1.8 --distance-threshold 200 --save <video>.mp4`
Expand All @@ -27,7 +27,7 @@ This method can work with any camera movement, including pan, tilt, rotation, mo

In the following video, the players are tracked and their trajectories are drawn, even as the camera moves:

![Tracking soccer players with Norfair and a moving camera.](/docs/videos/soccer.gif)
https://user-images.githubusercontent.com/3588715/189200514-b1b25601-2b45-4d2f-9c2f-224b09c9b020.mp4

> Video generated using command `python demo.py --transformation homography --draw-paths --path-history 150 --distance-threshold 200 --track-boxes --max-points=900 --min-distance=14 --save --model yolov5x --hit-counter-max 3 <video>.mp4` on a snippet of this [video](https://www.youtube.com/watch?v=CGFgHjeEkbY&t=1200s).
Expand Down
6 changes: 3 additions & 3 deletions demos/detectron2/Dockerfile
Expand Up @@ -11,12 +11,12 @@ RUN pip install --upgrade pip
# Install Detectron2 building from source
RUN pip install 'git+https://github.com/facebookresearch/detectron2.git'

# Download model weights
ADD https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl /model/model_final_f10217.pkl

# For some reason it doesn't work with latest version of OpenCV
RUN pip install opencv-python==4.5.5.64

RUN pip install git+https://github.com/tryolabs/norfair.git@master#egg=norfair

WORKDIR /demo/src/

# Download model weights
ADD https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl /model/model_final_f10217.pkl
2 changes: 1 addition & 1 deletion demos/detectron2/README.md
Expand Up @@ -18,4 +18,4 @@ For additional settings, you may display the instructions using `python demo.py

This example tracks objects using a single point per detection: the centroid of the bounding boxes returned by Detectron2.

![Norfair Detectron2 demo](../../docs/videos/traffic.gif)
https://user-images.githubusercontent.com/3588715/189415541-d0b8f963-b813-449c-8f69-3d0c52f488cf.mp4
4 changes: 2 additions & 2 deletions demos/detectron2/src/demo.py
Expand Up @@ -14,7 +14,7 @@
# Set up Detectron2 object detector
cfg = get_cfg()
cfg.merge_from_file("./detectron2_config.yaml")
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.4
cfg.MODEL.WEIGHTS = "/model/model_final_f10217.pkl"
detector = DefaultPredictor(cfg)

Expand All @@ -35,5 +35,5 @@
# if c == 2
]
tracked_objects = tracker.update(detections=detections)
draw_tracked_objects(frame, tracked_objects)
draw_tracked_objects(frame, tracked_objects, id_thickness=2)
video.write(frame)
2 changes: 1 addition & 1 deletion demos/keypoints_bounding_boxes/Dockerfile
Expand Up @@ -11,7 +11,7 @@ ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/hpcx/ompi/lib"
# Install dependencies for OpenPose and its installation
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get install --yes --auto-remove \
RUN apt-get update --yes && apt-get install --yes --auto-remove \
libopencv-dev \
protobuf-compiler \
libgoogle-glog-dev \
Expand Down
2 changes: 1 addition & 1 deletion demos/keypoints_bounding_boxes/README.md
Expand Up @@ -22,4 +22,4 @@ Alternatively, the example can be executed entirely within `keypoints_bounding_b

This example aims at showing the possibilities that Norfair offers to track objects from multiple classes using a single `Tracker` instance. Also the example shows Norfair's ability to draw keypoints and bounding boxes for different types of objects.

![keypoints_bounding_boxes_demo](../../docs/videos/keypoints_bounding_boxes_demo.gif)
https://user-images.githubusercontent.com/3588715/189385171-8e1d5a5d-3796-4408-8729-26103d906063.mp4
5 changes: 3 additions & 2 deletions demos/keypoints_bounding_boxes/src/demo.py
Expand Up @@ -8,6 +8,7 @@

import norfair
from norfair import Detection, Tracker, Video
from norfair.drawing import Color

# Import openpose
openpose_install_path = (
Expand Down Expand Up @@ -230,11 +231,11 @@ def keypoints_distance(detected_pose, tracked_pose):
norfair.draw_tracked_objects(
frame,
[person for person in tracked_objects if person.label == -1],
color_by_label=True,
color=Color.green,
)
norfair.draw_tracked_boxes(
frame,
[obj for obj in tracked_objects if obj.label >= 0],
[obj for obj in tracked_objects if obj.label > 0],
color_by_label=True,
)

Expand Down
2 changes: 1 addition & 1 deletion demos/mmdetection/README.md
Expand Up @@ -18,4 +18,4 @@ For additional settings, you may display the instructions using `python demo.py

This example tracks objects using a single point per detection: the centroid of the bounding boxes returned by MMDetection.

![Norfair MMDetection demo](../../docs/videos/traffic_mmdet.gif)
https://user-images.githubusercontent.com/3588715/188966051-14cd25ea-4e31-4df0-8732-6beb952abf3b.mp4
3 changes: 1 addition & 2 deletions demos/openpose/Dockerfile
Expand Up @@ -11,8 +11,7 @@ ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/hpcx/ompi/lib"
# Install dependencies for OpenPose and its installation
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update --yes
RUN apt-get install --yes --auto-remove \
RUN apt-get update --yes && apt-get install --yes --auto-remove \
libopencv-dev \
protobuf-compiler \
libgoogle-glog-dev \
Expand Down
6 changes: 2 additions & 4 deletions demos/openpose/README.md
Expand Up @@ -18,10 +18,8 @@ For additional settings, you may display the instructions using `python demo.py

If you just want to speed up inference on a detector, you can make your detector skip frames, and use Norfair to extrapolate the detections through these skipped frames.

In this example, we are skipping 4 out of every 5 frames, which should make processing the video 5 times faster. This is because the time added by running the Norfair itself is negligible when compared to not having to run 4 inferences on a deep neural network.
In this example, we are skipping 1 out of every 2 frames, which should make processing the video 2 times faster. This is because the time added by running the Norfair itself is negligible when compared to not having to run 4 inferences on a deep neural network.

This is what the results look like (original videos can be found at [Kaggle](https://www.kaggle.com/datasets/ashayajbani/oxford-town-centre?select=TownCentreXVID.mp4)):

![openposev17_1_skip_5_frames_short](https://user-images.githubusercontent.com/92468171/172702968-ae986ecc-9cfd-4cd2-9132-92c19ff36608.gif)

![openposev17_2_skip_5_frames_short](https://user-images.githubusercontent.com/92468171/172703046-e769a9fa-4c0e-4111-9478-eb2d8ad2cead.gif)
https://user-images.githubusercontent.com/3588715/189412164-9685072c-24d0-431e-a622-2db6d410e174.mp4
6 changes: 3 additions & 3 deletions demos/reid/README.md
Expand Up @@ -2,9 +2,9 @@

An example of how to use Norfair to perform re-identification using appearance embeddings. This example creates a simulation video where boxes are moving around. When boxes get occluded by other boxes we just grab the detection from the top box, so any other box occluded is not getting a detection. At the same time, detections are not perfect and have some noise.

| Without ReID | With ReID |
| :-----------------------: | :--------------------: |
| ![](./assets/no_reid.gif) | ![](./assets/reid.gif) |
Comparison of not using ReID (left) vs using it (right)

https://user-images.githubusercontent.com/3588715/189216867-7b5da1e5-e492-4c9f-ac6e-12cbd3eed1ea.mp4

## Instructions

Expand Down
36 changes: 25 additions & 11 deletions demos/reid/src/demo.py
Expand Up @@ -42,20 +42,34 @@ def embedding_distance(matched_not_init_trackers, unmatched_trackers):
def main(
output_path: str = "./out.mp4",
skip_period: int = 1,
disable_reid: bool = False,
):
video_path, _, video_predictions = generate_video()

tracker = Tracker(
initialization_delay=1,
distance_function=distance_func,
hit_counter_max=10,
filter_factory=OptimizedKalmanFilterFactory(),
distance_threshold=50,
past_detections_length=5,
reid_distance_function=embedding_distance,
reid_distance_threshold=0.5,
reid_hit_counter_max=500,
)
if disable_reid:
tracker = Tracker(
initialization_delay=1,
distance_function=distance_func,
hit_counter_max=10,
filter_factory=OptimizedKalmanFilterFactory(),
distance_threshold=50,
past_detections_length=5,
# reid_distance_function=embedding_distance,
# reid_distance_threshold=0.5,
# reid_hit_counter_max=500,
)
else:
tracker = Tracker(
initialization_delay=1,
distance_function=distance_func,
hit_counter_max=10,
filter_factory=OptimizedKalmanFilterFactory(),
distance_threshold=50,
past_detections_length=5,
reid_distance_function=embedding_distance,
reid_distance_threshold=0.5,
reid_hit_counter_max=500,
)

video = Video(input_path=video_path, output_path=output_path)
for i, cv2_frame in enumerate(video):
Expand Down
18 changes: 15 additions & 3 deletions demos/reid/src/video_generator.py
Expand Up @@ -168,13 +168,17 @@ def generate_video(
output_path: str = "demo.avi",
fps: int = 30,
canvas_size: int = 800,
border_size=10,
):
def _empty_canvas(canvas_size=(canvas_size, canvas_size, 3)):
img = np.ones(canvas_size, dtype=np.uint8) * 30
return img

video = cv2.VideoWriter(
output_path, cv2.VideoWriter_fourcc(*"DIVX"), fps, (canvas_size, canvas_size)
output_path,
cv2.VideoWriter_fourcc(*"DIVX"),
fps,
(canvas_size + 2 * border_size, canvas_size + 2 * border_size),
)

detections_gt = []
Expand All @@ -200,8 +204,16 @@ def _empty_canvas(canvas_size=(canvas_size, canvas_size, 3)):
img[int(ymin) : int(ymax), int(xmin) : int(xmax), channel] = feature[
channel
]

video.write(img)
border_size = 10
frame = (
np.ones(
(canvas_size + 2 * border_size, canvas_size + 2 * border_size, 3),
dtype=img.dtype,
)
* 255
)
frame[border_size:-border_size, border_size:-border_size] = img
video.write(frame)
detections_gt.append(dets_gt)
detections_pred.append(dets_pred)
video.release()
Expand Down
2 changes: 1 addition & 1 deletion demos/yolov4/README.md
Expand Up @@ -20,4 +20,4 @@ For additional settings, you may display the instructions using `python demo.py

This example tracks objects using a single point per detection: the centroid of the bounding boxes around cars returned by YOLOv4.

![Norfair YOLOv4 demo](../../docs/videos/yolov4_cars.gif)
https://user-images.githubusercontent.com/3588715/189133927-f4d7e594-7241-4113-bfa9-716b16d07e46.mp4
12 changes: 2 additions & 10 deletions demos/yolov5/README.md
Expand Up @@ -16,16 +16,8 @@ For additional settings, you may display the instructions using `python demo.py

## Explanation

This example tracks objects using a single or double point per detection: the centroid or the two corners of the bounding boxes around objects returned by YOLOv5.
This example cat track objects using a single or double point per detection: the centroid or the two corners of the bounding boxes around objects returned by YOLOv5.

## Tracking cars

![Norfair tracking cars using YOLOv5](../../docs/videos/yolov5_cars.gif)

## Tracking pedestrians

![Norfair tracking pedestrians using YOLOv5](../../docs/videos/yolov5_pedestrian.gif)

## Tracking all

![Norfair tracking cars and pedestrians using YOLOv5](../../docs/videos/yolov5_all.gif)
https://user-images.githubusercontent.com/3588715/189720485-31a6302c-d046-4f3c-ae01-5ae53b9fde35.mp4
2 changes: 0 additions & 2 deletions demos/yolov5/src/demo.py
Expand Up @@ -138,7 +138,6 @@ def yolo_detections_to_norfair_detections(
distance_function=distance_function,
distance_threshold=distance_threshold,
)
paths_drawer = Paths(center, attenuation=0.01)

for frame in video:
yolo_detections = model(
Expand All @@ -158,5 +157,4 @@ def yolo_detections_to_norfair_detections(
elif args.track_points == "bbox":
norfair.draw_boxes(frame, detections)
norfair.draw_tracked_boxes(frame, tracked_objects)
frame = paths_drawer.draw(frame, tracked_objects)
video.write(frame)
2 changes: 1 addition & 1 deletion demos/yolov7/README.md
Expand Up @@ -18,4 +18,4 @@ For additional settings, you may display the instructions using `python demo.py

This example tracks objects using a single point per detection: the centroid of the bounding boxes around objects returned by YOLOv7.

![Norfair YOLOv7 demo](../../docs/videos/yolov7_cars.gif)
https://user-images.githubusercontent.com/3588715/189417903-0265425b-fb36-4f1f-a979-57e0e56e733c.mp4
4 changes: 1 addition & 3 deletions demos/yolov7/src/demo.py
Expand Up @@ -127,7 +127,7 @@ def yolo_detections_to_norfair_detections(
parser.add_argument(
"--track-points",
type=str,
default="centroid",
default="bbox",
help="Track points: 'centroid' or 'bbox'",
)
args = parser.parse_args()
Expand All @@ -149,7 +149,6 @@ def yolo_detections_to_norfair_detections(
distance_function=distance_function,
distance_threshold=distance_threshold,
)
paths_drawer = Paths(center, attenuation=0.01)

for frame in video:
yolo_detections = model(
Expand All @@ -169,5 +168,4 @@ def yolo_detections_to_norfair_detections(
elif args.track_points == "bbox":
norfair.draw_boxes(frame, detections)
norfair.draw_tracked_boxes(frame, tracked_objects)
frame = paths_drawer.draw(frame, tracked_objects)
video.write(frame)

0 comments on commit f466291

Please sign in to comment.