| 17 | |
| 18 | @register(inputs=['inp'], outputs=['out']) |
| 19 | class Detect: |
| 20 | def __init__(self, name, args): |
| 21 | logger.info("loading MEMD detection...") |
| 22 | self._nms = args['nms_thres'] |
| 23 | self._score = args['score_thres'] |
| 24 | self._interval = args['interval'] |
| 25 | self._visualize = args['visualize'] |
| 26 | self.name = name |
| 27 | |
| 28 | # load model and warmup |
| 29 | self._model = load_onnx_model(args['path']) |
| 30 | warmup_data = np.zeros((256, 256, 3), dtype=np.uint8) |
| 31 | run(self._model, warmup_data, ["elec_cycle"], self._score, |
| 32 | self._nms) |
| 33 | |
| 34 | logger.info(" MEMD loaded.") |
| 35 | |
| 36 | @staticmethod |
| 37 | def restrict(val, min, max): |
| 38 | assert min < max |
| 39 | if val < min: |
| 40 | val = min |
| 41 | if val > max: |
| 42 | val = max |
| 43 | return round(val) |
| 44 | |
| 45 | def exec(self): |
| 46 | envelope = self.inp.recv() |
| 47 | if envelope is None: |
| 48 | return |
| 49 | image = envelope.msg |
| 50 | |
| 51 | process = envelope.partial_id % self._interval == 0 |
| 52 | image['items'] = [] |
| 53 | |
| 54 | if process: |
| 55 | data = image['data'] |
| 56 | outputs = run(self._model, data, ["elec_cycle"], |
| 57 | self._score, self._nms) |
| 58 | |
| 59 | items = [] |
| 60 | (max_h, max_w, _) = data.shape |
| 61 | for output in outputs: |
| 62 | item = dict() |
| 63 | bbox = output[0:4] |
| 64 | bbox[0] = self.restrict(bbox[0], 0, max_w) |
| 65 | bbox[1] = self.restrict(bbox[1], 0, max_h) |
| 66 | bbox[2] = self.restrict(bbox[2], bbox[0], max_w) |
| 67 | bbox[3] = self.restrict(bbox[3], bbox[1], max_h) |
| 68 | item["bbox"] = bbox |
| 69 | item["cls"] = 0 |
| 70 | item["score"] = output[4] |
| 71 | items.append(item) |
| 72 | image['items'] = items |
| 73 | |
| 74 | self.out.send(envelope) |
nothing calls this directly
no outgoing calls
no test coverage detected