MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / exec

Method exec

flow-python/examples/application/cat_finder/det.py:47–84  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

45 return val
46
47 def exec(self):
48 envelope = self.inp.recv()
49 if envelope is None:
50 return
51
52 msg = envelope.msg
53 msg['items'] = []
54
55 process = envelope.partial_id % self._interval == 0
56 if process:
57 data = msg['data']
58 outputs = self._predictor.inference(data)
59 # skip if detect nothing
60 if outputs is not None:
61 items = []
62
63 for i in range(outputs.shape[0]):
64 output = outputs[i]
65 # if neither cat nor dog, skip
66 if round(output[6]) != 15 and round(output[6]) != 16:
67 continue
68
69 item = dict()
70 item["bbox"] = output[0:4]
71 item["cls"] = round(output[6])
72 item["score"] = output[4] * output[5]
73 items.append(item)
74 msg['items'] = items
75
76 # import cv2
77 # x = self._predictor.visual(outputs, data)
78 # name = 'frame{0:07d}.jpg'.format(envelope.partial_id)
79 # cv2.imwrite(name, x)
80
81 if self._visualize == 1:
82 msg['data'] = self._predictor.visual(outputs, data)
83 msg['process'] = process
84 self.out.send(envelope)

Callers

nothing calls this directly

Calls 6

rangeFunction · 0.85
appendMethod · 0.80
visualMethod · 0.80
recvMethod · 0.45
inferenceMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected