Ejemplo n.º 1
0
 def postgresql_status(self):
     try:
         from data_models import Prediction
         Prediction.first()
         return 'OK'
     except:
         return 'failure'
Ejemplo n.º 2
0
    def test_predictions_weak(self, client):
        picture = Picture.create(image_id='foobar.jpg')
        algorithm = Algorithm.create(name='DeevioNet', version='1.1')
        prediction = Prediction.create(picture_id=picture.id, algorithm_id=algorithm.id, proba=0.69)
        prediction = Prediction.create(picture_id=picture.id, algorithm_id=algorithm.id, proba=0.7)

        body = json.loads(client.get('/v1/predictions/weak').data)

        assert len(body) == 1
Ejemplo n.º 3
0
 def post(self):
     vector = parser.parse_args()
     prediction = float(
         ml_model.predict(
             np.array([v for v in vector.values()]).reshape(1, -1)))
     db_log = Prediction(input_data=json.dumps(vector),
                         prediction=prediction,
                         predicted_at=datetime.datetime.now())
     db.session.add(db_log)
     db.session.commit()
     return {'prediction': prediction}
Ejemplo n.º 4
0
    def test_predictions_by_image_id(self, client):
        picture = Picture.create(image_id='foobar.jpg')
        algorithm = Algorithm.create(name='DeevioNet', version='1.1')
        prediction = Prediction.create(picture_id=picture.id, algorithm_id=algorithm.id, proba=0.99, status='complete', label='nail', result='good', bbox=[100, 200, 500, 500])

        body = json.loads(client.get('/v1/predictions/%s' % 'foobar.jpg').data)

        assert body['probability'] == prediction.proba
        assert body['status'] == prediction.status
        assert body['label'] == prediction.label
        assert body['result'] == prediction.result
        assert body['bbox'] == prediction.bbox
        assert body['algorithm']['type'] == 'GET'
        assert body['algorithm']['rel'] == 'algorithm'
        assert body['algorithm']['href'] == '/v1/algorithm/DeevioNet?version=1.1'
        assert body['picture']['type'] == 'GET'
        assert body['picture']['rel'] == 'picture'
        assert body['picture']['href'] == '/v1/picture/foobar.jpg'
Ejemplo n.º 5
0
 def test_prediction_create_algorithm(self):
     algorithm = Algorithm.create()
     prediction = Prediction.create(algorithm_id=algorithm.id)
     assert prediction.algorithm == algorithm
     assert algorithm.predictions[-1] == prediction
Ejemplo n.º 6
0
 def test_prediction_create_result(self, result):
     assert Prediction.create(result=result).result == result
Ejemplo n.º 7
0
 def test_prediction_create_bbox(self, bbox):
     assert Prediction.create(bbox=bbox).bbox == bbox
Ejemplo n.º 8
0
 def test_prediction_create_proba(self, proba):
     assert Prediction.create(proba=proba).proba == proba
Ejemplo n.º 9
0
 def test_prediction_init(self, label):
     assert Prediction(label=label).label == label
Ejemplo n.º 10
0
 def test_prediction_create_from_mq(self):
     payload = '{"algorithm": {"name": "DeevioNet","version": "1.0"},"status":"complete","imagePath":"20180907/1536311270718.jpg","imageId":"1536311270718","output":[{"bbox":[1008.8831787109375,280.6226501464844,1110.0245361328125,380.72021484375],"probability":0.9725130796432495,"label":"nail","result":"good"} ]}'
     Prediction.create_from_mq(payload)
Ejemplo n.º 11
0
 def test_prediction_create_picture(self):
     picture = Picture.create()
     prediction = Prediction.create(picture_id=picture.id)
     assert prediction.picture == picture
     assert picture.predictions[-1] == prediction
Ejemplo n.º 12
0
def on_message(client, userdata, msg):
    print('New message: %s' % msg.payload)
    Prediction.create_from_mq(msg.payload)
Ejemplo n.º 13
0
def predictions_weak():
    predictions = Prediction.weak()
    return jsonify(PredictionsPresenter(predictions).to_dict())
Ejemplo n.º 14
0
def predictions(image_id):
    picture = Picture.find_by(image_id=image_id)
    prediction = Prediction.find_by(picture_id=picture.id)
    return jsonify(PredictionPresenter(prediction).to_dict())