我试图提供一个TensorFlow模型(使用TensorFlow服务)。看来,为了使用TensorFlow服务API并进行预测,我需要使用原件方法。
对于我的Docker映像,我只为这个方法安装了1.3GB的TensorFlow包。显然,这并不理想。因此,我想知道是否可以从不同的(更精简的)包导入make_tensor_proto,或者使用其他方法。
发布于 2022-07-21 08:42:54
您可以按照下面链接中提到的步骤进行操作。
https://www.mux.com/blog/tuning-performance-of-tensorflow-serving-pipeline
简化步骤:
从这一行代码
import tensorflow as tf
...
tensor = tf.contrib.util.make_tensor_proto(features)
request.inputs['inputs'].CopyFrom(tensor)到这一行代码
from protos.tensorflow.core.framework import tensor_pb2
from protos.tensorflow.core.framework import tensor_shape_pb2
from protos.tensorflow.core.framework import types_pb2
...
# ensure NHWC shape and build tensor proto
tensor_shape = [1]+list(img.shape)
dims = [tensor_shape_pb2.TensorShapeProto.Dim(size=dim) for dim in tensor_shape]
tensor_shape = tensor_shape_pb2.TensorShapeProto(dim=dims)
tensor = tensor_pb2.TensorProto(
dtype=types_pb2.DT_FLOAT,
tensor_shape=tensor_shape,
float_val=list(img.reshape(-1)))
request.inputs['inputs'].CopyFrom(tensor) 您可以将这个编译好的pythonic函数复制到您的项目工作目录中,并复制到应该工作的docker中。
https://stackoverflow.com/questions/72882935
复制相似问题