定义Dockerfile

FROM 10.110.13.208:5000/1xiu/tensorflow_serving:4.0
MAINTAINER kevin [email protected]

WORKDIR /serving
RUN pip install tensorflow-serving-api && pip install Flask && pip install flask-restful
RUN apt-get install supervisor -y
COPY start.sh /serving
COPY app.py /serving/tensorflow_serving/example
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN chmod +x ./start.sh && mkdir -p /var/log/supervisor

EXPOSE 10010
CMD ["/usr/bin/supervisord"]

配置supervisord.conf

[supervisord]
nodaemon=true
[program:tensorflow]
command=/bin/bash -c "/serving/start.sh"

配置start.sh

#!/bin/bash
tensorflow_model_server --port=9000 --model_name=mnist --model_base_path=/tmp/mnist_model/ &> /var/log/supervisor/mnist_log &
/usr/bin/python /serving/tensorflow_serving/example/app.py --num_tests=1000 --server=localhost:9000 &> /var/log/supervisor/mnist_app_log &

创建app.py

from flask import Flask
from flask.ext import restful
from mnist_client import do_inference

app = Flask(__name__)
api = restful.Api(app)

class HelloWorld(restful.Resource):
    def get(self):
        error_rate=do_inference("localhost:9000","/tmp",1,1000)
        return {'error_rate': error_rate}

api.add_resource(HelloWorld, '/')

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=10010,debug=True)

results matching ""

    No results matching ""