Project import generated by Copybara.

GitOrigin-RevId: afeb9cf5a8c069c0a566d16e1622bbb086170e4d
This commit is contained in:
MediaPipe Team
2020-05-21 13:37:51 -04:00
committed by chuoling
parent b6e680647c
commit b133b0f200
258 changed files with 4146 additions and 5147 deletions
@@ -491,13 +491,13 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
// Formats and outputs cropped frames.
bool apply_padding = false;
float vertical_fill_precent;
float vertical_fill_percent;
std::vector<cv::Rect> render_to_locations;
cv::Scalar padding_color;
std::vector<cv::Scalar> padding_colors;
if (should_perform_frame_cropping_) {
MP_RETURN_IF_ERROR(FormatAndOutputCroppedFrames(
cropped_frames, &render_to_locations, &apply_padding, &padding_color,
&vertical_fill_precent, cc));
cropped_frames, &render_to_locations, &apply_padding, &padding_colors,
&vertical_fill_percent, cc));
}
// Caches prior FocusPointFrames if this was not the end of a scene.
prior_focus_point_frames_.clear();
@@ -534,7 +534,7 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
for (int i = 0; i < scene_frame_timestamps_.size(); i++) {
auto external_render_message = absl::make_unique<ExternalRenderFrame>();
ConstructExternalRenderMessage(
crop_from_locations[i], render_to_locations[i], padding_color,
crop_from_locations[i], render_to_locations[i], padding_colors[i],
scene_frame_timestamps_[i], external_render_message.get());
cc->Outputs()
.Tag(kExternalRenderingPerFrame)
@@ -547,7 +547,7 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
for (int i = 0; i < scene_frame_timestamps_.size(); i++) {
ExternalRenderFrame render_frame;
ConstructExternalRenderMessage(crop_from_locations[i],
render_to_locations[i], padding_color,
render_to_locations[i], padding_colors[i],
scene_frame_timestamps_[i], &render_frame);
external_render_list_->push_back(render_frame);
}
@@ -565,7 +565,7 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
::mediapipe::Status SceneCroppingCalculator::FormatAndOutputCroppedFrames(
const std::vector<cv::Mat>& cropped_frames,
std::vector<cv::Rect>* render_to_locations, bool* apply_padding,
cv::Scalar* padding_color, float* vertical_fill_precent,
std::vector<cv::Scalar>* padding_colors, float* vertical_fill_percent,
CalculatorContext* cc) {
RET_CHECK(apply_padding) << "Has padding boolean is null.";
if (cropped_frames.empty()) {
@@ -589,7 +589,7 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
if (scaled_height - target_height_ <= 1) scaled_height = target_height_;
*apply_padding =
scaled_width != target_width_ || scaled_height != target_height_;
*vertical_fill_precent = scaled_height / static_cast<float>(target_height_);
*vertical_fill_percent = scaled_height / static_cast<float>(target_height_);
if (*apply_padding) {
padder_ = absl::make_unique<PaddingEffectGenerator>(
scaled_width, scaled_height, target_aspect_ratio_);
@@ -616,6 +616,8 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
cv::Scalar* background_color = nullptr;
cv::Scalar interpolated_color;
for (int i = 0; i < num_frames; ++i) {
// Set default padding color to white.
cv::Scalar padding_color_to_add = cv::Scalar(255, 255, 255);
const int64 time_ms = scene_frame_timestamps_[i];
const Timestamp timestamp(time_ms);
auto scaled_frame = absl::make_unique<ImageFrame>(
@@ -649,6 +651,7 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
interpolated_color =
cv::Scalar(std::round(k[0]), std::round(k[1]), std::round(k[2]));
background_color = &interpolated_color;
padding_color_to_add = interpolated_color;
}
auto padded_frame = absl::make_unique<ImageFrame>();
MP_RETURN_IF_ERROR(padder_->Process(
@@ -667,6 +670,7 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
.Tag(kOutputCroppedFrames)
.Add(scaled_frame.release(), timestamp);
}
padding_colors->push_back(padding_color_to_add);
}
return ::mediapipe::OkStatus();
}
@@ -171,7 +171,7 @@ class SceneCroppingCalculator : public CalculatorBase {
::mediapipe::Status FormatAndOutputCroppedFrames(
const std::vector<cv::Mat>& cropped_frames,
std::vector<cv::Rect>* render_to_locations, bool* apply_padding,
cv::Scalar* padding_color, float* vertical_fill_precent,
std::vector<cv::Scalar>* padding_colors, float* vertical_fill_percent,
CalculatorContext* cc);
// Draws and outputs visualization frames if those streams are present.
@@ -125,10 +125,13 @@ void RectUnion(const Rect& rect_to_add, Rect* rect) {
LOG(ERROR) << "Detection missing a bounding box, skipped.";
}
if (has_valid_location) {
if (!ClampRect(original_frame_width, original_frame_height, &location)
.ok()) {
LOG(ERROR) << "Invalid detection bounding box, skipped.";
continue;
}
auto* detection = processed_detections->add_detections();
*detection = original_detection;
RET_CHECK_OK(
ClampRect(original_frame_width, original_frame_height, &location));
*(detection->mutable_location()) = location;
}
}
@@ -14,8 +14,8 @@ node: {
output_stream: "LETTERBOX_PADDING:letterbox_padding"
options: {
[mediapipe.ImageTransformationCalculatorOptions.ext] {
output_width: 128
output_height: 128
output_width: 256
output_height: 256
scale_mode: FIT
}
}
@@ -38,7 +38,7 @@ node {
output_stream: "TENSORS:detection_tensors"
options: {
[mediapipe.TfLiteInferenceCalculatorOptions.ext] {
model_path: "mediapipe/models/face_detection_front.tflite"
model_path: "mediapipe/models/face_detection_back.tflite"
}
}
}
@@ -51,16 +51,16 @@ node {
options: {
[mediapipe.SsdAnchorsCalculatorOptions.ext] {
num_layers: 4
min_scale: 0.1484375
min_scale: 0.15625
max_scale: 0.75
input_size_height: 128
input_size_width: 128
input_size_height: 256
input_size_width: 256
anchor_offset_x: 0.5
anchor_offset_y: 0.5
strides: 8
strides: 16
strides: 16
strides: 16
strides: 32
strides: 32
strides: 32
aspect_ratios: 1.0
fixed_anchor_size: true
}
@@ -87,11 +87,11 @@ node {
sigmoid_score: true
score_clipping_thresh: 100.0
reverse_output_order: true
x_scale: 128.0
y_scale: 128.0
h_scale: 128.0
w_scale: 128.0
min_score_thresh: 0.6
x_scale: 256.0
y_scale: 256.0
h_scale: 256.0
w_scale: 256.0
min_score_thresh: 0.65
}
}
}
@@ -119,7 +119,7 @@ node {
output_stream: "labeled_detections"
options: {
[mediapipe.DetectionLabelIdToTextCalculatorOptions.ext] {
label_map_path: "mediapipe/models/face_detection_front_labelmap.txt"
label_map_path: "mediapipe/models/face_detection_back_labelmap.txt"
}
}
}
@@ -157,7 +157,7 @@ class DemoDataset(object):
all_shards_dataset = tf.data.Dataset.from_tensor_slices(all_shards)
cycle_length = min(16, len(all_shards))
dataset = all_shards_dataset.apply(
tf.contrib.data.parallel_interleave(
tf.data.experimental.parallel_interleave(
tf.data.TFRecordDataset,
cycle_length=cycle_length,
block_length=1,
@@ -0,0 +1,47 @@
# Copyright 2020 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
"""Example of reading a MediaSequence dataset.
"""
from absl import app
from absl import flags
from mediapipe.examples.desktop.media_sequence.demo_dataset import DemoDataset
import tensorflow as tf
FLAGS = flags.FLAGS
def main(argv):
if len(argv) > 1:
raise app.UsageError('Too many command-line arguments.')
demo_data_path = '/tmp/demo_data/'
with tf.Graph().as_default():
d = DemoDataset(demo_data_path)
dataset = d.as_dataset('test')
# implement additional processing and batching here
dataset_output = dataset.make_one_shot_iterator().get_next()
images = dataset_output['images']
labels = dataset_output['labels']
with tf.Session() as sess:
images_, labels_ = sess.run([images, labels])
print('The shape of images_ is %s' % str(images_.shape)) # pylint: disable=superfluous-parens
print('The shape of labels_ is %s' % str(labels_.shape)) # pylint: disable=superfluous-parens
if __name__ == '__main__':
app.run(main)
@@ -109,14 +109,17 @@ DEFINE_string(output_side_packets_file, "",
::mediapipe::ParseTextProtoOrDie<::mediapipe::CalculatorGraphConfig>(
calculator_graph_config_contents);
std::map<std::string, ::mediapipe::Packet> input_side_packets;
std::vector<std::string> kv_pairs =
absl::StrSplit(FLAGS_input_side_packets, ',');
for (const std::string& kv_pair : kv_pairs) {
std::vector<std::string> name_and_value = absl::StrSplit(kv_pair, '=');
RET_CHECK(name_and_value.size() == 2);
RET_CHECK(!::mediapipe::ContainsKey(input_side_packets, name_and_value[0]));
input_side_packets[name_and_value[0]] =
::mediapipe::MakePacket<std::string>(name_and_value[1]);
if (!FLAGS_input_side_packets.empty()) {
std::vector<std::string> kv_pairs =
absl::StrSplit(FLAGS_input_side_packets, ',');
for (const std::string& kv_pair : kv_pairs) {
std::vector<std::string> name_and_value = absl::StrSplit(kv_pair, '=');
RET_CHECK(name_and_value.size() == 2);
RET_CHECK(
!::mediapipe::ContainsKey(input_side_packets, name_and_value[0]));
input_side_packets[name_and_value[0]] =
::mediapipe::MakePacket<std::string>(name_and_value[1]);
}
}
LOG(INFO) << "Initialize the calculator graph.";
::mediapipe::CalculatorGraph graph;
@@ -81,7 +81,7 @@
2. Copy the baseline model [(model card)](https://drive.google.com/file/d/1xTCi9-Nm9dt2KIk8WR0dDFrIssWawyXy/view) to local.
```bash
curl -o /tmp/mediapipe/yt8m_baseline_saved_model.tar.gz data.yt8m.org/models/baseline/saved_model.tar.gz
curl -o /tmp/mediapipe/yt8m_baseline_saved_model.tar.gz http://data.yt8m.org/models/baseline/saved_model.tar.gz
tar -xvf /tmp/mediapipe/yt8m_baseline_saved_model.tar.gz -C /tmp/mediapipe
```
@@ -107,7 +107,7 @@
```bash
curl -o /tmp/mediapipe/yt8m_baseline_saved_model.tar.gz data.yt8m.org/models/baseline/saved_model.tar.gz
curl -o /tmp/mediapipe/yt8m_baseline_saved_model.tar.gz http://data.yt8m.org/models/baseline/saved_model.tar.gz
tar -xvf /tmp/mediapipe/yt8m_baseline_saved_model.tar.gz -C /tmp/mediapipe
```
@@ -136,7 +136,7 @@
2. Copy the baseline model [(model card)](https://drive.google.com/file/d/1xTCi9-Nm9dt2KIk8WR0dDFrIssWawyXy/view) to local.
```bash
curl -o /tmp/mediapipe/yt8m_baseline_saved_model.tar.gz data.yt8m.org/models/baseline/saved_model.tar.gz
curl -o /tmp/mediapipe/yt8m_baseline_saved_model.tar.gz http://data.yt8m.org/models/baseline/saved_model.tar.gz
tar -xvf /tmp/mediapipe/yt8m_baseline_saved_model.tar.gz -C /tmp/mediapipe
```