| 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) |