-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1203 from luxonis/v3_benchmark_nodes
Benchmark nodes
- Loading branch information
Showing
21 changed files
with
498 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env python3 | ||
import depthai as dai | ||
import time | ||
|
||
# Create pipeline | ||
with dai.Pipeline() as pipeline: | ||
# Create the nodes | ||
cam = pipeline.create(dai.node.Camera).build() | ||
benchmarkIn = pipeline.create(dai.node.BenchmarkIn) | ||
# benchmarkIn.setRunOnHost(True) # The node can also run on host and include the transfer limitation, default is False | ||
output = cam.requestFullResolutionOutput() | ||
output.link(benchmarkIn.input) | ||
|
||
pipeline.start() | ||
while pipeline.isRunning(): | ||
time.sleep(1) # Let the logger print out the FPS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import depthai as dai | ||
import numpy as np | ||
|
||
|
||
# First prepare the model for benchmarking | ||
device = dai.Device() | ||
modelPath = dai.getModelFromZoo(dai.NNModelDescription("yolov6-nano", platform=device.getPlatformAsString())) | ||
modelArhive = dai.NNArchive(modelPath) | ||
inputSize = modelArhive.getInputSize() | ||
type = modelArhive.getConfig().model.inputs[0].preprocessing.daiType | ||
|
||
if type: | ||
try: | ||
frameType = dai.ImgFrame.Type.__getattribute__(type) | ||
except AttributeError: | ||
type = None | ||
|
||
if not type: | ||
if device.getPlatform() == dai.Platform.RVC2: | ||
frameType = dai.ImgFrame.Type.BGR888p | ||
else: | ||
frameType = dai.ImgFrame.Type.BGR888i | ||
|
||
|
||
# Construct the input (white) image for benchmarking | ||
img = np.ones((inputSize[1], inputSize[0], 3), np.uint8) * 255 | ||
inputFrame = dai.ImgFrame() | ||
inputFrame.setCvFrame(img, frameType) | ||
|
||
with dai.Pipeline(device) as p: | ||
benchmarkOut = p.create(dai.node.BenchmarkOut) | ||
benchmarkOut.setRunOnHost(False) # The node can run on host or on device | ||
benchmarkOut.setFps(-1) # As fast as possible | ||
|
||
neuralNetwork = p.create(dai.node.NeuralNetwork).build(benchmarkOut.out, modelArhive) | ||
|
||
benchmarkIn = p.create(dai.node.BenchmarkIn) | ||
benchmarkIn.setRunOnHost(False) # The node can run on host or on device | ||
benchmarkIn.sendReportEveryNMessages(100) | ||
benchmarkIn.logReportsAsWarnings(False) | ||
neuralNetwork.out.link(benchmarkIn.input) | ||
|
||
outputQueue = benchmarkIn.report.createOutputQueue() | ||
inputQueue = benchmarkOut.input.createInputQueue() | ||
|
||
p.start() | ||
inputQueue.send(inputFrame) # Send the input image only once | ||
while p.isRunning(): | ||
benchmarkReport = outputQueue.get() | ||
assert isinstance(benchmarkReport, dai.BenchmarkReport) | ||
print(f"FPS is {benchmarkReport.fps}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import depthai as dai | ||
|
||
with dai.Pipeline(createImplicitDevice=False) as p: | ||
# Create a BenchmarkOut node | ||
# It will listen on the input to get the first message and then send it out at a specified rate | ||
# The node sends the same message out (creates new pointers), not deep copies. | ||
benchmarkOut = p.create(dai.node.BenchmarkOut) | ||
benchmarkOut.setRunOnHost(True) # The node can run on host or on device | ||
benchmarkOut.setFps(30) | ||
|
||
# Create a BenchmarkIn node | ||
# This node is receiving the messages on the input and measuring the FPS and latency. | ||
# In the case that the input is with BenchmarkOut, the latency measurement is not always possible, as the message is not deep copied, | ||
# which means that the timestamps stay the same and latency virtually increases over time. | ||
benchmarkIn = p.create(dai.node.BenchmarkIn) | ||
benchmarkIn.setRunOnHost(True) # The node can run on host or on device | ||
benchmarkIn.sendReportEveryNMessages(100) | ||
|
||
benchmarkOut.out.link(benchmarkIn.input) | ||
outputQueue = benchmarkIn.report.createOutputQueue() | ||
inputQueue = benchmarkOut.input.createInputQueue() | ||
|
||
p.start() | ||
imgFrame = dai.ImgFrame() | ||
inputQueue.send(imgFrame) | ||
while p.isRunning(): | ||
benchmarkReport = outputQueue.get() | ||
assert isinstance(benchmarkReport, dai.BenchmarkReport) | ||
print(f"FPS is {benchmarkReport.fps}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "depthai/common/ProcessorType.hpp" | ||
#include "depthai/common/optional.hpp" | ||
#include "depthai/pipeline/datatype/DatatypeEnum.hpp" | ||
#include "depthai/properties/Properties.hpp" | ||
|
||
namespace dai { | ||
|
||
/** | ||
* Specify benchmark properties (number of messages to send/receive) | ||
*/ | ||
struct BenchmarkInProperties : PropertiesSerializable<Properties, BenchmarkInProperties> { | ||
/** | ||
* Specify how many messages to measure for each report | ||
*/ | ||
uint32_t reportEveryNMessages = 50; | ||
|
||
/** | ||
* Specify whether the latenices are attached to the report individually | ||
*/ | ||
bool attachLatencies = false; | ||
|
||
/** | ||
* Send the reports also as logger warnings | ||
*/ | ||
bool logReportsAsWarnings = true; | ||
}; | ||
|
||
DEPTHAI_SERIALIZE_EXT(BenchmarkInProperties, reportEveryNMessages, attachLatencies, logReportsAsWarnings); | ||
|
||
} // namespace dai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.