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 })
async def _predict_async_post( data: Data, job_id: str, background_tasks: BackgroundTasks = BackgroundTasks() ) -> Dict[str, List[float]]: image = base64.b64decode(str(data.image_data)) io_bytes = io.BytesIO(image) data.image_data = Image.open(io_bytes) store_data_job._save_data_job(data, job_id, background_tasks, True) return {'job_id': job_id}
async def _predict_label( data: Data, job_id: str, background_tasks: BackgroundTasks = BackgroundTasks() ) -> Dict[str, List[float]]: image = base64.b64decode(str(data.image_data)) io_bytes = io.BytesIO(image) data.image_data = Image.open(io_bytes) label_proba = await __async_predict_label(data) store_data_job._save_data_job(data, job_id, background_tasks, False) return {'prediction': label_proba, '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 _test_label(data: Data = Data()) -> Dict[str, Dict[str, float]]: data.image_data = data.test_data label_proba = __predict_label(data) return {'prediction': label_proba}
async def _test(data: Data = Data()) -> Dict[str, int]: data.image_data = data.test_data __predict(data) return {'prediction': data.prediction}
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})
def __predict(data: Data): input_np = DataConverter.convert_input_data_to_np(data.input_data) output_np = active_predictor.predict(input_np) reshaped_output_nps = DataConverter.reshape_output(output_np) data.prediction = reshaped_output_nps.tolist() logger.info({'job_id': data.job_id, 'prediction': data.prediction})
def labels(): _data = Data() labels = _data.labels return jsonify({'labels': labels})
def labels(): _data = Data() labels = _data.labels return jsonify({"labels": labels})
def _test_label(data: Data = Data()) -> Dict[str, Dict[str, float]]: data.input_data = data.test_data label_proba = __predict_label(data) return {"prediction": label_proba}
def _test(data: Data = Data()) -> Dict[str, int]: data.input_data = data.test_data __predict(data) return {"prediction": data.prediction}
async def __async_predict(data: Data): input_np = DataConverter.convert_input_data_to_np(data.input_data) output_np = await active_predictor.async_predict(input_np) reshaped_output_nps = DataConverter.reshape_output(output_np) data.prediction = reshaped_output_nps.tolist() logger.info({"job_id": data.job_id, "prediction": data.prediction})