def predict_label(): _data = Data() labels = _data.labels if request.method == 'GET': data = _data.test_data image_data = get_image_data(data) prediction = predict_image(image_data) argmax = int(np.argmax(np.array(prediction)[0])) return jsonify({labels[argmax]: prediction[0][argmax]}) elif request.method == 'POST': input_data = request.get_json() raw_data = input_data["image_data"] decoded = base64.b64decode(str(raw_data)) io_bytes = io.BytesIO(decoded) data = Image.open(io_bytes) image_data = get_image_data(data) prediction = predict_image(image_data) argmax = int(np.argmax(np.array(prediction)[0])) job_id = data['job_id'] if 'job_id' in input_data.keys( ) else get_job_id() return jsonify({ labels[argmax]: prediction[0][argmax], 'job_id': job_id })
def predict(): _data = Data() if request.method == 'GET': data = _data.test_data image_data = get_image_data(data) prediction = predict_image(image_data) return jsonify({'prediction': prediction}) elif request.method == 'POST': input_data = request.get_json() raw_data = input_data["image_data"] decoded = base64.b64decode(str(raw_data)) io_bytes = io.BytesIO(decoded) data = Image.open(io_bytes) image_data = get_image_data(data) prediction = predict_image(image_data) job_id = data['job_id'] if 'job_id' in input_data.keys( ) else get_job_id() return jsonify({'prediction': prediction, 'job_id': job_id})
def predict(): _data = Data() if request.method == "GET": data = _data.test_data image_data = get_image_data(data) prediction = predict_image(image_data) return jsonify({"prediction": prediction}) elif request.method == "POST": input_data = request.get_json() raw_data = input_data["image_data"] decoded = base64.b64decode(str(raw_data)) io_bytes = io.BytesIO(decoded) data = Image.open(io_bytes) image_data = get_image_data(data) prediction = predict_image(image_data) job_id = data["job_id"] if "job_id" in input_data.keys( ) else get_job_id() return jsonify({"prediction": prediction, "job_id": job_id})
async def __async_predict(data: Data): image_data = get_image_data(data.image_data) output_np = await active_predictor.async_predict(image_data) reshaped_output_nps = DataConverter.reshape_output(output_np) data.prediction = reshaped_output_nps.tolist() logger.info({'job_id': data.job_id, 'prediction': data.prediction})