def predict()

in miscellaneous/distributed_tensorflow_mask_rcnn/container-serving/resources/predict.py [0:0]


    def predict(cls, img=None, img_id=None):

        detection_results = predict_image(img, cls.predictor)
        print(detection_results)

        predictions = {"img_id": str(img_id)}

        annotations = []
        for dr in detection_results:
            a = {}
            b = dr.box.tolist()
            a["bbox"] = [int(b[0]), int(b[1]), int(b[2] - b[0]), int(b[3] - b[1])]
            category_id = dr.class_id

            a["category_id"] = int(category_id)
            a["category_name"] = cfg.DATA.CLASS_NAMES[int(category_id)]
            rle = cls.binary_mask_to_rle(dr.mask)
            a["segmentation"] = rle
            annotations.append(a)

        predictions["annotations"] = annotations
        print(predictions)

        return predictions