The power of Docker and how to use it

Yiling Liu
2 min readDec 10, 2019

--

Docker

A Docker image is a private filesystem, just for your container. It provides all the files and code your container will need.

Create a docker image by running docker build

Running the docker build command creates a Docker image using the Dockerfile. This built image is in your machine’s local Docker image registry.

cd doodle/cheers2019 && docker build -t lyleaf/cheers2019 .

Run a container based on your docker image by running docker run

Running a container launches your software with private resources, securely isolated from the rest of your machine.

docker run -it --rm lyleaf/cheers2019

Share your docker image using docker push

docker login && docker push lyleaf/cheers2019

MediaPipe

MediaPipe is basically a diagram, there are calculators which are nodes.

Calculator

You can define your calculator class, then register it to the graph using a macro invocation REGISTER_CALCULATOR.

REGISTER_CALCULATOR(PacketClonerCalculator);

Graph

Graph exist in pbtxt format, containing the nodes, input and output.

input_stream: "room_mic_signal"
input_stream: "room_lighting_sensor"
input_stream: "room_video_tick_signal"

node {
calculator: "PacketClonerCalculator"
input_stream: "room_mic_signal"
input_stream: "room_lighting_sensor"
input_stream: "room_video_tick_signal"
output_stream: "cloned_room_mic_signal"
output_stream: "cloned_lighting_sensor"
output_stream: "cloned_video_tick_signal"
}

MediaPipe object_detection graph (desktop) explained

They define this graph here: https://github.com/google/mediapipe/blob/master/mediapipe/graphs/object_detection/object_detection_desktop_tensorflow_graph.pbtxt

Official documentation here: https://mediapipe.readthedocs.io/en/latest/object_detection_desktop.html#tensorflow-lite-object-detection-demo

If you copy paste the graph into MediaPipe graph viewer https://viz.mediapipe.dev/, you can see a graph.

  1. Input file will be decoded to video header and images (frames)

2.1 Frames will be turned into Tensor using ImageFrameToTensor calculator.

2.2 A single side packet of saved_model.pb will be turned into a Tensorflow seesion, via TensorFlowSessionFromSavedModel calculator.

3. Tensorflow session + image will go into TensorFlowInferenceCalculator, and create 4 outputs: NUM_DETECTIONS, CLASSES, SCORES, BOXES.

4. Lots of proposals, and we filter the proposals by NonMaxSuppressionCalculator.

5. Maps the label IDs to the corresponding label text using DetectionLabelIdToTextCalculator. The label map is provided in label_map_path option.

6. Converts detections to drawing primitives for annotation overlay, using DetectionsToRenderDataCalculator.

7. AnnotationOverlayCalculator will draw annotations and overlays them on top of the original image.

8. Use OpenCvVideoEncoderCalculator to encode the annotated images to a video file, using properties in the input video header like video frame rate etc.

Run MediaPipe hello_world on Docker

docker run -it --name mediapipe mediapipe:latestGLOG_logtostderr=1 bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world:hello_world

Run MediaPipe object_detection on Docker

bazel build -c opt \
--define MEDIAPIPE_DISABLE_GPU=1 \
--define no_aws_support=true \
mediapipe/examples/desktop/object_detection:object_detection_tensorflow
GLOG_logtostderr=1 bazel-bin/mediapipe/examples/desktop/object_detection/object_detection_tensorflow \
--calculator_graph_config_file=mediapipe/graphs/object_detection/object_detection_desktop_tensorflow_graph.pbtxt \
--input_side_packets=input_video_path=<input video path>,output_video_path=<output video path>

--

--

Yiling Liu
Yiling Liu

Written by Yiling Liu

Creative Technologist, ex-googler

No responses yet