Commit 966ed5ad authored by Ubuntu's avatar Ubuntu
Browse files

First submission

parent b98553c0
# Don't track content of these folders
build/
data/inception_weights
data/weights
Mask R-CNN
The MIT License (MIT)
Copyright (c) 2017 Matterport, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
include README.md
include LICENSE
include requirements.txt
\ No newline at end of file
# MyFoodRepo Segmentation and Classification API
This repository contains the code for the machine leanrning and segmentation api used in MyFoodRepo.
This is currently hosted in Amazon EC2 instance server with ip address: **18.196.75.61**
Path to the directory containing the code in the server -
```
cd ../www/myfoodrepo-api
```
## Before running
- Create 2 directories named "weights" and "inception_weights" inside the "./data" directory.
- Then download the weights file of the trained Mask R-CNN model and graph and label files of the trained Inception V3 model by running "./download_model.py". (For this you need to include your AWS access and secret keys in the "download_model.py" file.)
## Setting up configuration to access AWS EC2 instance from local machine
By being inside your user directory type the following on terminal:
```
~ anuradha$ cd .ssh
mv ../Documents/foodrepo-visualization.pem .
vim config
```
Add the following entry to config file:
```
host foodrepo-api
Hostname 18.196.75.61
IdentityFile ~/.ssh/foodrepo-visualization.pem
User ubuntu
```
Then:
```
ssh foodrepo
```
But there comes the error:
```
Warning: Permanently added '18.196.75.61' (ECDSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/Users/anuradha/.ssh/foodrepo-visualization.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/Users/anuradha/.ssh/foodrepo-visualization.pem": bad permissions
ubuntu@18.196.75.61: Permission denied (publickey).
```
Then you need to change the permission of the .pem file to readonly mode by typing in the following command:
```
chmod 400 foodrepo-visualization.pem
```
After than you need to remove 18.196.75.61 from the list of known hosts:
```
vim known_hosts
```
Remove the entry with 18.196.75.61. Then:
```
ssh foodrepo
```
You are now on the instance. To switch to sudo mode:
```
sudo su -
```
## Troubleshooting the API
After you have switched on to the sudo mode, you will be able to see 2 tmux sessions created:
```
$ tmux ls
app: 1 windows (created Wed Oct 17 12:59:31 2018) [204x61]
worker: 1 windows (created Wed Oct 17 12:59:52 2018) [204x61]
```
You can attach each session using command:
```
$ tmux attach-session -t session_name
```
The Redis app server which listens to the external requests coming to the api is running on the tmux session "app".
Then those requests are passed to another worker server which listens to the requests coming from the Redis app server. This worker server is running on the tmux session "worker".
The worker processes the requests using the machine learning prediction functions included in "predict.py" and passes the results to the Redis app server to be delivered.
In case the servers have gone down due to some reason, you can go to the respective tmux session and view the error logs.
To restart the Redis app server and the worker server type in the following commands in the corresponding tmux sessions.
```
$ python3 app.py
```
```
$ python3 worker.py
```
## How to use the API
### Enqueue an image for prediction
```
http://ml.myfoodrepo.org/api/v2/enqueue/image_url
```
Example:
```
http://ml.myfoodrepo.org/api/v2/enqueue/https://cdn1.imggmi.com/uploads/2019/1/25/9e7cee02923a4e07c65359daee579f15-full.jpg
```
Response:
```
{"api_version":0.1,"image_id":"7e2022be1eb7dcc83182bbe9f819f483","response_channel":"myfoodrepo-imagerecognition-api::RESPONSE","status":"MYFOODREPO.IMAGE_ENQUEUED"}
```
### Check status
```
http://ml.myfoodrepo.org/api/v2/status/image_id_returned_by_previous_response
```
Example:
```
http://ml.myfoodrepo.org/api/v2/status/7e2022be1eb7dcc83182bbe9f819f483
```
Response:
```
{"api_version":0.2,"image_id":"7e2022be1eb7dcc83182bbe9f819f483","result":[{"bbox":[54.0,82.0,157.0,169.0],"myfoodrepo_category_id":1151,"score":0.020304925739765167,"segmentation":[[136.0,242.5,135.0,242.5,134.0,242.5,133.5,242.0,133.0,241.5,132.0,241.5,131.0,241.5,130.0,241.5,129.0,241.5,128.0,241.5,127.0,241.5,126.0,241.5,125.0,241.5,124.5,241.0,124.0,240.5,123.0,240.5,122.0,240.5,121.0,240.5,120.5,240.0,120.0,239.5,119.0,239.5,118.0,239.5,117.0,239.5,116.5,239.0,116.0,238.5,115.0,238.5,114.0,238.5,113.0,238.5,112.0,238.5,111.0,238.5,110.5,238.0,110.0,237.5,109.0,237.5,108.0,237.5,107.5,237.0,107.0,236.5,106.0,236.5,105.5,236.0,105.0,235.5,104.0,235.5,103.5,235.0,103.0,234.5,102.5,234.0,102.0,233.5,101.0,233.5,100.5,233.0,100.0,232.5,99.0,232.5,98.0,232.5,97.5,232.0,97.0,231.5,96.0,231.5,95.5,231.0,95.0,230.5,94.5,230.0,94.0,229.5,93.5,229.0,93.0,228.5,92.5,228.0,92.0,227.5,91.5,227.0,91.0,226.5,90.0,226.5,89.5,226.0,89.0,225.5,88.5,225.0,88.0,224.5,87.5,224.0,87.0,223.5,86.5,223.0,86.0,222.5,85.5,222.0,85.0,221.5,84.0,221.5,83.5,221.0,83.0,220.5,82.5,220.0,82.5,219.0,82.0,218.5,81.5,218.0,81.0,217.5,80.5,217.0,80.0,216.5,79.5,216.0,79.5,215.0,79.0,214.5,78.5,214.0,78.0,213.5,77.5,213.0,77.0,212.5,76.5,212.0,76.0,211.5,75.5,211.0,75.0,210.5,74.5,210.0,74.0,209.5,73.5,209.0,73.0,208.5,72.5,208.0,72.5,207.0,72.0,206.5,71.5,206.0,71.5,205.0,71.0,204.5,70.5,204.0,70.5,203.0,70.0,202.5,69.5,202.0,69.5,201.0,69.0,200.5,68.5,200.0,68.0,199.5,67.5,199.0,67.5,198.0,67.0,197.5,66.5,197.0,66.5,196.0,66.0,195.5,65.5,195.0,65.5,194.0,65.0,193.5,64.5,193.0,64.5,192.0,64.5,191.0,64.0,190.5,63.5,190.0,63.5,189.0,63.0,188.5,62.5,188.0,62.5,187.0,62.0,186.5,61.5,186.0,61.5,185.0,61.0,184.5,60.5,184.0,60.5,183.0,60.5,182.0,60.0,181.5,59.5,181.0,59.5,180.0,59.5,179.0,59.5,178.0,59.5,177.0,59.5,176.0,59.5,175.0,59.0,174.5,58.5,174.0,58.5,173.0,58.5,172.0,58.5,171.0,58.5,170.0,58.5,169.0,58.5,168.0,58.5,167.0,58.5,166.0,58.5,165.0,58.5,164.0,58.5,163.0,58.5,162.0,58.5,161.0,58.5,160.0,58.0,159.5,57.5,159.0,57.5,158.0,57.5,157.0,57.5,156.0,57.5,155.0,57.5,154.0,57.5,153.0,57.5,152.0,57.5,151.0,57.5,150.0,57.5,149.0,57.5,148.0,58.0,147.5,58.5,147.0,58.5,146.0,58.5,145.0,58.5,144.0,58.5,143.0,58.5,142.0,58.5,141.0,58.5,140.0,58.5,139.0,58.5,138.0,58.5,137.0,58.5,136.0,58.5,135.0,58.5,134.0,58.5,133.0,58.5,132.0,59.0,131.5,59.5,131.0,59.5,130.0,59.5,129.0,59.5,128.0,59.5,127.0,59.5,126.0,59.5,125.0,60.0,124.5,60.5,124.0,60.5,123.0,60.5,122.0,61.0,121.5,61.5,121.0,61.5,120.0,62.0,119.5,62.5,119.0,63.0,118.5,63.5,118.0,63.5,117.0,64.0,116.5,64.5,116.0,64.5,115.0,65.0,114.5,65.5,114.0,65.5,113.0,66.0,112.5,66.5,112.0,67.0,111.5,67.5,111.0,68.0,110.5,68.5,110.0,69.0,109.5,69.5,109.0,69.5,108.0,70.0,107.5,70.5,107.0,71.0,106.5,71.5,106.0,71.5,105.0,72.0,104.5,72.5,104.0,73.0,103.5,74.0,103.5,74.5,103.0,75.0,102.5,75.5,102.0,76.0,101.5,76.5,101.0,77.0,100.5,77.5,100.0,78.0,99.5,79.0,99.5,79.5,99.0,80.0,98.5,80.5,98.0,81.0,97.5,81.5,97.0,82.0,96.5,82.5,96.0,83.0,95.5,83.5,95.0,84.0,94.5,85.0,94.5,85.5,94.0,86.0,93.5,87.0,93.5,88.0,93.5,88.5,93.0,89.0,92.5,90.0,92.5,90.5,92.0,91.0,91.5,92.0,91.5,92.5,91.0,93.0,90.5,94.0,90.5,94.5,90.0,95.0,89.5,96.0,89.5,97.0,89.5,97.5,89.0,98.0,88.5,99.0,88.5,100.0,88.5,101.0,88.5,102.0,88.5,103.0,88.5,103.5,88.0,104.0,87.5,105.0,87.5,106.0,87.5,107.0,87.5,108.0,87.5,109.0,87.5,110.0,87.5,111.0,87.5,112.0,87.5,113.0,87.5,114.0,87.5,115.0,87.5,116.0,87.5,116.5,87.0,117.0,86.5,118.0,86.5,119.0,86.5,120.0,86.5,121.0,86.5,122.0,86.5,123.0,86.5,124.0,86.5,125.0,86.5,126.0,86.5,127.0,86.5,128.0,86.5,128.5,86.0,129.0,85.5,130.0,85.5,131.0,85.5,132.0,85.5,133.0,85.5,134.0,85.5,135.0,85.5,136.0,85.5,137.0,85.5,138.0,85.5,139.0,85.5,140.0,85.5,141.0,85.5,142.0,85.5,143.0,85.5,144.0,85.5,145.0,85.5,146.0,85.5,147.0,85.5,148.0,85.5,149.0,85.5,150.0,85.5,151.0,85.5,152.0,85.5,153.0,85.5,154.0,85.5,154.5,86.0,155.0,86.5,156.0,86.5,157.0,86.5,158.0,86.5,159.0,86.5,160.0,86.5,161.0,86.5,161.5,87.0,162.0,87.5,163.0,87.5,164.0,87.5,165.0,87.5,166.0,87.5,167.0,87.5,167.5,88.0,168.0,88.5,169.0,88.5,170.0,88.5,171.0,88.5,171.5,89.0,172.0,89.5,173.0,89.5,173.5,90.0,174.0,90.5,174.5,91.0,175.0,91.5,175.5,92.0,176.0,92.5,177.0,92.5,177.5,93.0,178.0,93.5,179.0,93.5,179.5,94.0,180.0,94.5,181.0,94.5,181.5,95.0,182.0,95.5,182.5,96.0,183.0,96.5,183.5,97.0,184.0,97.5,184.5,98.0,185.0,98.5,186.0,98.5,186.5,99.0,187.0,99.5,187.5,100.0,188.0,100.5,188.5,101.0,189.0,101.5,189.5,102.0,189.5,103.0,190.0,103.5,190.5,104.0,191.0,104.5,192.0,104.5,192.5,105.0,193.0,105.5,193.5,106.0,194.0,106.5,194.5,107.0,195.0,107.5,195.5,108.0,195.5,109.0,196.0,109.5,196.5,110.0,197.0,110.5,197.5,111.0,198.0,111.5,198.5,112.0,199.0,112.5,199.5,113.0,199.5,114.0,200.0,114.5,200.5,115.0,200.5,116.0,201.0,116.5,201.5,117.0,202.0,117.5,202.5,118.0,203.0,118.5,203.5,119.0,203.5,120.0,204.0,120.5,204.5,121.0,204.5,122.0,205.0,122.5,205.5,123.0,205.5,124.0,205.5,125.0,205.5,126.0,206.0,126.5,206.5,127.0,206.5,128.0,206.5,129.0,206.5,130.0,206.5,131.0,206.5,132.0,207.0,132.5,207.5,133.0,207.5,134.0,207.5,135.0,207.5,136.0,207.5,137.0,207.5,138.0,207.5,139.0,207.5,140.0,207.5,141.0,207.5,142.0,207.5,143.0,207.5,144.0,207.5,145.0,207.5,146.0,207.5,147.0,207.5,148.0,207.5,149.0,207.5,150.0,207.5,151.0,207.5,152.0,207.5,153.0,207.0,153.5,206.5,154.0,206.5,155.0,206.5,156.0,206.5,157.0,206.5,158.0,206.5,159.0,206.5,160.0,206.5,161.0,206.5,162.0,206.5,163.0,206.5,164.0,206.0,164.5,205.5,165.0,205.5,166.0,205.5,167.0,205.5,168.0,205.5,169.0,205.5,170.0,205.5,171.0,205.5,172.0,205.5,173.0,205.5,174.0,205.5,175.0,205.0,175.5,204.5,176.0,204.5,177.0,204.5,178.0,204.5,179.0,204.5,180.0,204.5,181.0,204.5,182.0,204.0,182.5,203.5,183.0,203.5,184.0,203.5,185.0,203.0,185.5,202.5,186.0,202.5,187.0,202.0,187.5,201.5,188.0,201.5,189.0,201.0,189.5,200.5,190.0,200.5,191.0,200.0,191.5,199.5,192.0,199.5,193.0,199.0,193.5,198.5,194.0,198.5,195.0,198.0,195.5,197.5,196.0,197.0,196.5,196.5,197.0,196.5,198.0,196.0,198.5,195.5,199.0,195.0,199.5,194.5,200.0,194.5,201.0,194.5,202.0,194.0,202.5,193.5,203.0,193.5,204.0,193.0,204.5,192.5,205.0,192.5,206.0,192.0,206.5,191.5,207.0,191.5,208.0,191.0,208.5,190.5,209.0,190.0,209.5,189.5,210.0,189.5,211.0,189.0,211.5,188.5,212.0,188.5,213.0,188.0,213.5,187.5,214.0,187.5,215.0,187.0,215.5,186.5,216.0,186.5,217.0,186.0,217.5,185.5,218.0,185.0,218.5,184.5,219.0,184.5,220.0,184.0,220.5,183.5,221.0,183.0,221.5,182.5,222.0,182.5,223.0,182.0,223.5,181.5,224.0,181.0,224.5,180.5,225.0,180.5,226.0,180.0,226.5,179.0,226.5,178.5,227.0,178.0,227.5,177.5,228.0,177.5,229.0,177.0,229.5,176.5,230.0,176.0,230.5,175.0,230.5,174.5,231.0,174.0,231.5,173.5,232.0,173.0,232.5,172.0,232.5,171.5,233.0,171.0,233.5,170.0,233.5,169.5,234.0,169.0,234.5,168.0,234.5,167.5,235.0,167.0,235.5,166.5,236.0,166.0,236.5,165.0,236.5,164.5,237.0,164.0,237.5,163.0,237.5,162.0,237.5,161.0,237.5,160.5,238.0,160.0,238.5,159.0,238.5,158.0,238.5,157.0,238.5,156.0,238.5,155.5,239.0,155.0,239.5,154.0,239.5,153.0,239.5,152.0,239.5,151.0,239.5,150.5,240.0,150.0,240.5,149.0,240.5,148.0,240.5,147.0,240.5,146.5,241.0,146.0,241.5,145.0,241.5,144.0,241.5,143.0,241.5,142.0,241.5,141.0,241.5,140.0,241.5,139.0,241.5,138.0,241.5,137.0,241.5,136.5,242.0,136.0,242.5]]},{"bbox":[221.0,90.0,147.0,152.0],"myfoodrepo_category_id":1177,"score":0.08391623944044113,"segmentation":[[305.0,239.5,304.0,239.5,303.0,239.5,302.0,239.5,301.0,239.5,300.0,239.5,299.0,239.5,298.0,239.5,297.0,239.5,296.0,239.5,295.0,239.5,294.0,239.5,293.0,239.5,292.0,239.5,291.0,239.5,290.0,239.5,289.0,239.5,288.0,239.5,287.0,239.5,286.0,239.5,285.0,239.5,284.5,239.0,284.0,238.5,283.0,238.5,282.0,238.5,281.0,238.5,280.5,238.0,280.0,237.5,279.0,237.5,278.0,237.5,277.0,237.5,276.5,237.0,276.0,236.5,275.0,236.5,274.0,236.5,273.0,236.5,272.0,236.5,271.5,236.0,271.0,235.5,270.0,235.5,269.0,235.5,268.0,235.5,267.5,235.0,267.0,234.5,266.0,234.5,265.5,234.0,265.0,233.5,264.0,233.5,263.5,233.0,263.0,232.5,262.0,232.5,261.5,232.0,261.0,231.5,260.0,231.5,259.0,231.5,258.5,231.0,258.0,230.5,257.0,230.5,256.5,230.0,256.0,229.5,255.0,229.5,254.5,229.0,254.0,228.5,253.5,228.0,253.0,227.5,252.5,227.0,252.0,226.5,251.0,226.5,250.5,226.0,250.0,225.5,249.5,225.0,249.0,224.5,248.0,224.5,247.5,224.0,247.0,223.5,246.5,223.0,246.0,222.5,245.5,222.0,245.0,221.5,244.5,221.0,244.0,220.5,243.5,220.0,243.0,219.5,242.5,219.0,242.0,218.5,241.5,218.0,241.0,217.5,240.5,217.0,240.0,216.5,239.5,216.0,239.0,215.5,238.5,215.0,238.0,214.5,237.5,214.0,237.0,213.5,236.5,213.0,236.5,212.0,236.0,211.5,235.5,211.0,235.5,210.0,235.0,209.5,234.5,209.0,234.0,208.5,233.5,208.0,233.5,207.0,233.0,206.5,232.5,206.0,232.5,205.0,232.0,204.5,231.5,204.0,231.5,203.0,231.0,202.5,230.5,202.0,230.5,201.0,230.5,200.0,230.0,199.5,229.5,199.0,229.5,198.0,229.5,197.0,229.0,196.5,228.5,196.0,228.5,195.0,228.0,194.5,227.5,194.0,227.5,193.0,227.5,192.0,227.0,191.5,226.5,191.0,226.5,190.0,226.5,189.0,226.5,188.0,226.5,187.0,226.0,186.5,225.5,186.0,225.5,185.0,225.5,184.0,225.5,183.0,225.5,182.0,225.5,181.0,225.5,180.0,225.5,179.0,225.5,178.0,225.0,177.5,224.5,177.0,224.5,176.0,224.5,175.0,224.5,174.0,224.5,173.0,224.5,172.0,224.5,171.0,224.5,170.0,224.5,169.0,224.5,168.0,224.5,167.0,224.5,166.0,224.5,165.0,224.5,164.0,224.5,163.0,224.5,162.0,224.0,161.5,223.5,161.0,223.5,160.0,223.5,159.0,223.5,158.0,223.5,157.0,223.5,156.0,223.5,155.0,224.0,154.5,224.5,154.0,224.5,153.0,224.5,152.0,224.5,151.0,224.5,150.0,224.5,149.0,224.5,148.0,224.5,147.0,224.5,146.0,224.5,145.0,224.5,144.0,225.0,143.5,225.5,143.0,225.5,142.0,225.5,141.0,225.5,140.0,225.5,139.0,225.5,138.0,226.0,137.5,226.5,137.0,226.5,136.0,226.5,135.0,226.5,134.0,226.5,133.0,227.0,132.5,227.5,132.0,227.5,131.0,228.0,130.5,228.5,130.0,228.5,129.0,229.0,128.5,229.5,128.0,229.5,127.0,230.0,126.5,230.5,126.0,230.5,125.0,231.0,124.5,231.5,124.0,232.0,123.5,232.5,123.0,232.5,122.0,233.0,121.5,233.5,121.0,234.0,120.5,234.5,120.0,235.0,119.5,235.5,119.0,235.5,118.0,236.0,117.5,236.5,117.0,237.0,116.5,237.5,116.0,237.5,115.0,238.0,114.5,238.5,114.0,239.0,113.5,239.5,113.0,240.0,112.5,240.5,112.0,240.5,111.0,241.0,110.5,241.5,110.0,242.0,109.5,242.5,109.0,243.0,108.5,243.5,108.0,244.0,107.5,244.5,107.0,245.0,106.5,245.5,106.0,246.0,105.5,246.5,105.0,247.0,104.5,247.5,104.0,248.0,103.5,248.5,103.0,249.0,102.5,249.5,102.0,250.0,101.5,250.5,101.0,251.0,100.5,252.0,100.5,252.5,100.0,253.0,99.5,253.5,99.0,254.0,98.5,255.0,98.5,255.5,98.0,256.0,97.5,256.5,97.0,257.0,96.5,257.5,96.0,258.0,95.5,259.0,95.5,259.5,95.0,260.0,94.5,261.0,94.5,261.5,94.0,262.0,93.5,263.0,93.5,263.5,93.0,264.0,92.5,265.0,92.5,265.5,92.0,266.0,91.5,267.0,91.5,267.5,91.0,268.0,90.5,269.0,90.5,270.0,90.5,271.0,90.5,272.0,90.5,272.5,90.0,273.0,89.5,274.0,89.5,275.0,89.5,276.0,89.5,277.0,89.5,278.0,89.5,279.0,89.5,280.0,89.5,281.0,89.5,282.0,89.5,283.0,89.5,284.0,89.5,285.0,89.5,286.0,89.5,287.0,89.5,288.0,89.5,289.0,89.5,290.0,89.5,291.0,89.5,292.0,89.5,293.0,89.5,294.0,89.5,295.0,89.5,296.0,89.5,297.0,89.5,298.0,89.5,299.0,89.5,300.0,89.5,301.0,89.5,302.0,89.5,303.0,89.5,304.0,89.5,305.0,89.5,306.0,89.5,307.0,89.5,308.0,89.5,309.0,89.5,310.0,89.5,311.0,89.5,312.0,89.5,313.0,89.5,314.0,89.5,315.0,89.5,316.0,89.5,317.0,89.5,318.0,89.5,319.0,89.5,319.5,90.0,320.0,90.5,321.0,90.5,322.0,90.5,323.0,90.5,324.0,90.5,324.5,91.0,325.0,91.5,326.0,91.5,326.5,92.0,327.0,92.5,328.0,92.5,328.5,93.0,329.0,93.5,329.5,94.0,330.0,94.5,331.0,94.5,331.5,95.0,332.0,95.5,333.0,95.5,333.5,96.0,334.0,96.5,335.0,96.5,335.5,97.0,336.0,97.5,336.5,98.0,337.0,98.5,337.5,99.0,338.0,99.5,339.0,99.5,339.5,100.0,340.0,100.5,341.0,100.5,341.5,101.0,342.0,101.5,343.0,101.5,343.5,102.0,344.0,102.5,344.5,103.0,345.0,103.5,345.5,104.0,346.0,104.5,346.5,105.0,347.0,105.5,348.0,105.5,348.5,106.0,349.0,106.5,349.5,107.0,350.0,107.5,350.5,108.0,351.0,108.5,351.5,109.0,351.5,110.0,352.0,110.5,352.5,111.0,353.0,111.5,353.5,112.0,354.0,112.5,354.5,113.0,355.0,113.5,355.5,114.0,355.5,115.0,356.0,115.5,356.5,116.0,357.0,116.5,357.5,117.0,357.5,118.0,358.0,118.5,358.5,119.0,358.5,120.0,359.0,120.5,359.5,121.0,360.0,121.5,360.5,122.0,361.0,122.5,361.5,123.0,361.5,124.0,361.5,125.0,362.0,125.5,362.5,126.0,362.5,127.0,362.5,128.0,363.0,128.5,363.5,129.0,363.5,130.0,364.0,130.5,364.5,131.0,364.5,132.0,365.0,132.5,365.5,133.0,365.5,134.0,365.5,135.0,366.0,135.5,366.5,136.0,366.5,137.0,366.5,138.0,366.5,139.0,366.5,140.0,366.5,141.0,366.5,142.0,366.5,143.0,367.0,143.5,367.5,144.0,367.5,145.0,367.5,146.0,367.5,147.0,367.5,148.0,367.5,149.0,367.5,150.0,367.5,151.0,367.5,152.0,367.5,153.0,367.5,154.0,367.5,155.0,367.5,156.0,367.5,157.0,367.5,158.0,367.5,159.0,367.5,160.0,367.5,161.0,367.5,162.0,367.5,163.0,367.5,164.0,367.5,165.0,367.5,166.0,367.5,167.0,367.5,168.0,367.5,169.0,367.5,170.0,367.5,171.0,367.5,172.0,367.5,173.0,367.5,174.0,367.5,175.0,367.5,176.0,367.5,177.0,367.5,178.0,367.5,179.0,367.0,179.5,366.5,180.0,366.5,181.0,366.5,182.0,366.5,183.0,366.5,184.0,366.5,185.0,366.5,186.0,366.5,187.0,366.0,187.5,365.5,188.0,365.5,189.0,365.5,190.0,365.0,190.5,364.5,191.0,364.5,192.0,364.0,192.5,363.5,193.0,363.5,194.0,363.0,194.5,362.5,195.0,362.5,196.0,362.0,196.5,361.5,197.0,361.5,198.0,361.5,199.0,361.0,199.5,360.5,200.0,360.0,200.5,359.5,201.0,359.5,202.0,359.0,202.5,358.5,203.0,358.0,203.5,357.5,204.0,357.0,204.5,356.5,205.0,356.5,206.0,356.0,206.5,355.5,207.0,355.0,207.5,354.5,208.0,354.0,208.5,353.5,209.0,353.0,209.5,352.5,210.0,352.5,211.0,352.0,211.5,351.5,212.0,351.5,213.0,351.0,213.5,350.5,214.0,350.0,214.5,349.5,215.0,349.0,215.5,348.0,215.5,347.5,216.0,347.0,216.5,346.5,217.0,346.5,218.0,346.0,218.5,345.5,219.0,345.0,219.5,344.5,220.0,344.0,220.5,343.0,220.5,342.5,221.0,342.0,221.5,341.5,222.0,341.5,223.0,341.0,223.5,340.5,224.0,340.0,224.5,339.0,224.5,338.5,225.0,338.0,225.5,337.0,225.5,336.5,226.0,336.0,226.5,335.5,227.0,335.0,227.5,334.5,228.0,334.0,228.5,333.0,228.5,332.5,229.0,332.0,229.5,331.5,230.0,331.0,230.5,330.0,230.5,329.5,231.0,329.0,231.5,328.0,231.5,327.5,232.0,327.0,232.5,326.5,233.0,326.0,233.5,325.5,234.0,325.0,234.5,324.0,234.5,323.5,235.0,323.0,235.5,322.0,235.5,321.0,235.5,320.0,235.5,319.5,236.0,319.0,236.5,318.0,236.5,317.0,236.5,316.0,236.5,315.0,236.5,314.5,237.0,314.0,237.5,313.0,237.5,312.0,237.5,311.0,237.5,310.0,237.5,309.5,238.0,309.0,238.5,308.0,238.5,307.0,238.5,306.0,238.5,305.5,239.0,305.0,239.5]]}],"size":[286,420],"status":"MYFOODREPO.IMAGE_PROCESSED"}
```
## Authors
Kalpani Anuradha Welivita [(kalpani.welivita@epfl.ch)](kalpani.welivita@epfl.ch)
Sharada Mohanty [(sharada.mohanty@epfl.ch)](sharada.mohanty@epfl.ch)
#!/usr/bin/env python
import os
import json
import matplotlib.image as mpimg
from .predict import predict_output, predict_output_base64
def predict_file_at_path(img_path):
print(img_path)
ROOT_DIR = os.getcwd()
file_path = os.path.join(ROOT_DIR, img_path)
image = mpimg.imread(file_path)
img_size = [image.shape[0], image.shape[1]]
output = predict_output(image)
return output, img_size
def evaluate(test_images_path, predictions_output_path):
images = [f for f in os.listdir(test_images_path) if os.path.isfile(os.path.join(test_images_path, f))]
predictions = []
for image in images:
output, img_size = predict_file_at_path(test_images_path + "/" + image)
image_id = int(os.path.basename(image).replace(".jpg", ""))
for prediction in output:
prediction["image_id"] = image_id
predictions.append(output)
break
fp = open(predictions_output_path, "w")
fp.write(json.dumps(predictions))
fp.close()
print("PREDICTIONS WRITTEN TO", predictions_output_path)
#!/usr/bin/env ptyhon
from flask import Flask, jsonify, abort, request
import redis
import config
import hashlib
import json
"""
Instantitate
"""
POOL = redis.ConnectionPool(host=config.REDIS_HOST, port=config.REDIS_PORT, db=config.REDIS_DB, password=config.REDIS_AUTH_PASSWORD)
app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 80971520
@app.route('/api/v2/enqueue/<path:url>', methods=['GET'])
def enqueue(url):
redis_conn = redis.Redis(connection_pool=POOL)
try :
image_id = hashlib.md5(url).hexdigest()
except:
image_id = hashlib.md5(url.encode('utf-8')).hexdigest()
cached_result = None
if cached_result == None:
query = {"type" : "url", "image_id":image_id, "url":url}
redis_conn.rpush("{}::{}".format(config.REDIS_NAMESPACE, config.QUEUE_KEY), json.dumps(query))
status = "MYFOODREPO.IMAGE_ENQUEUED"
_response = {"image_id":image_id, "status":status, "response_channel":config.RESPONSE_CHANNEL, "api_version":"0.3"}
# Store processing status in a hash
redis_conn.hset("{}::status".format(config.REDIS_NAMESPACE), image_id, json.dumps(_response))
return jsonify(_response)
else:
# Push results into response channel for consistency
redis_conn.rpush(config.RESPONSE_CHANNEL, cached_result)
return jsonify(json.loads(cached_result.decode("utf-8")))
@app.route('/api/v2/enqueue_base64', methods=['POST'])
def enqueue_base64():
redis_conn = redis.Redis(connection_pool=POOL)
#print(request.data)
image_base64 = request.form.get('image_base64')
query = {"type":"base64", "image_base64":image_base64}
image_id = hashlib.md5(image_base64.encode("utf-8")).hexdigest()
query["image_id"] = image_id
redis_conn.rpush("{}::{}".format(config.REDIS_NAMESPACE, config.QUEUE_KEY), json.dumps(query))
status = "MYFOODREPO.IMAGE_ENQUEUED"
_response = {"image_id": image_id , "status":status, "response_channel":config.RESPONSE_CHANNEL, "demo":"0.2"}
redis_conn.hset("{}::status".format(config.REDIS_NAMESPACE), query["image_id"], json.dumps(_response))
return jsonify(_response)
@app.route('/api/v2/status/<path:image_id>', methods=['GET'])
def status(image_id):
image_id = image_id.strip()
redis_conn = redis.Redis(connection_pool=POOL)
result = redis_conn.hget("{}::status".format(config.REDIS_NAMESPACE), image_id)
if result == None:
abort(404)
else:
return jsonify(json.loads(result.decode("utf-8")))
if __name__ == '__main__':
app.run(host='0.0.0.0',port=80 ,debug=config.DEBUG_MODE)
["1004", "1010", "1013", "1022", "1024", "1026", "1032", "1033", "1038", "1040", "1050", "1055", "1056", "1058", "1060", "1061", "1068", "1069", "1070", "1074", "1075", "1078", "1082", "1084", "1085", "1092", "1098", "1102", "1107", "1108", "1113", "1116", "1119", "1123", "1124", "1143", "1144", "1150", "1151", "1152", "1153", "1154", "1156", "1157", "1162", "1163", "1166", "1169", "1170", "1176", "1180", "1184", "1187", "1199", "1200", "1209", "1210", "1212", "1213", "1214", "1220", "1221", "1228", "1229", "1237", "1249", "1294", "1307", "1308", "1310", "1311", "1321", "1323", "1327", "1348", "1352", "1374", "1402", "1422", "1455", "1463", "1467", "1468", "1469", "1483", "1490", "1496", "1505", "1506", "1513", "1520", "1523", "1538", "1545", "1554", "1556", "1557", "1560", "1561", "1565", "1566", "1568", "1569", "1587", "1588", "1607", "1627", "1670", "1724", "1730", "1748", "1788", "1789", "1853", "1857", "1879", "1889", "1893", "1915", "1916", "1924", "1948", "1956", "1967", "1980", "1986", "2022", "2043", "2053", "2073", "2084", "2099", "2103", "2131", "2132", "2134", "2172", "2194", "2203", "2237", "2254", "2269", "2278", "2303", "2320", "2350", "2362", "2388", "2446", "2454", "2470", "2495", "2498", "2501", "2504", "2512", "2521", "2524", "2530", "2534", "2543", "2555", "2562", "2578", "2580", "2610", "2616", "2618", "2620", "2634", "2636", "2711", "2714", "2728", "2730", "2734", "2736", "2738", "2741", "2742", "2743", "2747", "2749", "2750", "2836", "2859", "2898", "2905", "2923", "2930", "2935", "2939", "2941", "2944", "2952", "2961", "2964", "2970", "2973", "3042", "3080", "3082", "3100", "3220", "3249", "3258", "3262", "3293", "3306", "3336", "3630", "5641"]
\ No newline at end of file
["1004", "1010", "1013", "1022", "1024", "1026", "1032", "1033", "1038", "1040", "1050", "1055", "1056", "1058", "1060", "1061", "1068", "1069", "1070", "1074", "1075", "1078", "1082", "1084", "1085", "1092", "1098", "1102", "1107", "1108", "1113", "1116", "1119", "1123", "1124", "1143", "1144", "1150", "1151", "1152", "1153", "1154", "1156", "1157", "1162", "1163", "1166", "1169", "1170", "1176", "1180", "1184", "1187", "1199", "1200", "1209", "1210", "1212", "1213", "1214", "1220", "1221", "1228", "1229", "1237", "1249", "1294", "1307", "1308", "1310", "1311", "1321", "1323", "1327", "1348", "1352", "1374", "1402", "1422", "1455", "1463", "1467", "1468", "1469", "1483", "1490", "1496", "1505", "1506", "1513", "1520", "1523", "1538", "1545", "1554", "1556", "1557", "1560", "1561", "1565", "1566", "1568", "1569", "1587", "1588", "1607", "1627", "1670", "1724", "1730", "1748", "1788", "1789", "1853", "1857", "1879", "1889", "1893", "1915", "1916", "1924", "1948", "1956", "1967", "1980", "1986", "2022", "2043", "2053", "2073", "2084", "2099", "2103", "2131", "2132", "2134", "2172", "2194", "2203", "2237", "2254", "2269", "2278", "2303", "2320", "2350", "2362", "2388", "2446", "2454", "2470", "2495", "2498", "2501", "2504", "2512", "2521", "2524", "2530", "2534", "2543", "2555", "2562", "2578", "2580", "2610", "2616", "2618", "2620", "2634", "2636", "2711", "2714", "2728", "2730", "2734", "2736", "2738", "2741", "2742", "2743", "2747", "2749", "2750", "2836", "2859", "2898", "2905", "2923", "2930", "2935", "2939", "2941", "2944", "2952", "2961", "2964", "2970", "2973", "3042", "3080", "3082", "3100", "3220", "3249", "3258", "3262", "3293", "3306", "3336", "3630", "5641", "done"]
\ No newline at end of file
This diff is collapsed.
REDIS_HOST="localhost"
REDIS_PORT=6379
REDIS_DB=0
REDIS_NAMESPACE="myfoodrepo-imagerecognition-api"
REDIS_AUTH_PASSWORD=""
QUEUE_KEY="Q"
RESPONSE_CHANNEL="{}::{}".format(REDIS_NAMESPACE,"RESPONSE")
GPU_MODE=False
DEBUG_MODE=False
MODEL_DIRECTORY = "new_model_v1.1"
{
"categories":[
{
"id": "1009",
"name": "Potato-gnocchi"
},
{
"id": "1013",
"name": "Chips, french fries"
},
{
"id": "1361",
"name": "Crème brûlée"
},
{
"id": "1367",
"name": "Panna cotta"
},
{
"id": "1371",
"name": "Tiramisu"
},
{
"id": "1500",
"name": "Pasta, ravioli, stuffing"
},
{
"id": "1708",
"name": "Meat carpaccio"
},
{
"id": "1717",
"name": "Escalope"
},
{
"id": "1791",
"name": "Chicken, wing"
},
{
"id": "1967",
"name": "Salmon"
},
{
"id": "1984",
"name": "Calamar"
},
{
"id": "1986",
"name": "Shrimp / prawn (large)"
},
{
"id": "1995",
"name": "Blue mussels"
},
{
"id": "1997",
"name": "Oysters"
},
{
"id": "1998",
"name": "Snails"
},
{
"id": "2234",
"name": "Cupcake"
},
{
"id": "2237",
"name": "Apple pie"
},
{
"id": "2265",
"name": "Churros"
},
{
"id": "2270",
"name": "Donut"
},
{
"id": "2277",
"name": "French toast"
},
{
"id": "2303",
"name": "Cake, chocolate"
},
{
"id": "2320",
"name": "Omelette, plain"
},
{
"id": "2333",
"name": "Carrot cake"
},
{
"id": "2355",
"name": "Waffle"
},
{
"id": "2365",
"name": "Macaroon"
},
{
"id": "2736",
"name": "Bolognaise sauce"
},
{
"id": "2749",
"name": "Guacamole"
},
{
"id": "2846",
"name": "Soup, Miso"
},
{
"id": "2873",
"name": "Falafel (balls)"
},
{
"id": "2910",
"name": "Bruschette"
},
{
"id": "2918",
"name": "Spring roll (fried)"
},
{
"id": "2924",
"name": "Samosa"
},
{
"id": "2930",
"name": "Burger"
},
{
"id": "2931",
"name": "Cannelloni"
},
{
"id": "2934",
"name": "Lasagna"
},
{
"id": "2939",
"name": "Pizza"
},
{
"id": "2941",
"name": "Sandwich"
},
{
"id": "2942",
"name": "Takoyaki"
},
{
"id": "2943",
"name": "Tacos"
},
{
"id": "2944",
"name": "Sushi"
},
{
"id": "2945",
"name": "Sashimi"
},
{
"id": "2946",
"name": "Ramen"
},
{
"id": "2947",
"name": "Gyro sandwich"
},
{
"id": "2949",
"name": "Pancakes"
},
{
"id": "2950",
"name": "Paella"
},
{
"id": "2951",
"name": "Onion rings"
},
{
"id": "2952",
"name": "Hummus"
},
{
"id": "2953",
"name": "Gyoza"
},
{
"id": "2954",
"name": "Greek salad"
},
{
"id": "2955",
"name": "Frozen yogurt"
},
{
"id": "2956",
"name": "Fried rice"
},
{
"id": "2957",
"name": "Foie gras"
},
{
"id": "2958",
"name": "Fish and chips"
},
{
"id": "2959",
"name": "Dumplings"
},
{
"id": "2961",
"name": "Chocolate mousse"
},
{
"id": "2962",
"name": "Cheesecake"
},
{
"id": "2964",
"name": "Caprese salad (Tomato Mozzarella)"
},
{
"id": "2965",
"name": "Baklava"
}
]
}
This diff is collapsed.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 13 14:20:26 2019
@author: tati
"""
import uuid
import requests
url = 'https://s3.eu-central-1.amazonaws.com/myfoodrepo-stg/image_media/files/000/000/045/original/6e37ac54.jpeg?response-content-disposition=inline&X-Amz-Security-Token=AgoGb3JpZ2luEBUaDGV1LWNlbnRyYWwtMSKAAkElAgtGHpZXseAlfDZ7o%2B%2Bu73e4zgfgqLKEBmfyJmfW10boYWC%2FEZivdrN6uKG432hKkt3uoB4kiXK7EII6cj5MTGL0fzPGiVoOl0Db4rLgR1pjruHP%2FqyJmccpTO5zmjh%2F9xj5B%2Bm9wovWtynWgMZJcYkpSYIKTTiOogaib6JS0kOyH7QhFN41wDFqplnQkMFS7S%2BdDMQ9LyzgkOjUfi4sA2fqWwda4BZLi9AT6IlTCUnxBPVPudbZI2yxle8wMGFjhPbbfgooNJwhYYKHd0JzMwtUGJN53%2FcjOyoTkjZ84xsWXezFoMVEIJvuIc81mpEIszulUDdsoJE8jJQyaRMq%2BwMIu%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FARAAGgw4NzQ5NDI2NTcxMzAiDLBWb12v3taWngsbISrPAyH%2B7703Rv0BJkTGEII440Z8yYNSypbGmxgM0tFd8TXOo%2FmHyjLfa9c9UPKQQWVl8TuMMVvH%2BFI99t%2BBRZ4YkkDIqVwlg%2BoQE7jSrCOX7UyrYaZjjbpMK3JAWQwbiiZdTuXW8%2BTHhuPPO008VVpMNfmqEejsQGX8lGoZRcK4K7sN4qmVSzlkwyw%2Fpt%2BSfPe24b2v6ofZBTk9lV%2BqEtVdGm52Yy%2BMZ4fKdZcNz3xb3dPr%2FBDgRt5RXhE4Ihi81LZ6ljSGOEdrKqcawtApq8BnGSJhKfKPO7CS3j%2BuSjs8Vj%2FGZvmJxu4U%2B4l38XNQ8Yr25v5vXZ7ao4KuV0T0786cSZwW0zr6mrYBShp75Dh1MFO10GhLnOYcA0rIEoTQ7cxF9Sm5fmKgMrr%2BgaBEWyJyKrUY62mPfJyjWcDl5kdOBKo5ug4PNLAX7wBQUUps2M43qullSJbk%2Ba%2BMUuc1bhyQoDwGRLqtwglrNuZSBrANrspsiagLRkPUXPkuwC7zCkCKMKei34oW6Mu9nT3B9LynsF0eQO3is59UVp26pqwFOXj5%2FMamafLxhJc2wYeuQNcPqDTpwOaNyMj9fXaZVT7TFEALKR4Yijcjy9ZDpWUHXGEwgfrk5gU%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20190513T094908Z&X-Amz-SignedHeaders=host&X-Amz-Expires=300&X-Amz-Credential=ASIA4XNVFOJVARMOQ62H%2F20190513%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Signature=25aa654ed871e3397f9246dfe43e990394a725b91b8954987ee9e66645a1832f'
filename = "temp/"+str(uuid.uuid4())+".jpg"
image_data = requests.get(url).content
f = open(filename, "wb")
f.write(image_data)
f.close()
\ No newline at end of file
from boto3.session import Session
import botocore
ACCESS_KEY = 'AKIAIRZOMWEOYH42QMQQ'
SECRET_KEY = '3xzZ14VX3iUtVpvjuCcTtA2cQxSydYpNSZVOeajg'
session = Session(aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
s3 = session.resource('s3')
your_bucket = s3.Bucket('myfoodrepo-ml-models')
try:
your_bucket.download_file('mask_rcnn_myfoodrepo_0159.h5', './data/weights/mask_rcnn_myfoodrepo_0159.h5')
your_bucket.download_file('output_graph_inceptionv3_test1.pb', './data/inception_weights/output_graph_inceptionv3_test1.pb')
your_bucket.download_file('output_labels_inceptionv3_test1.txt', './data/inception_weights/output_labels_inceptionv3_test1.txt')
#your_bucket.download_file('categories_all_523.json', './data/annotations/categories_all_523.json')
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "404":
print("The object does not exist.")
else:
raise
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment