示例#1
0
 def postgresql_status(self):
     try:
         from data_models import Prediction
         Prediction.first()
         return 'OK'
     except:
         return 'failure'
示例#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
示例#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}
示例#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'
示例#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
示例#6
0
 def test_prediction_create_result(self, result):
     assert Prediction.create(result=result).result == result
示例#7
0
 def test_prediction_create_bbox(self, bbox):
     assert Prediction.create(bbox=bbox).bbox == bbox
示例#8
0
 def test_prediction_create_proba(self, proba):
     assert Prediction.create(proba=proba).proba == proba
示例#9
0
 def test_prediction_init(self, label):
     assert Prediction(label=label).label == label
示例#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)
示例#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
示例#12
0
def on_message(client, userdata, msg):
    print('New message: %s' % msg.payload)
    Prediction.create_from_mq(msg.payload)
示例#13
0
def predictions_weak():
    predictions = Prediction.weak()
    return jsonify(PredictionsPresenter(predictions).to_dict())
示例#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())