Project import generated by Copybara.
GitOrigin-RevId: 8e1da4611d93ccb7d9674713157d43be0348d98f
This commit is contained in:
@@ -254,11 +254,11 @@ class SolutionBase:
|
||||
for stream_name in self._output_stream_type_info.keys():
|
||||
self._graph.observe_output_stream(stream_name, callback, True)
|
||||
|
||||
input_side_packets = {
|
||||
self._input_side_packets = {
|
||||
name: self._make_packet(self._side_input_type_info[name], data)
|
||||
for name, data in (side_inputs or {}).items()
|
||||
}
|
||||
self._graph.start_run(input_side_packets)
|
||||
self._graph.start_run(self._input_side_packets)
|
||||
|
||||
# TODO: Use "inspect.Parameter" to fetch the input argument names and
|
||||
# types from "_input_stream_type_info" and then auto generate the process
|
||||
@@ -353,6 +353,12 @@ class SolutionBase:
|
||||
self._input_stream_type_info = None
|
||||
self._output_stream_type_info = None
|
||||
|
||||
def reset(self) -> None:
|
||||
"""Resets the graph for another run."""
|
||||
if self._graph:
|
||||
self._graph.close()
|
||||
self._graph.start_run(self._input_side_packets)
|
||||
|
||||
def _initialize_graph_interface(
|
||||
self,
|
||||
validated_graph: validated_graph_config.ValidatedGraphConfig,
|
||||
|
||||
@@ -298,6 +298,56 @@ class SolutionBaseTest(parameterized.TestCase):
|
||||
'ImageTransformation.output_height': 0
|
||||
})
|
||||
|
||||
@parameterized.named_parameters(('graph_without_side_packets', """
|
||||
input_stream: 'image_in'
|
||||
output_stream: 'image_out'
|
||||
node {
|
||||
calculator: 'ImageTransformationCalculator'
|
||||
input_stream: 'IMAGE:image_in'
|
||||
output_stream: 'IMAGE:transformed_image_in'
|
||||
}
|
||||
node {
|
||||
calculator: 'ImageTransformationCalculator'
|
||||
input_stream: 'IMAGE:transformed_image_in'
|
||||
output_stream: 'IMAGE:image_out'
|
||||
}
|
||||
""", None), ('graph_with_side_packets', """
|
||||
input_stream: 'image_in'
|
||||
input_side_packet: 'allow_signal'
|
||||
input_side_packet: 'rotation_degrees'
|
||||
output_stream: 'image_out'
|
||||
node {
|
||||
calculator: 'ImageTransformationCalculator'
|
||||
input_stream: 'IMAGE:image_in'
|
||||
input_side_packet: 'ROTATION_DEGREES:rotation_degrees'
|
||||
output_stream: 'IMAGE:transformed_image_in'
|
||||
}
|
||||
node {
|
||||
calculator: 'GateCalculator'
|
||||
input_stream: 'transformed_image_in'
|
||||
input_side_packet: 'ALLOW:allow_signal'
|
||||
output_stream: 'image_out_to_transform'
|
||||
}
|
||||
node {
|
||||
calculator: 'ImageTransformationCalculator'
|
||||
input_stream: 'IMAGE:image_out_to_transform'
|
||||
input_side_packet: 'ROTATION_DEGREES:rotation_degrees'
|
||||
output_stream: 'IMAGE:image_out'
|
||||
}""", {
|
||||
'allow_signal': True,
|
||||
'rotation_degrees': 0
|
||||
}))
|
||||
def test_solution_reset(self, text_config, side_inputs):
|
||||
config_proto = text_format.Parse(text_config,
|
||||
calculator_pb2.CalculatorGraphConfig())
|
||||
input_image = np.arange(27, dtype=np.uint8).reshape(3, 3, 3)
|
||||
with solution_base.SolutionBase(
|
||||
graph_config=config_proto, side_inputs=side_inputs) as solution:
|
||||
for _ in range(20):
|
||||
outputs = solution.process(input_image)
|
||||
self.assertTrue(np.array_equal(input_image, outputs.image_out))
|
||||
solution.reset()
|
||||
|
||||
def _process_and_verify(self,
|
||||
config_proto,
|
||||
side_inputs=None,
|
||||
|
||||
@@ -26,7 +26,7 @@ import numpy.testing as npt
|
||||
from mediapipe.python.solutions import objectron as mp_objectron
|
||||
|
||||
TEST_IMAGE_PATH = 'mediapipe/python/solutions/testdata'
|
||||
DIFF_THRESHOLD = 35 # pixels
|
||||
DIFF_THRESHOLD = 30 # pixels
|
||||
EXPECTED_BOX_COORDINATES_PREDICTION = [[[236, 413], [408, 474], [135, 457],
|
||||
[383, 505], [80, 478], [408, 345],
|
||||
[130, 347], [384, 355], [72, 353]],
|
||||
|
||||
Reference in New Issue
Block a user