已经使用 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())
帮助将不胜感激!