def test_bulk_with_min_value(self):

        img = ClImage(url=urls[0])

        m = self.app.models.get('general-v1.3')
        model_output_info = ModelOutputInfo(output_config=ModelOutputConfig(
            min_value=0.96))

        res = m.predict(inputs=[img, img, img],
                        model_output_info=model_output_info)

        for result in res['outputs']:
            for c in result['data']['concepts']:
                self.assertGreaterEqual(c['value'], 0.96)
Beispiel #2
0
    def test_bulk_with_min_value(self):

        img = ClImage(url=sample_inputs.METRO_IMAGE_URL)

        m = self.app.models.get(model_id=GENERAL_MODEL_ID)
        model_output_info = ModelOutputInfo(output_config=ModelOutputConfig(
            min_value=0.96))

        res = m.predict(inputs=[img, img, img],
                        model_output_info=model_output_info)
        self.assertEqual(10000, res['status']['code'])

        for result in res['outputs']:
            for c in result['data']['concepts']:
                self.assertGreaterEqual(c['value'], 0.96)
def test_concept_bulk_predict_with_arguments(
        mock_http_client):  # type: (mock.Mock) -> None
    mock_execute_request = mock_request(
        mock_http_client, """
{
  "status": {
    "code": 10000,
    "description": "Ok"
  },
  "outputs": [
    {
      "id": "@outputID1",
      "status": {
        "code": 10000,
        "description": "Ok"
      },
      "created_at": "2019-01-29T16:45:43.793810775Z",
      "model": {
        "id": "aaa03c23b3724a16a56b629203edc62c",
        "name": "general",
        "created_at": "2016-03-09T17:11:39.608845Z",
        "app_id": "main",
        "output_info": {
          "message": "Show output_info with: GET /models/{model_id}/output_info",
          "type": "concept",
          "type_ext": "concept"
        },
        "model_version": {
          "id": "aa9ca48295b37401f8af92ad1af0d91d",
          "created_at": "2016-07-13T01:19:12.147644Z",
          "status": {
            "code": 21100,
            "description": "Model trained successfully"
          },
          "train_stats": {}
        },
        "display_name": "General"
      },
      "input": {
        "id": "@inputID1",
        "data": {
          "image": {
            "url": "https://clarifai.com/developer/static/images/model-samples/celeb-001.jpg"
          }
        }
      },
      "data": {
        "concepts": [
          {
            "id": "@conceptID11",
            "name": "menschen",
            "value": 0.9963381,
            "app_id": "main"
          },
          {
            "id": "@conceptID12",
            "name": "ein",
            "value": 0.9879057,
            "app_id": "main"
          }
        ]
      }
    },
    {
      "id": "@outputID2",
      "status": {
        "code": 10000,
        "description": "Ok"
      },
      "created_at": "2019-01-29T16:45:43.793810775Z",
      "model": {
        "id": "aaa03c23b3724a16a56b629203edc62c",
        "name": "general",
        "created_at": "2016-03-09T17:11:39.608845Z",
        "app_id": "main",
        "output_info": {
          "message": "Show output_info with: GET /models/{model_id}/output_info",
          "type": "concept",
          "type_ext": "concept"
        },
        "model_version": {
          "id": "aa9ca48295b37401f8af92ad1af0d91d",
          "created_at": "2016-07-13T01:19:12.147644Z",
          "status": {
            "code": 21100,
            "description": "Model trained successfully"
          },
          "train_stats": {}
        },
        "display_name": "General"
      },
      "input": {
        "id": "@inputID2",
        "data": {
          "image": {
            "url": "https://clarifai.com/developer/static/images/model-samples/apparel-001.jpg"
          }
        }
      },
      "data": {
        "concepts": [
          {
            "id": "@conceptID21",
            "name": "brillen und kontaktlinsen",
            "value": 0.99984586,
            "app_id": "main"
          },
          {
            "id": "@conceptID22",
            "name": "linse",
            "value": 0.999823,
            "app_id": "main"
          }
        ]
      }
    }
  ]
}
""")

    app = ClarifaiApp()
    model = app.models.get(model_id='@modelID')
    response = model.predict(
        [Image(url='@url1'), Image(url='@url2')],
        ModelOutputInfo(output_config=ModelOutputConfig(
            language='de', max_concepts=2, min_value=0.5)))

    output1 = response['outputs'][0]
    assert output1['input']['id'] == '@inputID1'
    assert output1['id'] == '@outputID1'
    assert output1['data']['concepts'][0]['id'] == '@conceptID11'
    assert output1['data']['concepts'][1]['id'] == '@conceptID12'

    output2 = response['outputs'][1]
    assert output2['input']['id'] == '@inputID2'
    assert output2['id'] == '@outputID2'
    assert output2['data']['concepts'][0]['id'] == '@conceptID21'
    assert output2['data']['concepts'][1]['id'] == '@conceptID22'

    assert_request(
        mock_execute_request, 'POST', '/v2/models/@modelID/outputs', """
{
  "inputs": [
    {
      "data": {
        "image": {
          "url": "@url1"
        }
      }
    },
    {
      "data": {
        "image": {
          "url": "@url2"
        }
      }
    }
  ],
  "model": {
    "output_info": {
      "output_config": {
        "language": "de",
        "max_concepts": 2,
        "min_value": 0.5
      }
    }
  }
}
  """)