Detect objects in the input image.
(self, img, conf_th=0.3)
| 101 | del self.stream |
| 102 | |
| 103 | def detect(self, img, conf_th=0.3): |
| 104 | """Detect objects in the input image.""" |
| 105 | img_resized = _preprocess_trt(img, self.input_shape) |
| 106 | np.copyto(self.host_inputs[0], img_resized.ravel()) |
| 107 | |
| 108 | if self.cuda_ctx: |
| 109 | self.cuda_ctx.push() |
| 110 | cuda.memcpy_htod_async( |
| 111 | self.cuda_inputs[0], self.host_inputs[0], self.stream) |
| 112 | self.context.execute_async( |
| 113 | batch_size=1, |
| 114 | bindings=self.bindings, |
| 115 | stream_handle=self.stream.handle) |
| 116 | cuda.memcpy_dtoh_async( |
| 117 | self.host_outputs[1], self.cuda_outputs[1], self.stream) |
| 118 | cuda.memcpy_dtoh_async( |
| 119 | self.host_outputs[0], self.cuda_outputs[0], self.stream) |
| 120 | self.stream.synchronize() |
| 121 | if self.cuda_ctx: |
| 122 | self.cuda_ctx.pop() |
| 123 | |
| 124 | output = self.host_outputs[0] |
| 125 | return _postprocess_trt(img, output, conf_th) |
no test coverage detected