我訓練了一個基本的圖像分類模型在使用Tensorflow MNIST,日誌與MLflow實驗運行。
模型:“my_sequential”_________________________________________________________________層(類型)輸出形狀參數# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =改造(改造)(1)沒有,28日28日0 conv2d (conv2d)(32), 26日26日320 max_pooling2d (MaxPooling(32)沒有,13日13日0 2 d)平(平)(沒有,5408)0密度(密度)(540900,100)dense_1(致密)(沒有,10)1010 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =總參數:542230可訓練的參數:542230 Non-trainable params: 0 _________________________________________________________________
mlflow.start_run()運行:run_id = run.info.run_id mlflow.tensorflow.autolog()模型。適合(trainX trainY validation_data = (testX,暴躁的),時代= 2,batch_size = 64)
然後我注冊服務的模型,使模型。
當試圖通過瀏覽器發送JSON文本形式
[{“b64”:“AA AA…= = "})
我得到錯誤如下:
BAD_REQUEST:遇到了一個意想不到的錯誤,同時評估模型。驗證序列化Dataframe兼容推理模型的輸入。回溯(最近調用最後):文件“/磚/ conda / env / model-10 / lib / python3.8 /網站/ mlflow / pyfunc / scoring_server / __init__。py”, 306行,在轉換raw_predictions = model.predict(數據)文件”/磚/ conda / env / model-10 / lib / python3.8 /網站/ mlflow / pyfunc / __init__。py”, 605行,在預測返回self._model_impl.predict(數據)文件”/磚/ conda / env / model-10 / lib / python3.8 /網站/ mlflow / keras。py”, 475行,在預測預測= _predict(數據)文件”/磚/ conda / env / model-10 / lib / python3.8 /網站/ mlflow / keras。py”, 462行,在_predict預測= pd.DataFrame (self.keras_model.predict (data.values))文件”/磚/ conda / env / model-10 / lib / python3.8 /網站/ keras / traceback_utils跑龍套。py”, 67行,error_handler提高e.with_traceback (filtered_tb)從沒有文件“/磚/ conda / env / model-10 / lib / python3.8 /網站/ tensorflow / python /框架/ func_graph。py”, 1147行,autograph_handler提高e.ag_error_metadata.to_exception (e) ValueError:在用戶代碼:文件”/磚/ conda / env / model-10 / lib / python3.8 /網站/ keras /發動機/培訓。py”, 1801行,在predict_function *返回step_function(自我,迭代器)文件“/磚/ conda / env / model-10 / lib / python3.8 /網站/ keras /發動機/培訓。py”, 1790行,step_function * *輸出= model.distribute_strategy.run (run_step args =(數據)文件”/磚/ conda / env / model-10 / lib / python3.8 /網站/ keras /發動機/培訓。py”, 1783行,run_step * *輸出= model.predict_step(數據)文件”/磚/ conda / env / model-10 / lib / python3.8 /網站/ keras /發動機/培訓。py”, 1751行,在predict_step返回自我(x,培訓= False)文件“/磚/ conda / env / model-10 / lib / python3.8 /網站/ keras / traceback_utils跑龍套。py”, 67行,error_handler提高e.with_traceback (filtered_tb)從沒有文件“/磚/ conda / env / model-10 / lib / python3.8 /網站/ keras /層/核心/重塑。py”, 110行,_fix_unknown_dimension提高ValueError(味精)ValueError:異常時遇到層稱為“重塑”重塑(類型)。新數組的總大小必須不變,input_shape = [1], output_shape =[1] 28日28日調用參數收到:•輸入=特遣部隊。張量(形狀= (,1),dtype = float32)
這似乎是因為我通過字節編碼的圖像數據作為一個字符串,而不是numpy數組。根據TensorFlow文檔,這就是它必須被傳遞。
如果我有一個圖像形狀(1)28日,28日,稱為img,我將它轉換為所需的格式
image_data = base64.b64encode (img) json = {“b64”: image_data.decode ()}
我的問題有兩個部分: