(predictions, image_size)
| 17 | |
| 18 | |
| 19 | def create_instances(predictions, image_size): |
| 20 | ret = Instances(image_size) |
| 21 | |
| 22 | score = np.asarray([x["score"] for x in predictions]) |
| 23 | chosen = (score > args.conf_threshold).nonzero()[0] |
| 24 | score = score[chosen] |
| 25 | bbox = np.asarray([predictions[i]["bbox"] for i in chosen]).reshape(-1, 4) |
| 26 | bbox = BoxMode.convert(bbox, BoxMode.XYWH_ABS, BoxMode.XYXY_ABS) |
| 27 | |
| 28 | labels = np.asarray([dataset_id_map(predictions[i]["category_id"]) for i in chosen]) |
| 29 | |
| 30 | ret.scores = score |
| 31 | ret.pred_boxes = Boxes(bbox) |
| 32 | ret.pred_classes = labels |
| 33 | |
| 34 | try: |
| 35 | ret.pred_masks = [predictions[i]["segmentation"] for i in chosen] |
| 36 | except KeyError: |
| 37 | pass |
| 38 | return ret |
| 39 | |
| 40 | |
| 41 | if __name__ == "__main__": |
no test coverage detected