mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge pull request #28588 from abhishek-gola:ORT_GPU_wrapper
Added OnnxRuntime GPU wrapper #28588 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -129,11 +129,13 @@ def apply_modnet(args, model, image):
|
||||
image, args.scale, (args.width, args.height), args.mean, swapRB=args.rgb
|
||||
)
|
||||
model.setInput(inp)
|
||||
t0 = cv.getTickCount()
|
||||
out = model.forward()
|
||||
t = (cv.getTickCount() - t0) / cv.getTickFrequency()
|
||||
alpha_mask = postprocess_output(image, out)
|
||||
alpha_3ch = cv.merge([alpha_mask / 255.0, alpha_mask / 255.0, alpha_mask / 255.0])
|
||||
composite = (image.astype(np.float32) * alpha_3ch).astype(np.uint8)
|
||||
return alpha_mask, composite
|
||||
return alpha_mask, composite, t
|
||||
|
||||
|
||||
def main(func_args=None):
|
||||
@@ -156,10 +158,8 @@ def main(func_args=None):
|
||||
args.model = findModel(args.model, args.sha1)
|
||||
net = loadModel(args, engine)
|
||||
|
||||
alpha_mask, composite = apply_modnet(args, net, image)
|
||||
|
||||
t, _ = net.getPerfProfile()
|
||||
label = "Inference time: %.2f ms" % (t * 1000.0 / cv.getTickFrequency())
|
||||
alpha_mask, composite, t = apply_modnet(args, net, image)
|
||||
label = "Inference time: %.2f ms" % (t * 1000.0)
|
||||
|
||||
draw_label(image, label, (0, 255, 0))
|
||||
draw_label(alpha_mask, label, (255, 255, 255))
|
||||
|
||||
@@ -135,7 +135,9 @@ def main(func_args=None):
|
||||
|
||||
# Run a model
|
||||
net.setInput(blob)
|
||||
t0 = cv.getTickCount()
|
||||
out = net.forward()
|
||||
t = (cv.getTickCount() - t0) / cv.getTickFrequency()
|
||||
|
||||
(h, w, _) = frame.shape
|
||||
roi_rows = min(300, h)
|
||||
@@ -143,8 +145,7 @@ def main(func_args=None):
|
||||
frame[:roi_rows,:roi_cols,:] >>= 1
|
||||
|
||||
# Put efficiency information.
|
||||
t, _ = net.getPerfProfile()
|
||||
label = 'Inference time: %.1f ms' % (t * 1000.0 / cv.getTickFrequency())
|
||||
label = 'Inference time: %.1f ms' % (t * 1000.0)
|
||||
cv.putText(frame, label, (15, 30), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0))
|
||||
|
||||
# Print predicted classes.
|
||||
|
||||
@@ -99,10 +99,11 @@ def loadModel(args, engine):
|
||||
return net
|
||||
|
||||
def apply_dexined(model, image):
|
||||
t0 = cv.getTickCount()
|
||||
out = model.forward()
|
||||
t = (cv.getTickCount() - t0) / cv.getTickFrequency()
|
||||
result,_ = post_processing(out, image.shape[:2])
|
||||
t, _ = model.getPerfProfile()
|
||||
label = 'Inference time: %.2f ms' % (t * 1000.0 / cv.getTickFrequency())
|
||||
label = 'Inference time: %.2f ms' % (t * 1000.0)
|
||||
cv.putText(image, label, (0, 15), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255))
|
||||
cv.putText(result, label, (0, 15), cv.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255))
|
||||
cv.imshow("Output", result)
|
||||
|
||||
@@ -34,14 +34,14 @@ while cv.waitKey(1) < 0:
|
||||
swapRB=True, crop=False)
|
||||
|
||||
net.setInput(inp)
|
||||
t0 = cv.getTickCount()
|
||||
out = net.forward()
|
||||
t = (cv.getTickCount() - t0) / cv.getTickFrequency()
|
||||
|
||||
out = out.reshape(3, out.shape[2], out.shape[3])
|
||||
out = out.transpose(1, 2, 0)
|
||||
|
||||
t, _ = net.getPerfProfile()
|
||||
freq = cv.getTickFrequency() / 1000
|
||||
print(t / freq, 'ms')
|
||||
print('%.2f ms' % (t * 1000.0))
|
||||
|
||||
if args.median_filter:
|
||||
out = cv.medianBlur(out, args.median_filter)
|
||||
|
||||
@@ -105,7 +105,9 @@ while cv.waitKey(1) < 0:
|
||||
|
||||
# NOTE: In OpenCV 5.0, requesting 'detection_out_final' will fail if the .pbtxt
|
||||
# does not register it as an output. See file header for details.
|
||||
t0 = cv.getTickCount()
|
||||
boxes, masks = net.forward(['detection_out_final', 'detection_masks'])
|
||||
t = (cv.getTickCount() - t0) / cv.getTickFrequency()
|
||||
|
||||
numClasses = masks.shape[1]
|
||||
numDetections = boxes.shape[2]
|
||||
@@ -148,8 +150,7 @@ while cv.waitKey(1) < 0:
|
||||
drawBox(*box)
|
||||
|
||||
# Put efficiency information.
|
||||
t, _ = net.getPerfProfile()
|
||||
label = 'Inference time: %.2f ms' % (t * 1000.0 / cv.getTickFrequency())
|
||||
label = 'Inference time: %.2f ms' % (t * 1000.0)
|
||||
cv.putText(frame, label, (0, 15), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0))
|
||||
|
||||
showLegend(classes)
|
||||
|
||||
@@ -367,8 +367,11 @@ int main(int argc, char** argv)
|
||||
}
|
||||
preprocess(frame, net, Size(inpWidth, inpHeight));
|
||||
|
||||
TickMeter tickMeter;
|
||||
vector<Mat> outs;
|
||||
tickMeter.start();
|
||||
net.forward(outs, net.getUnconnectedOutLayersNames());
|
||||
tickMeter.stop();
|
||||
|
||||
classIds.clear();
|
||||
confidences.clear();
|
||||
@@ -378,13 +381,10 @@ int main(int argc, char** argv)
|
||||
|
||||
drawPred(classIds, confidences, boxes, frame, sans, stdSize, stdWeight, stdImgSize, stdThickness);
|
||||
|
||||
vector<double> layersTimes;
|
||||
int imgWidth = max(frame.rows, frame.cols);
|
||||
int size = static_cast<int>((stdSize * imgWidth) / (stdImgSize * 1.5));
|
||||
int weight = static_cast<int>((stdWeight * imgWidth) / (stdImgSize * 1.5));
|
||||
double freq = getTickFrequency() / 1000;
|
||||
double t = net.getPerfProfile(layersTimes) / freq;
|
||||
string label = format("FPS: %.2f", 1000/t);
|
||||
string label = format("FPS: %.2f", 1000.0 / tickMeter.getTimeMilli());
|
||||
putText(frame, label, Point(0, size), Scalar(0, 255, 0), sans, size, weight);
|
||||
imshow(kWinName, frame);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,9 @@ while cv.waitKey(1) < 0:
|
||||
inp = cv.dnn.blobFromImage(frame, inScale, (inWidth, inHeight),
|
||||
(0, 0, 0), swapRB=False, crop=False)
|
||||
net.setInput(inp)
|
||||
t0 = cv.getTickCount()
|
||||
out = net.forward()
|
||||
t = (cv.getTickCount() - t0) / cv.getTickFrequency()
|
||||
|
||||
assert(len(BODY_PARTS) <= out.shape[1])
|
||||
|
||||
@@ -115,8 +117,6 @@ while cv.waitKey(1) < 0:
|
||||
cv.ellipse(frame, points[idFrom], (3, 3), 0, 0, 360, (0, 0, 255), cv.FILLED)
|
||||
cv.ellipse(frame, points[idTo], (3, 3), 0, 0, 360, (0, 0, 255), cv.FILLED)
|
||||
|
||||
t, _ = net.getPerfProfile()
|
||||
freq = cv.getTickFrequency() / 1000
|
||||
cv.putText(frame, '%.2fms' % (t / freq), (10, 20), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0))
|
||||
cv.putText(frame, '%.2f ms' % (t * 1000.0), (10, 20), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0))
|
||||
|
||||
cv.imshow('OpenPose using OpenCV', frame)
|
||||
|
||||
@@ -132,12 +132,13 @@ def apply_super_resolution(net, image, args):
|
||||
)
|
||||
|
||||
net.setInput(blob)
|
||||
t0 = cv.getTickCount()
|
||||
output = net.forward()
|
||||
t = (cv.getTickCount() - t0) / cv.getTickFrequency()
|
||||
|
||||
result = postprocess_output(output, args, original_shape)
|
||||
|
||||
t, _ = net.getPerfProfile()
|
||||
label = "Inference time: %.2f ms" % (t * 1000.0 / cv.getTickFrequency())
|
||||
label = "Inference time: %.2f ms" % (t * 1000.0)
|
||||
cv.putText(result, label, (10, 30), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user