Beispiel #1
0
class Apparel:
    def __init__(self):
        self.app = ClarifaiApp(api_key='986fb613cdcf42d781e69646ce92d7b5')
        self.model = Model(self.app.api,
                           model_id='72c523807f93e18b431676fb9a58e6ad')
        self.fmodel = Model(self.app.api,
                            model_id='e466caa0619f444ab97497640cefc4dc')

    def detect(self, frame, height, width):
        response = self.model.predict_by_filename(frame)
        items = []
        boxes = []

        if 'regions' in response['outputs'][0]['data']:
            for region in response['outputs'][0]['data']['regions']:
                bb = region['region_info']['bounding_box']
                boxes.append([
                    int(height * bb['top_row']),
                    int(height * bb['bottom_row']),
                    int(width * bb['left_col']),
                    int(width * bb['right_col'])
                ])
                items.append(region['data']['concepts'][0]['name'])

        return items, boxes

    def detect_famous(self, frame, height, width):
        response = self.fmodel.predict_by_filename(frame)
        celebs = []
        boxes = []

        if 'regions' in response['outputs'][0]['data']:
            regions = response['outputs'][0]['data']['regions']
            for region in regions:
                if region['data']['concepts'][0]['value'] > 0.5:
                    celebs.append(region['data']['concepts'][0]['name'])
                    bb = region['region_info']['bounding_box']
                    boxes.append([
                        int(height * bb['top_row']),
                        int(height * bb['bottom_row']),
                        int(width * bb['left_col']),
                        int(width * bb['right_col'])
                    ])

        return celebs, boxes
Beispiel #2
0
def test_model_evaluate(mock_http_client):  # type: (mock.Mock) -> None
    mock_execute_request = mock_request(
        mock_http_client, """
{
    "status": {
        "code": 10000,
        "description": "Ok"
    },
    "model_version": {
        "id": "@modelVersionID",
        "created_at": "2017-01-01T00:00:00.000000Z",
        "status": {
            "code": 21100,
            "description": "Model trained successfully"
        },
        "active_concept_count": 2,
        "metrics": {
            "status": {
                "code": 21303,
                "description": "Model is queued for evaluation."
            }
        },
        "total_input_count": 30
    }
}
""")

    app = ClarifaiApp()
    model = Model(app.api, model_id='@modelID')
    model.model_version = '@modelVersionID'
    response = model.evaluate()

    assert response['status']['code'] == 10000

    assert_request(mock_execute_request, 'POST',
                   '/v2/models/@modelID/versions/@modelVersionID/metrics',
                   '{}')
 def test_predict_with_model_id(self):
     """ test initialize model object """
     # make model from model_id
     m = Model(self.app.api, model_id='eee28c313d69466f836ab83287a54ed9')
     m.predict_by_url(sample_inputs.METRO_IMAGE_URL)
Beispiel #4
0
 def __init__(self):
     self.app = ClarifaiApp(api_key='986fb613cdcf42d781e69646ce92d7b5')
     self.model = Model(self.app.api,
                        model_id='72c523807f93e18b431676fb9a58e6ad')
     self.fmodel = Model(self.app.api,
                         model_id='e466caa0619f444ab97497640cefc4dc')
Beispiel #5
0
 def test_predict_with_model_id(self):
     """ test initialize model object """
     # make model from model_id
     m = Model(self.app.api, model_id='eee28c313d69466f836ab83287a54ed9')
     m.predict_by_url(urls[0])
 def test_predict_with_model_id(self):
   """ test initialize model object """
   # make model from model_id
   m = Model(self.app.api, model_id='eee28c313d69466f836ab83287a54ed9')
   m.predict_by_url(sample_inputs.METRO_IMAGE_URL)