From ebb2686fb4d259ea61251ca23a4c4dc4705344e1 Mon Sep 17 00:00:00 2001 From: kinaryml Date: Sat, 22 Oct 2022 03:34:26 -0700 Subject: [PATCH] Moved OutputType and Activation to image_segmenter --- mediapipe/tasks/python/components/proto/BUILD | 24 ---------------- .../components/proto/segmenter_options.py | 28 ------------------- mediapipe/tasks/python/test/vision/BUILD | 1 - .../test/vision/image_segmenter_test.py | 5 ++-- mediapipe/tasks/python/vision/BUILD | 1 - .../tasks/python/vision/image_segmenter.py | 20 +++++++++---- 6 files changed, 17 insertions(+), 62 deletions(-) delete mode 100644 mediapipe/tasks/python/components/proto/BUILD delete mode 100644 mediapipe/tasks/python/components/proto/segmenter_options.py diff --git a/mediapipe/tasks/python/components/proto/BUILD b/mediapipe/tasks/python/components/proto/BUILD deleted file mode 100644 index ef37d9270..000000000 --- a/mediapipe/tasks/python/components/proto/BUILD +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2022 The MediaPipe Authors. All Rights Reserved. -# -# 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. - -# Placeholder for internal Python strict library compatibility macro. - -package(default_visibility = ["//mediapipe/tasks:internal"]) - -licenses(["notice"]) - -py_library( - name = "segmenter_options", - srcs = ["segmenter_options.py"] -) diff --git a/mediapipe/tasks/python/components/proto/segmenter_options.py b/mediapipe/tasks/python/components/proto/segmenter_options.py deleted file mode 100644 index 5f8e22777..000000000 --- a/mediapipe/tasks/python/components/proto/segmenter_options.py +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2022 The TensorFlow Authors. All Rights Reserved. -# -# 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. -"""Segmenter options data class.""" - -import enum - - -class OutputType(enum.Enum): - UNSPECIFIED = 0 - CATEGORY_MASK = 1 - CONFIDENCE_MASK = 2 - - -class Activation(enum.Enum): - NONE = 0 - SIGMOID = 1 - SOFTMAX = 2 diff --git a/mediapipe/tasks/python/test/vision/BUILD b/mediapipe/tasks/python/test/vision/BUILD index 63fc56b42..321b33a61 100644 --- a/mediapipe/tasks/python/test/vision/BUILD +++ b/mediapipe/tasks/python/test/vision/BUILD @@ -48,7 +48,6 @@ py_test( "//mediapipe/python:_framework_bindings", "//mediapipe/tasks/python/core:base_options", "//mediapipe/tasks/python/test:test_utils", - "//mediapipe/tasks/python/components/proto:segmenter_options", "//mediapipe/tasks/python/vision:image_segmenter", "//mediapipe/tasks/python/vision/core:vision_task_running_mode", "@absl_py//absl/testing:parameterized", diff --git a/mediapipe/tasks/python/test/vision/image_segmenter_test.py b/mediapipe/tasks/python/test/vision/image_segmenter_test.py index 9b4e2c4b4..3fa01e62f 100644 --- a/mediapipe/tasks/python/test/vision/image_segmenter_test.py +++ b/mediapipe/tasks/python/test/vision/image_segmenter_test.py @@ -24,7 +24,6 @@ from absl.testing import parameterized from mediapipe.python._framework_bindings import image as image_module from mediapipe.python._framework_bindings import image_frame -from mediapipe.tasks.python.components.proto import segmenter_options from mediapipe.tasks.python.core import base_options as base_options_module from mediapipe.tasks.python.test import test_utils from mediapipe.tasks.python.vision import image_segmenter @@ -33,8 +32,8 @@ from mediapipe.tasks.python.vision.core import vision_task_running_mode _BaseOptions = base_options_module.BaseOptions _Image = image_module.Image _ImageFormat = image_frame.ImageFormat -_OutputType = segmenter_options.OutputType -_Activation = segmenter_options.Activation +_OutputType = image_segmenter.OutputType +_Activation = image_segmenter.Activation _ImageSegmenter = image_segmenter.ImageSegmenter _ImageSegmenterOptions = image_segmenter.ImageSegmenterOptions _RUNNING_MODE = vision_task_running_mode.VisionTaskRunningMode diff --git a/mediapipe/tasks/python/vision/BUILD b/mediapipe/tasks/python/vision/BUILD index 863312e4c..da9072f18 100644 --- a/mediapipe/tasks/python/vision/BUILD +++ b/mediapipe/tasks/python/vision/BUILD @@ -48,7 +48,6 @@ py_library( "//mediapipe/python:packet_getter", "//mediapipe/tasks/cc/components/proto:segmenter_options_py_pb2", "//mediapipe/tasks/cc/vision/image_segmenter/proto:image_segmenter_options_py_pb2", - "//mediapipe/tasks/python/components/proto:segmenter_options", "//mediapipe/tasks/python/core:base_options", "//mediapipe/tasks/python/core:optional_dependencies", "//mediapipe/tasks/python/core:task_info", diff --git a/mediapipe/tasks/python/vision/image_segmenter.py b/mediapipe/tasks/python/vision/image_segmenter.py index e7278eb96..aea5a8554 100644 --- a/mediapipe/tasks/python/vision/image_segmenter.py +++ b/mediapipe/tasks/python/vision/image_segmenter.py @@ -15,6 +15,7 @@ import dataclasses from typing import Callable, List, Mapping, Optional +import enum from mediapipe.python import packet_creator from mediapipe.python import packet_getter @@ -23,7 +24,6 @@ from mediapipe.python._framework_bindings import packet from mediapipe.python._framework_bindings import task_runner from mediapipe.tasks.cc.components.proto import segmenter_options_pb2 from mediapipe.tasks.cc.vision.image_segmenter.proto import image_segmenter_options_pb2 -from mediapipe.tasks.python.components.proto import segmenter_options from mediapipe.tasks.python.core import base_options as base_options_module from mediapipe.tasks.python.core import task_info as task_info_module from mediapipe.tasks.python.core.optional_dependencies import doc_controls @@ -33,8 +33,6 @@ from mediapipe.tasks.python.vision.core import vision_task_running_mode _BaseOptions = base_options_module.BaseOptions _SegmenterOptionsProto = segmenter_options_pb2.SegmenterOptions _ImageSegmenterOptionsProto = image_segmenter_options_pb2.ImageSegmenterOptions -_OutputType = segmenter_options.OutputType -_Activation = segmenter_options.Activation _RunningMode = vision_task_running_mode.VisionTaskRunningMode _TaskInfo = task_info_module.TaskInfo _TaskRunner = task_runner.TaskRunner @@ -48,6 +46,18 @@ _TASK_GRAPH_NAME = 'mediapipe.tasks.vision.ImageSegmenterGraph' _MICRO_SECONDS_PER_MILLISECOND = 1000 +class OutputType(enum.Enum): + UNSPECIFIED = 0 + CATEGORY_MASK = 1 + CONFIDENCE_MASK = 2 + + +class Activation(enum.Enum): + NONE = 0 + SIGMOID = 1 + SOFTMAX = 2 + + @dataclasses.dataclass class ImageSegmenterOptions: """Options for the image segmenter task. @@ -69,8 +79,8 @@ class ImageSegmenterOptions: """ base_options: _BaseOptions running_mode: _RunningMode = _RunningMode.IMAGE - output_type: Optional[_OutputType] = _OutputType.CATEGORY_MASK - activation: Optional[_Activation] = _Activation.NONE + output_type: Optional[OutputType] = OutputType.CATEGORY_MASK + activation: Optional[Activation] = Activation.NONE result_callback: Optional[ Callable[[List[image_module.Image], image_module.Image, int], None]] = None