S-Leaf: Leaf recognition for plant information retrieval is a system in the form of an application that is able to identify different plant species based on the leaf object of the plant.
To train the model, you can use this training notebook.
If you want to use the background images we use on this experiment, you can download it on this link and upload it to your Google Drive.
- From GCP Dashboard click Navigation menu and click compute engine on compute section
- Make sure you at VM Instance and click create instance
- Name your instance example instance-2
- Choose us-central-1 for region and us-central1-a for zone (optional)
- On Machine Configuration, on series section choose N1 Series and choose n1-standard-1 on machine type section
- You can choose any boot disk whatever do you want, for my case i choose ubuntu 18.04
- Checklist on Allow HTTP traffic and Allow HTTPS traffic on Firewall section (this turn for endpoint case if you want connect it to your android/web application)
- Click Management, security, disks, networking, sole tenancy
- Click on Networking
- Fill flask-server on Network tags
- At last click create
The purpose of making VPC network is to connect the network from the VM to the browser
- Click VPC network on Navigation menu
- If you already on VPC Network click firewall
- Click Create Firewall rule
- On Create Firewall rule name your Firewall rule, on my case i name it allow-flask
- On Target tags fill with flask-server and On Source IP ranges fill with 0.0.0.0/0
- Make sure you setting TCP on 5000 (this thing for port)
- At last click create
[!] After training, make sure that you already save your model in your drive.
If you want to use our pre-trained model, you can download it on our drive:
To deploy the model on Google Compute Engine, make sure you have docker installed on your machine, then do following steps:
- Clone this repository on your VM instance
- Go to
server/main_server
. - Download your model that's already saved in Google Drive by following this tutorial.
Save it inserver/main_server/model
.
Then, go to the model dir, and unzip the model:unzip [YOUR_ZIPPED_MODEL]
- Go back to
server/main_server
dir. Build your docker image by running this command:sudo docker build -t sleaf:latest .
- Run your docker image.
sudo docker run --detach -v "$(pwd)/model/[your model dir]:/app/model/custom_bgmodify" -p 80:8080 sleaf:latest
- Test your API. Run this command on your CLI:
You should get this response:
curl http://127.0.0.1/
If you have checked Allow HTTP traffic on your Firewall setting, you can access the API from external machine.Welcome to S-LEAF!
You can check the detail of the API on this documentation.curl http://[YOUR_VM_EXTERNAL_IP]
To test the model deployment, you need to use the Application.
- Make sure you are in the
server/main_server
directory. - Open the
app.yaml
, and edit these lines based on your project:host: "[ENDPOINT NAME].endpoints.[YOUR PROJECT].cloud.goog" x-google-endpoints: - name: "[ENDPOINT NAME].endpoints.[YOUR PROJECT].cloud.goog" target: "[YOUR VM IP]" schemes: - "http"
- Upload the configuration and create a managed service.
gcloud endpoints services deploy app.yaml
- Use the following command to confirm that the required services are enabled:
If you do not see the required services listed, enable them:
gcloud services list
Also enable your Endpoints service:gcloud services enable servicemanagement.googleapis.com gcloud services enable servicecontrol.googleapis.com gcloud services enable endpoints.googleapis.com
gcloud services enable [ENDPOINTS_SERVICE_NAME]
ENDPOINTS_SERVICE_NAME
is the full name you specified on yourapp.yaml
file as in thehost
field.
[!] Make sure you have Docker installed in your VM instance.
- Create your own container network called
esp_net
:sudo docker network create --driver bridge esp_net
- Run the S-Leaf server:
sudo docker run --detach --name sleaf_api -v "$(pwd)/model/[your model dir]:/app/model/custom_bgmodify" sleaf:latest
- Run the pre-packaged public ESP Docker container. In the ESP startup options, replace
SERVICE_NAME
with the name of your service. This is the same name that you configured in the host field of your OpenAPI document (app.yaml
).sudo docker run \ --name=esp \ --detach \ --publish=80:8080 \ --net=esp_net \ gcr.io/endpoints-release/endpoints-runtime:1 \ --service=SERVICE_NAME \ --rollout_strategy=managed \ --backend=sleaf_api:8080
- Finally, you can try accessing your API using the service name!
To confirm, try this command:
and you will get the response as defined here
curl http://[SERVICE_NAME]/random
- Clone the repository to your local device
- Change BASE_URL variable in Constants class located on utils package to your API URL
- Run the application on your device