Skip to content

Commit

Permalink
tensorflow-lite: cleanup dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Mar 1, 2023
1 parent 694c195 commit 3c237ea
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions plugins/tensorflow-lite/src/predict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,36 +479,27 @@ def run_detection_crop(self, detection_session: DetectionSession, sample: RawIma
return ret

def run_detection_gstsample(self, detection_session: PredictSession, gstsample, settings: Any, src_size, convert_to_src_size) -> Tuple[ObjectsDetected, Image.Image]:
if False:
# pycoral supports fast path with gst sample directly which can be used if detection snapshots
# are not needed.
with self.mutex:
gst_buffer = gstsample.get_buffer()
run_inference(self.interpreter, gst_buffer)
objs = detect.get_objects(
self.interpreter, score_threshold=score_threshold)
else:
caps = gstsample.get_caps()
# can't trust the width value, compute the stride
height = caps.get_structure(0).get_value('height')
width = caps.get_structure(0).get_value('width')
gst_buffer = gstsample.get_buffer()
result, info = gst_buffer.map(Gst.MapFlags.READ)
if not result:
return
try:
image = detection_session.image
detection_session.image = None

if image and (image.width != width or image.height != height):
image.close()
image = None
if image:
image.frombytes(bytes(info.data))
else:
image = Image.frombuffer('RGB', (width, height), bytes(info.data))
finally:
gst_buffer.unmap(info)
caps = gstsample.get_caps()
# can't trust the width value, compute the stride
height = caps.get_structure(0).get_value('height')
width = caps.get_structure(0).get_value('width')
gst_buffer = gstsample.get_buffer()
result, info = gst_buffer.map(Gst.MapFlags.READ)
if not result:
return
try:
image = detection_session.image
detection_session.image = None

if image and (image.width != width or image.height != height):
image.close()
image = None
if image:
image.frombytes(bytes(info.data))
else:
image = Image.frombuffer('RGB', (width, height), bytes(info.data))
finally:
gst_buffer.unmap(info)

return self.run_detection_image(detection_session, image, settings, src_size, convert_to_src_size)

Expand Down

0 comments on commit 3c237ea

Please sign in to comment.