要查找 Tensorflow 版本,我们可以通过以下方式执行此操作: python -c 'import tensorflow as tf; 打印(tf.版本)'
Tensorflow Serving是单独安装的,那么如何查找Tensorflow Serving的版本呢?
和张量流一样吗?没有看到任何与此相关的参考/评论或文档。
我使用了人口普查数据并使用 tensorflow 中的 estimators api 创建了一个广泛而深入的模型。在 Java 中加载模型时,似乎存在一个错误,不允许加载模型。异常看起来像
Exception in thread "main" org.tensorflow.TensorFlowException: Op type not
registered 'SparseFeatureCross' in binary running on gmalhotra-mba-2.local.
Make sure the Op and Kernel are registered in the binary running in this
process.
at org.tensorflow.SavedModelBundle.load(Native Method)
at org.tensorflow.SavedModelBundle.load(SavedModelBundle.java:39)
at deeplearning.DeepLearningTest.main(DeepLearningTest.java:32)
Run Code Online (Sandbox Code Playgroud)
请在下面找到用于保存模型的python代码:https : //gist.github.com/gaganmalhotra/cd6a5898b9caf9005a05c8831a9b9153
使用的Java代码如下:
public static void main(String[] args) {
try (SavedModelBundle b = SavedModelBundle.load("/Users/gagandeep.malhotra/Documents/SampleTF_projects/temporaryModel/1510624417/", "serve")) {
Session sess = b.session();
//Create the input sensor
float[][] mat=new float[1][1];
mat[0]=new float[]{0.5f};
// create tensors specific …Run Code Online (Sandbox Code Playgroud) 我有一个模型,比如说mymodel和两个不同的数据集:setA,setB。
在分别训练(在我的本地机器上)setA和setB 之后,tensorflow 服务创建了两个不同的目录:分别为setA和setB 的100、200。
在 docker 中托管模型
root@ccb58054cae5:/# ls /serving/model/
100 200
root@ccb58054cae5:/# bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server --port=9000 --model_name=mymodel --model_base_path=/serving/model &> log &
Run Code Online (Sandbox Code Playgroud)
现在,当我对setB进行推理时,我能够成功获得响应,因为默认情况下 tensorflow 服务加载200,因为它认为这是最新模型。
现在我想查询setA,所以我需要在代码中提到要命中哪个版本的托管模型,那就是100。
在代码方面: request.model_spec.version.value = 100
为了完整起见,这里是其他相关的客户端代码:
host, port = FLAGS.server.split(':')
channel = implementations.insecure_channel(host, int(port))
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
request = predict_pb2.PredictRequest()
request.model_spec.name = 'mymodel'
request.model_spec.signature_name = signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY
request.model_spec.version.value = 100
Run Code Online (Sandbox Code Playgroud)
我是request.model_spec.version.value …
我训练用一个简单的模型MNIST tensorflow 2.0的谷歌Colab并在保存它以.json格式。单击此处以查看我在其中编写代码的Colab笔记本。然后在运行命令
!simple_tensorflow_serving --model_base_path="/" --model_platform="tensorflow"
它显示错误AttributeError:模块'tensorflow'没有属性'gfile'
simple_tensorflow_serving帮助轻松地将经过训练的张量流模型部署到生产中。
我使用的版本:
(1)TensorFlow-2.0
(2)simple_tensorflow_serving-0.6.4
先感谢您 :)
我可以使用以下代码成功保存 TF2 图像分割模型并将其部署到 AI Platform:
@tf.function(input_signature=[tf.TensorSpec(shape=(None), dtype=tf.string)])
def serving(input_image):
# Convert bytes of jpeg input to float32 tensor for model
def _input_to_feature(image_bytes):
img = tf.image.decode_jpeg(image_bytes, channels=3)
img = tf.image.convert_image_dtype(img, tf.float32) / 255.0
img = tf.image.resize_with_pad(img, 256, 256)
return img
img = tf.map_fn(_input_to_feature, input_image, dtype=tf.float32)
# Predict
pred = model(img)
def _pred_to_image(pred):
pred = tf.cast(pred * 255, dtype=tf.uint8)
img_str = tf.image.encode_png(pred, compression=-1, name=None)
return img_str
img_str = tf.map_fn(_pred_to_image, pred, dtype=tf.string)
return img_str
tf.saved_model.save(model, export_dir=checkpoint_dir+'/saved_model', signatures=serving)
Run Code Online (Sandbox Code Playgroud)
但是,我在发送这样的请求时收到此错误:
img_str = base64.b64encode(open('sample_372.jpg', "rb").read()).decode()
response …Run Code Online (Sandbox Code Playgroud) google-cloud-platform tensorflow-serving tensorflow2.0 gcp-ai-platform-training
我正好有这个问题:
在张量流服务模型上运行预测后,我得到了这个PredictResponse对象作为输出:
outputs {
key: "scores"
value {
dtype: DT_FLOAT
tensor_shape {
dim {
size: 1
}
dim {
size: 2
}
}
float_val: 0.407728463411
float_val: 0.592271506786
}
}
Run Code Online (Sandbox Code Playgroud)
如该问题的建议,我尝试使用:result.outputs ['outputs']。float_val
但是它返回类型 <type google.protobuf.pyext._message.RepeatedScalarContainer>
它是由这段代码产生的,灵感来自inception_client.py示例:
channel = implementations.insecure_channel(host, int(port))
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
result = stub.Predict(request, 10.0) # 10 secs timeout
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我正在尝试找到一种方法来使用 Tensorflow 服务并能够添加新模型和新版本的模型。我可以将 tensorflow 服务指向 S3 存储桶吗?
我还需要它作为容器运行吗?这是可能的还是我需要实现另一个程序来下拉模型并将其添加到共享卷并要求 tensorflow 更新文件系统中的模型?
或者我是否需要构建自己的 docker 镜像才能从 s3 中提取内容?
我在 docker-for-windows Linux 容器中拉取 tensorflow/serving
PS C:\WINDOWS\system32> docker pull tensorflow/serving
Using default tag: latest
latest: Pulling from tensorflow/serving
Digest: sha256:f7e59a29cbc17a6b507751cddde37bccad4407c05ebf2c13b8e6ccb7d2e9affb
Status: Image is up to date for tensorflow/serving:latest
docker.io/tensorflow/serving:latest
Run Code Online (Sandbox Code Playgroud)
之后,对于任何以下命令,容器都没有列出
PS C:\WINDOWS\system32> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
PS C:\WINDOWS\system32> docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
PS C:\WINDOWS\system32> docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Run Code Online (Sandbox Code Playgroud)
我也尝试重新启动 docker,请问如何解决?
docker docker-image tensorflow tensorflow-serving docker-for-windows