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

Class Detect

flow-python/examples/application/cat_finder/det.py:19–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17
18@register(inputs=['inp'], outputs=['out'])
19class Detect:
20 def __init__(self, name, args):
21 logger.info("loading YOLOX detection...")
22 self._tsize = args['tsize']
23 self._interval = args['interval']
24 self._visualize = args['visualize']
25 self.name = name
26
27 # load detect model and warmup
28 self._predictor = PredictorLite(path=args['path'],
29 confthre=args['conf'],
30 nmsthre=args['nms'],
31 test_size=(self._tsize, self._tsize),
32 device=args['device'],
33 device_id=args['device_id'])
34 warmup_data = np.zeros((224, 224, 3), dtype=np.uint8)
35 self._predictor.inference(warmup_data)
36 logger.info(" YOLOX loaded.")
37
38 @staticmethod
39 def restrict(val, min, max):
40 assert min < max
41 if val < min:
42 val = min
43 if val > max:
44 val = max
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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected