forked from shouxieai/tensorRT_Pro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dujw
committed
Jul 16, 2022
1 parent
61c494f
commit 6420525
Showing
19 changed files
with
203 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
import cv2 | ||
import numpy as np | ||
import pytrt as tp | ||
|
||
# change current workspace | ||
os.chdir("../workspace/") | ||
|
||
# 如果执行出错,请删掉 ~/.pytrt 的缓存模型 | ||
# rm -rf ~/.pytrt,重新下载 | ||
device_id = 7 | ||
engine_file = "yolov7.fp32.trtmodel" | ||
if not os.path.exists(engine_file): | ||
tp.compile_onnx_to_file(5, tp.onnx_hub("yolov7"), engine_file, device_id=device_id) | ||
|
||
yolo = tp.Yolo(engine_file, type=tp.YoloType.V5, device_id=device_id) | ||
image = cv2.imread("inference/car.jpg") | ||
bboxes = yolo.commit(image).get() | ||
print(f"{len(bboxes)} objects") | ||
print(bboxes) | ||
|
||
for box in bboxes: | ||
left, top, right, bottom = map(int, [box.left, box.top, box.right, box.bottom]) | ||
cv2.rectangle(image, (left, top), (right, bottom), tp.random_color(box.class_label), 5) | ||
|
||
os.makedirs("single_inference", exist_ok=True) | ||
saveto = "single_inference/yolov5.car.jpg" | ||
print(f"Save to {saveto}") | ||
|
||
cv2.imwrite(saveto, image) | ||
|
||
|
||
try: | ||
import torch | ||
|
||
image = cv2.imread("inference/car.jpg") | ||
device = 0 | ||
|
||
gpu_image = torch.from_numpy(image).to(device) | ||
bboxes = yolo.commit_gpu( | ||
pimage = gpu_image.data_ptr(), | ||
width = image.shape[1], | ||
height = image.shape[0], | ||
device_id = device, | ||
imtype = tp.ImageType.GPUBGR, | ||
stream = torch.cuda.current_stream().cuda_stream | ||
).get() | ||
print(f"{len(bboxes)} objects") | ||
print(bboxes) | ||
|
||
for box in bboxes: | ||
left, top, right, bottom = map(int, [box.left, box.top, box.right, box.bottom]) | ||
cv2.rectangle(image, (left, top), (right, bottom), tp.random_color(box.class_label), 5) | ||
|
||
os.makedirs("single_inference", exist_ok=True) | ||
saveto = "single_inference/yolov7-gpuptr.car.jpg" | ||
print(f"Save to {saveto}") | ||
|
||
cv2.imwrite(saveto, image) | ||
|
||
except Exception as e: | ||
print("GPUPtr test failed.", e) |
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
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 |
---|---|---|
|
@@ -19,7 +19,9 @@ namespace YoloHighPerf{ | |
|
||
enum class Type : int{ | ||
V5 = 0, | ||
X = 1 | ||
X = 1, | ||
V3 = 2, | ||
V7 = 3 | ||
}; | ||
|
||
struct Box{ | ||
|
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
Oops, something went wrong.