- Install miniconda
- Clone code and checkout branch
git clone https://github.com/arylwen/fsdl_project.git fsdl_project_docker
cd fsdl_project_docker/
git checkout docker_template_exp
- Use environment.yml file for creating new environment in conda
make conda-update
conda activate fsdl_project
4a. (Optional, only if packages have changed)
make pip-tools-upgrade
- Install additional python packages in the newly created conda environment using pip-tools
make pip-tools
Refer tutorial jupyter notebook for running inference.
- Run the server
python3 semantic_search/ml_api/run.py to start the Flask Server.
- Goto http://localhost:5000/ui/.
- Goto POST /v1/predictions endpoint.
- Click on Try Now and enter text under the section "Text query to match an image" For eg. Type "Running dogs" and hit execute.
- Response will be generated under the Response Body section below.
corpus_id
- Pointing to Image Index Number in the preseeded Image Corpus
Score
- Cosine Similarity
version
- Model version
{
"errors": [],
"predictions": [
{
"corpus_id": 2,
"score": 0.237429678440094
},
{
"corpus_id": 3,
"score": 0.23457613587379456
},
{
"corpus_id": 0,
"score": 0.19539634883403778
}
],
"version": "0.1.0"
}
- Build Docker Container
sudo docker build -f docker/Dockerfile -t fsdl .
- Run docker container[bash]
sudo docker run -it -p 5000:5000 fsdl bash
sudo docker run -it -p 5000:5000 --name ml_api docker_ml_api bash
- Run the flask app
python3 ml_api/run.py
- Build and Run Docker Containers
sudo docker-compose -f docker/docker-compose.yml up -d --build
-
Ensure all 4 docker images are created and running
- Images corpus will be pulled
2. Model will be exposed at
/v1/predictions
endpoint. 2./metric
endpoint will be exposed for Prometheus server to pull monitoring data.
- Images corpus will be pulled
2. Model will be exposed at
-
Go to http://localhost:5000/ui/ and try sending the request by adding a text query.
- Ensure you get the response back as shown above in the Response body section.
Monitoring Metrics with Prometheus
-
Go to http://localhost:3000/ and login Grafana with username
admin
and passwordfoobar
-
In the home dashboard ,click on Add Datasource and select Prometheus.
-
Under HTTP-> URL section add
http://prometheus:9090
and click Save and Test. Ensure you get a message saying "Data Source is working". -
Monitor Endpoints Metrics
-
Go to Dashboards -> Browse -> New -> Import
-
Import dashboard grafana_flask_basic_dashboard_ml_api.json" present in our repository from
semantic_search/docker/config/grafana/
-
Dashboard will be loaded which is configured to monitor two metrics : Request Latency ,Latency
- Built using flask_before_request and flask_after_request hooks to capture metrics with each HTTP request to the application.
-
Try sending some requests from http://localhost:5000/ui/ , the data points will start appearing on the dashboard
-
Monitor Infrastructure Metrics
- Import dashboard basic_cadvisor_dashboard_ml_api.json" present in the repository from
semantic_search/docker/config/grafana/
-
Monitor ML Model Metrics
-
Import dashboard ml_api_dashboard.json" present in the repository from
semantic_search/docker/config/grafana/
ERROR: for ml_api no such image: sha256:c3df073f09547286f8901569a25498cb09a11d94e8e2250c80074d916eee6b90: No such image: sha256:c3df073f09547286f8901569a25498cb09a11d94e8e2250c80074d916eee6b90 ERROR: The image for the service you're trying to recreate has been removed. If you continue, volume data could be lost. Consider backing up your data before continuing.
Solution :Remove stopped docker containers
Go to semantic_search/docker and run: docker-compose rm
and remove any stopped docker container.
##List all docker containers
sudo docker container ls --all
or
sudo docker container -p