Tensorflow服务示例是否应具有10%的错误率?

问题描述 投票:1回答:2

我遵循了文档Building an optimized serving binary然后是Testing the development environment,然后得到

推断错误率:10.4%

是否期望重新安装TensorFlow Serving发行版会在提供的示例模型上提供10%的错误率?

我的环境:

AWS EC2
OS: Amazon Linux AMI release 2018.03
Instance Type: r5.large

复制步骤:

# download tensorflow serving code
git clone https://github.com/tensorflow/serving
cd serving
# build optimized serving binary
docker build --pull -t $USER/tensorflow-serving-devel   -f tensorflow_serving/tools/docker/Dockerfile.devel .
# run & open shell for generated docker image
docker run -it -p 8600:8600 ec2-user/tensorflow-serving-devel:latest
# train the mnist model
python tensorflow_serving/example/mnist_saved_model.py /tmp/mnist_model
# serve the model
tensorflow_model_server --port=8500 --model_name=mnist --model_base_path=/tmp/mnist_model/ &
# test the client
python tensorflow_serving/example/mnist_client.py --num_tests=1000 --server=localhost:8500
tensorflow-serving
2个回答
1
投票
作为tensorflow_serving示例的一部分的示例mnist_saved_model.py更加着重于创建模型的速度,以及一个有关如何保存模型以及准确性的简单示例。

https://www.tensorflow.org/tfx/serving/serving_advanced中,它表明当上述代码经过100次迭代训练时,其错误率为13.1%,而经过2000次迭代训练时,其错误率为9.5%。

如果未指定--training_iteration,则默认值为1000,因此您的10.4错误率符合这些结果。

您会发现此mnist模型可提供更好的准确性(并且需要更长的时间进行训练:https://github.com/tensorflow/models/tree/master/official/mnist

此模型将对mnist_client.py示例进行细微更改。

尝试此:

训练mnist模型

git clone https://github.com/tensorflow/models export PYTHONPATH="$PYTHONPATH:$PWD/models" pushd models/official/mnist/ python mnist.py --export_dir /tmp/mnist_model
为模型服务

tensorflow_model_server --port=8500 --model_name=mnist --model_base_path=/tmp/mnist_model/ &

切换回原始目录

popd

对mnist_client.py进行以下更改以使用新模型

diff --git a/tensorflow_serving/example/mnist_client.py b/tensorflow_serving/example/mnist_client.py index 592969d..85ef0bf 100644 --- a/tensorflow_serving/example/mnist_client.py +++ b/tensorflow_serving/example/mnist_client.py @@ -112,8 +112,8 @@ def _create_rpc_callback(label, result_counter): sys.stdout.write('.') sys.stdout.flush() response = numpy.array( - result_future.result().outputs['scores'].float_val) - prediction = numpy.argmax(response) + result_future.result().outputs['classes'].int64_val) + prediction = response[0] if label != prediction: result_counter.inc_error() result_counter.inc_done() @@ -143,9 +143,9 @@ def do_inference(hostport, work_dir, concurrency, num_tests): for _ in range(num_tests): request = predict_pb2.PredictRequest() request.model_spec.name = 'mnist' - request.model_spec.signature_name = 'predict_images' + request.model_spec.signature_name = 'classify' image, label = test_data_set.next_batch(1) - request.inputs['images'].CopyFrom( + request.inputs['image'].CopyFrom( tf.contrib.util.make_tensor_proto(image[0], shape=[1, image[0].size])) result_counter.throttle() result_future = stub.Predict.future(request, 5.0) # 5 seconds
测试客户端

python tensorflow_serving/example/mnist_client.py --num_tests=1000 --server=localhost:8500

Inference error rate: 0.8%


1
投票
Tensorflow服务示例是否有10%的错误率?

是的,由于该模型在训练和测试数据上的准确性几乎相同(大约90%),因此该特定示例的错误率预计为10%,即,这是一个非常基本的神经网络,如图here所示。 。

如果想要良好的预测精度,则可能必须使用resnet_client.py,或者实际上可以添加更多层并调整超参数以获得更高的预测精度或更低的推理错误率。

有关如何使用重新发送模型的教程here。这应该为您提供更少的推断错误率。

© www.soinside.com 2019 - 2024. All rights reserved.