1

已经使用 grpc 创建了一个 rpc 服务。当我尝试在 grpc 调用(预测)中调用张量流预测函数时。我收到与张量流相关的错误,并发现 tf.global_variables() 变为空。这是代码

class ModelServiceServicer(modelService_pb2_grpc.ModelServiceServicer):
"""Provides methods that implement functionality of route guide 
   server."""

def __init__(self, model_dir_path, metrics_enabled, metrics_service):
    self.metrics_enabled = metrics_enabled
    self.metrics_service = metrics_service
    self.serialized_model = TfContainer(model_dir_path)
    self.input = ["""#input"""]        
    **#this works**
    print(self.serialized_model.handle_predict(self.input))        
    print("intialized")
    print(tf.global_variables())


def predict(self, request, context):
    print("request is ")
    #print(request)
    print(context)
    start_time = datetime.now()
    print(self.input)
    print(self.serialized_model)
    try:
        **#this becomes empty**
        print(tf.global_variables())
        **#this does not work.**
        print(self.serialized_model.handle_predict(self.input))
    except:
        traceback.print_stack()
        print('------')
        traceback.print_exc()      **
    print(self.serialized_model.handle_predict(self.input))        
    print("intialized")
    print(tf.global_variables())  

帮助将不胜感激!

4

1 回答 1

0

实际的 Servicer 方法调用确实发生在另一个线程中,特别是在初始化服务器时提供的 ThreadPool 中。根据 TensorFlow文档 tf.global_variables似乎没有直接绑定到线程,不像tf.local_variables. 你能提供更多关于什么是期望值的信息tf.global_variables吗?或者一个最小的可重现片段会更好!

于 2019-02-21T22:41:18.040 回答