I am Xiandong QI with email: xqiad@connect.ust.hk. I chose the following task:
- An English word image generators, then feed it to machine learning model [preferably neural network] to recognize the word from the image
and finished 3 bonus:
- Deliver an API to call the program
- Push the program as a Docker Image to Docker Hub
- Demonstrate the use of Cloud Computing for the solution
- Go to current folder
- Run
pythoh bnp_app.py
- Open another terminal and input (use word "bad" as an example)
curl --data input_word="bad" http://localhost:5000/predict
Then, the prediction result is returned.
{"pred_texts":["bad"],"top_3_paths":["bad","pbad","kbad"]}
docker pull xiandong/bnp-app
sudo docker run -d -p 5000:5000 xiandong/bnp-app
curl --data input_word="bad" http://localhost:5000/predict
python train_image_ocr.py
And a new folder image_ocr
with the new model weights will be recorded.
Next, you can replace the model path in Dockerfile
and bnp_app.py
as you wish.
run:
sudo docker build -t bnp-app:latest .
Now let’s run our Docker container to test our app:
sudo docker run -d -p 5000:5000 bnp-app
# docker stop <CONTAINER ID> i.e., bd7b477188a5
by running
sudo docker ps -a
docker logs <CONTAINER ID> i.e., f2672b5aff0a
open another terminal and input (use "small" as an example)
curl --data input_word="small" http://localhost:5000/predict
curl --data input_word="good" http://localhost:5000/predict
curl --data input_word="am" http://localhost:5000/predict
curl --data input_word="bad" http://localhost:5000/predict
Then, the result is returned.
sudo docker login
sudo docker images
sudo docker tag <IMAGE ID, d03fcc88da88> xiandong/bnp-app
sudo docker push xiandong/bnp-app
docker pull xiandong/bnp-app
sudo docker run -d -p 5000:5000 xiandong/bnp-app
curl --data input_word="bad" http://localhost:5000/predict
Now we run our docker container in Kubernetes. Note that the image tag is just pointing to our hosted docker image on Docker Hub. In addition, we’ll specify with --port that we want to run our app on port 5000.
kubectl run bnp-app --image=xiandong/bnp-app --port 5000
# We can verify that our pod is running by typing
kubectl get pods
# anyone visiting the IP address of our deployment can access our API.
kubectl expose deployment bnp-app --type=LoadBalancer --port 80 --target-port 5000
# running
kubectl get service
# curl --data input_word="bad" http://localhost:5000/predict
curl --data input_word="bad" http://<EXTERNAL-IP of k8s>/predict
As you can see below, the API correctly returns the label of beagle for the picture.
{"pred_texts":["bad"],"top_3_paths":["bad","pbad","kbad"]}
- https://github.com/keras-team/keras/blob/master/examples/image_ocr.py
- https://medium.com/analytics-vidhya/deploy-your-first-deep-learning-model-on-kubernetes-with-python-keras-flask-and-docker-575dc07d9e76
- https://github.com/Tony607/keras-image-ocr
- https://www.dlology.com/blog/how-to-train-a-keras-model-to-recognize-variable-length-text/
- tensorflow/tensorflow#14356
- https://stackoverflow.com/questions/24808043/importerror-no-module-named-scipy
- https://github.com/nicholastoddsmith/pythonml
- https://www.pyimagesearch.com/2017/07/10/using-tesseract-ocr-python/
- https://towardsdatascience.com/intuitively-understanding-connectionist-temporal-classification-3797e43a86c
- Sequence Modeling With CTC
- https://towardsdatascience.com/build-a-handwritten-text-recognition-system-using-tensorflow-2326a3487cd5
- https://towardsdatascience.com/faq-build-a-handwritten-text-recognition-system-using-tensorflow-27648fb18519