Ejemplo n.º 1
0
    def test_03(self):

        with self.assertRaises(AssertionError):
            RetinanetToPmml(self.model,
                            input_shape=(224, 224, 3),
                            backbone_name='resnet50',
                            pmml_file_name="retinanet_with_coco_2.pmml")
Ejemplo n.º 2
0
    def test_03(self):

        model = load_model('resnet50_coco_best_v2.1.0.h5',
                           backbone_name='resnet50')
        with self.assertRaises(AssertionError):
            RetinanetToPmml(model,
                            input_shape=(224, 224, 3),
                            backbone_name='resnet50',
                            pmml_file_name="retinanet_with_coco_2.pmml")
Ejemplo n.º 3
0
 def test_05(self):
     backbone = 'resnet'
     script_content = open("nyoka/tests/preprocess.py", 'r').read()
     RetinanetToPmml(self.model,
                     input_shape=(224, 224, 3),
                     backbone_name=backbone,
                     pmml_file_name="retinanet_with_coco_2.pmml",
                     script_args={
                         "content": script_content,
                         "def_name": "getBase64EncodedString",
                         "return_type": "string",
                         "encode": True
                     })
     recon_pmml_obj = pml.parse("retinanet_with_coco_2.pmml", True)
     content = recon_pmml_obj.TransformationDictionary.DefineFunction[
         0].Apply.Extension[0].anytypeobjs_[0]
     content = base64.b64decode(content).decode()
     self.assertEqual(script_content, content)
Ejemplo n.º 4
0
    def test_02(self):

        backbone = 'mobilenet'
        RetinanetToPmml(self.model,
                        input_shape=(224, 224, 3),
                        backbone_name=backbone,
                        pmml_file_name="retinanet_with_coco_2.pmml")
        recon_pmml_obj = pml.parse("retinanet_with_coco_2.pmml", True)
        binary_buffered = recon_pmml_obj.DataDictionary.DataField[0].Extension[
            0].value
        self.assertEqual(binary_buffered, 'true')
        function = recon_pmml_obj.DeepNetwork[
            0].LocalTransformations.DerivedField[0].Apply.function
        self.assertEqual(function,
                         'KerasRetinaNet:getBase64StringFromBufferedInput')
        scaling = recon_pmml_obj.DeepNetwork[
            0].LocalTransformations.DerivedField[0].Apply.Constant[0].valueOf_
        self.assertEqual(scaling, 'tf')
Ejemplo n.º 5
0
    def test_01(self):
        RetinanetToPmml(model=self.model,
                        input_shape=(224, 224, 3),
                        input_format='image',
                        backbone_name='resnet',
                        trained_classes=classes,
                        pmml_file_name="RetinaNet.pmml")
        model_name = self.adapa_utility.upload_to_zserver('RetinaNet.pmml')
        z_boxes, z_scores, z_labels = self.adapa_utility.score_in_zserver(
            model_name, 'nyoka/tests/test_image_retinanet.png', 'RN')
        img = load_img('nyoka/tests/test_image_retinanet.png')
        img = img_to_array(img)
        img = preprocess_input(img)
        test = np.expand_dims(img, axis=0)
        boxes, scores, labels = self.model.predict(test)
        scores = scores.flatten()
        boxes = boxes.reshape(-1, 4)
        labels = labels.flatten()

        scores_cnt = 0
        for a, b in zip(scores, z_scores):
            a = "{:.4f}".format(a)
            b = "{:.4f}".format(b)
            if a != b:
                scores_cnt += 1

        labels_cnt = 0
        for a, b in zip(labels, z_labels):
            b = self.classes.index(b)
            if a != b:
                labels_cnt += 1

        boxes_cnt = 0
        for a, b in zip(boxes, z_boxes):
            for a_, b_ in zip(a, b):
                a_ = "{:.2f}".format(a_)
                b_ = "{:.2f}".format(b_)
                if a_ != b_:
                    boxes_cnt += 1

        self.assertEqual(scores_cnt, 0)
        self.assertEqual(labels_cnt, 0)
        self.assertEqual(boxes_cnt, 0)