簡體   English   中英

使用Tensorflow服務提供預訓練的keras接收模型時發生失敗的前提條件錯誤

[英]Failed precondition error when using Tensorflow serving to serve pretrained keras xception model

這是我用來將keras模型導出為tensorflow服務格式的代碼。導出的模型在tensorflow服務中成功加載(沒有任何警告或錯誤)。 但是,當我使用客戶端向服務器發出請求時,出現FailedPrecondition錯誤。 grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with: status = StatusCode.FAILED_PRECONDITION details = "Attempting to use uninitialized value block11_sepconv2_bn/moving_mean

import sys
import os
import tensorflow as tf
from keras import backend as K
from keras.models import Model
from keras.models import load_model
from tensorflow.python.saved_model import builder as saved_model_builder
from tensorflow.python.saved_model import utils
from tensorflow.python.saved_model import tag_constants, signature_constants
from tensorflow.python.saved_model.signature_def_utils_impl import     
build_signature_def, predict_signature_def
from tensorflow.contrib.session_bundle import exporter
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' 

config = tf.ConfigProto( device_count = {'GPU': 2 , 'CPU': 12} ) 
sess = tf.Session(config=config) 
K.set_session(sess)
K._LEARNING_PHASE = tf.constant(0)
K.set_learning_phase(0) 

xception = load_model('models/xception/model.h5')
config = xception.get_config()
weights = xception.get_weights()

new_xception = Model.from_config(config)
new_xception.set_weights(weights)

export_path = 'prod_models/2'
builder = saved_model_builder.SavedModelBuilder(export_path)
signature = predict_signature_def(inputs={'images': new_xception.input},
                              outputs={'scores': new_xception.output})
with K.get_session() as sess:
    builder.add_meta_graph_and_variables(sess=sess,
                                     tags=[tag_constants.SERVING],
                                     signature_def_map={'predict': 
                                                       signature})
    builder.save()
  • 套件版本
    • Python 3.6.3
    • 張量流-gpu 1.8.0
    • 凱拉斯2.1.5
    • CUDA 9.0.176

我嘗試使用以下模型來復制您的問題,因為我無權訪問您使用的模型文件:

from keras.applications.xception import Xception
new_xception = Xception()

我可以毫無問題地向該模型發出請求(python 3.6.4,tf 1.8.0,keras 2.2.0)。 您正在使用哪個版本的TF服務?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM