Fifo.read_elem()
Info | Value |
---|---|
Package | mvnc |
Module | mvncapi |
Version | 2.0 |
See also | Fifo, Fifo.write_elem(), Graph.queue_inference_With_fifo_elem(), Graph.queue_inference() |
Overview
This method returns an element from the Fifo, usually the result of an inference, along with the associated user-defined object that was passed to Fifo.write_elem() or Graph.queue_inference_with_fifo_elem().
This will also remove the element from the queue.
Syntax
output_tensor, user_obj = fifo.read_elem()
Parameters
None.
Return
tensor, user_obj
A numpy.ndarray with output tensor data of the type specified by the FifoDataType option, and the user-defined data that was passed to Fifo.write_elem() or Graph.queue_inference_with_fifo_elem().
Raises
Exception with a status code from Status if underlying function calls return a status other than Status.OK.
Notes
- The FifoType set during initialization must allow read access for the API.
- The Fifo cannot be written to or read from until it is allocated with Graph.allocate_with_fifos() or Fifo.allocate(). The FifoState must be ALLOCATED.
- The API can only read each element once even if FifoOption.RW_CONSUMER_COUNT is greater than 1.
- This is a blocking call if FifoOption.RW_DONT_BLOCK is false. If the Fifo is empty this method will not return until there is an element to read.
- You can check the current fill level of the Fifo with Fifo.get_option() for FifoOption.RO_READ_FILL_LEVEL.
- After an inference is queued there is a delay while device communication occurs and the inference is performed before the element is removed from the input Fifo and placed into the output Fifo.
Example
from mvnc import mvncapi
#
# Open a Device, create a Graph, and load graph data from file...
#
# Allocate the Graph and create and allocate two associate Fifos for input and output
input_fifo, output_fifo = graph.allocate_with_fifos(device, graph_buffer)
#
# Write elements to an input Fifo with Fifo.write_elem() and initiate inferences with Graph.queue_inference()
#
# Read the result to the output Fifo
result_tensor, user_obj = output_fifo.read_elem()
#
# Do something with the result...
#
# Destroy the Fifos
input_fifo.destroy()
output_fifo.destroy()
#
# Perform other clean up...
#