Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update centerface.py #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions prj-tensorrt/centerface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def __init__(self, landmarks=True):
runtime = trt.Runtime(self.trt_logger)
self.net = runtime.deserialize_cuda_engine(f.read())
self.img_h_new, self.img_w_new, self.scale_h, self.scale_w = 0, 0, 0, 0
self.engine = self.net
# Create the context for this engine
self.context = self.engine.create_execution_context()

def __call__(self, img, height, width, threshold=0.5):
h, w = img.shape[:2]
Expand Down Expand Up @@ -67,12 +70,8 @@ def do_inference(context, bindings, inputs, outputs, stream, batch_size=1):

image_cv = cv2.resize(img, dsize=(self.img_w_new, self.img_h_new))
blob = np.expand_dims(image_cv[:, :, (2, 1, 0)].transpose(2, 0, 1), axis=0).astype("float32")
engine = self.net

# Create the context for this engine
context = engine.create_execution_context()
# Allocate buffers for input and output
inputs, outputs, bindings, stream = allocate_buffers(engine) # input, output: host # bindings

inputs, outputs, bindings, stream = allocate_buffers(self.engine) # input, output: host # bindings

# Do inference
shape_of_output = [(1, 1, int(self.img_h_new / 4), int(self.img_w_new / 4)),
Expand All @@ -82,7 +81,7 @@ def do_inference(context, bindings, inputs, outputs, stream, batch_size=1):
# Load data to the buffer
inputs[0].host = blob.reshape(-1)
begin = datetime.datetime.now()
trt_outputs = do_inference(context, bindings=bindings, inputs=inputs, outputs=outputs, stream=stream) # numpy data
trt_outputs = do_inference(self.context, bindings=bindings, inputs=inputs, outputs=outputs, stream=stream) # numpy data
end = datetime.datetime.now()
print("gpu times = ", end - begin)

Expand Down