Updated implementation and tests

This commit is contained in:
kinaryml 2022-09-29 02:45:20 -07:00
parent 4204c8b8a9
commit b04af0cafa
6 changed files with 37 additions and 8 deletions

View File

@ -86,7 +86,7 @@ cc_library(
name = "builtin_task_graphs", name = "builtin_task_graphs",
deps = [ deps = [
"//mediapipe/tasks/cc/vision/object_detector:object_detector_graph", "//mediapipe/tasks/cc/vision/object_detector:object_detector_graph",
"//mediapipe/tasks/cc/vision/image_classification:image_classifier_graph", "//mediapipe/tasks/cc/vision/image_classifier:image_classifier_graph",
], ],
) )

View File

@ -0,0 +1,29 @@
# 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 = "classifier_options",
srcs = ["classifier_options.py"],
deps = [
"//mediapipe/tasks/cc/components/proto:classifier_options_py_pb2",
"//mediapipe/tasks/python/core:optional_dependencies",
],
)

View File

@ -99,11 +99,11 @@ class ImageClassifierTest(parameterized.TestCase):
expected_classification_result): expected_classification_result):
# Creates classifier. # Creates classifier.
if model_file_type is ModelFileType.FILE_NAME: if model_file_type is ModelFileType.FILE_NAME:
base_options = _BaseOptions(file_name=self.model_path) base_options = _BaseOptions(model_asset_path=self.model_path)
elif model_file_type is ModelFileType.FILE_CONTENT: elif model_file_type is ModelFileType.FILE_CONTENT:
with open(self.model_path, 'rb') as f: with open(self.model_path, 'rb') as f:
model_content = f.read() model_content = f.read()
base_options = _BaseOptions(file_content=model_content) base_options = _BaseOptions(model_asset_buffer=model_content)
else: else:
# Should never happen # Should never happen
raise ValueError('model_file_type is invalid.') raise ValueError('model_file_type is invalid.')

View File

@ -46,8 +46,8 @@ py_library(
"//mediapipe/python:_framework_bindings", "//mediapipe/python:_framework_bindings",
"//mediapipe/python:packet_creator", "//mediapipe/python:packet_creator",
"//mediapipe/python:packet_getter", "//mediapipe/python:packet_getter",
"//mediapipe/tasks/cc/vision/image_classification:image_classifier_options_py_pb2", "//mediapipe/tasks/cc/vision/image_classifier/proto:image_classifier_options_py_pb2",
"//mediapipe/tasks/python/components:classifier_options", "//mediapipe/tasks/python/components/proto:classifier_options",
"//mediapipe/tasks/python/components/containers:classifications", "//mediapipe/tasks/python/components/containers:classifications",
"//mediapipe/tasks/python/core:base_options", "//mediapipe/tasks/python/core:base_options",
"//mediapipe/tasks/python/core:optional_dependencies", "//mediapipe/tasks/python/core:optional_dependencies",

View File

@ -21,8 +21,8 @@ from mediapipe.python import packet_getter
from mediapipe.python._framework_bindings import image as image_module from mediapipe.python._framework_bindings import image as image_module
from mediapipe.python._framework_bindings import packet as packet_module from mediapipe.python._framework_bindings import packet as packet_module
from mediapipe.python._framework_bindings import task_runner as task_runner_module from mediapipe.python._framework_bindings import task_runner as task_runner_module
from mediapipe.tasks.cc.vision.image_classification import image_classifier_options_pb2 from mediapipe.tasks.cc.vision.image_classifier.proto import image_classifier_options_pb2
from mediapipe.tasks.python.components import classifier_options from mediapipe.tasks.python.components.proto import classifier_options
from mediapipe.tasks.python.components.containers import classifications as classifications_module from mediapipe.tasks.python.components.containers import classifications as classifications_module
from mediapipe.tasks.python.core import base_options as base_options_module 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 import task_info as task_info_module
@ -104,7 +104,7 @@ class ImageClassifier(base_vision_task_api.BaseVisionTaskApi):
file such as invalid file path. file such as invalid file path.
RuntimeError: If other types of error occurred. RuntimeError: If other types of error occurred.
""" """
base_options = _BaseOptions(file_name=model_path) base_options = _BaseOptions(model_asset_path=model_path)
options = ImageClassifierOptions( options = ImageClassifierOptions(
base_options=base_options, running_mode=_RunningMode.IMAGE) base_options=base_options, running_mode=_RunningMode.IMAGE)
return cls.create_from_options(options) return cls.create_from_options(options)