SequentialStream使用样例
示例代码
from mindx.sdk.stream import BufferInput
from mindx.sdk.stream import PluginNode, SequentialStream
props0 = {
"modelPath":"../models/yolov3/yolov3_tf_bs1_fp16.om",
"postProcessConfigPath":"../models/yolov3/yolov3_tf_bs1_fp16.cfg",
"labelPath":"../models/yolov3/yolov3.names",
"postProcessLibPath":"libMpYOLOv3PostProcessor.so"
}
props1 = {
"modelPath":"../models/resnet50/resnet50_aipp_tf.om",
"postProcessConfigPath":"../models/resnet50/resnet50_aipp_tf.cfg",
"labelPath":"../models/resnet50/resnet50_clsidx_to_labels.names",
"postProcessLibPath":"libresnet50postprocessor.so"
}
props2 = {
"outputDataKeys":"mxpi_modelinfer0,mxpi_modelinfer1"
}
try:
s=SequentialStream("stream")
s.set_device_id("0")
s.add(PluginNode("appsrc"))
s.add(PluginNode("mxpi_imagedecoder"))
s.add(PluginNode("mxpi_imageresize"))
s.add(PluginNode("mxpi_modelinfer", props0))
s.add(PluginNode("mxpi_imagecrop"))
s.add(PluginNode("mxpi_imageresize"))
s.add(PluginNode("mxpi_modelinfer", props1))
s.add(PluginNode("mxpi_dataserialize", props2))
s.add(PluginNode("appsink"))
s.build()
bufferInput = BufferInput()
with open("test.jpg", 'rb') as rf:
bufferInput.data = rf.read()
s.send("appsrc0", [], bufferInput)
result = s.get_result("appsink0", [], 3000)
print("result:", result.buffer_output.data)
except Exception as e:
print(e)
父主题: 样例演示