Python-side, creates a ML model which identifies cannabis strains using a dataset of images scraped from the internet. The model takes as input an Image with (supposedly) a cannabis leaf and outputs its strain. Client-side (Swift), sends a request to the API made in Flask (which encorporates the ML model) with an encoded image and receives the output of the model.
- API
- iOS Client
- Model Prototype
- Crawler
- Further training of ML model with more data
- Further UI/UX imporvements for the iOS Client
The API works by running it locally in a virtualenv and allowing Flask to host the network on the network in order for the iOS Client to work.
- the Web Crawler (found in API/Crawler)
- Scrapes https://potguide.com/ for images and labels of cannabis strains and saves them in a folder with the label as name
- the Image Classifier (found in API/ImageClassifierML)
- Machine Learning Model which uses a CNN trained on the pictures gathered by the Crawler above. The input is comprised of an image (which is resized to 150 x 150 px) and the output is the strain of the cannabis depicted in the picture and the accuracy of the classification.
The Server related methodology can be found in API/Server and an example of a Python Client can be found in API/ClientExample
Data images are passed to the API by encoding them in a base64string. The result is a JSON structure which holds a dictionary of type { "Output" : ["<label>", "<accuracy>"] }
http://FLASK_HOST_ADDRESS:PORT/ (GET, checks API availability)
http://FLASK_HOST_ADDRESS:PORT/predictOnImage (POST, form-data with format : "data" : base64string, sends base64 encoded image to Server and get the output of the ML model)
The Client is built in Swift and uses an AR Session View for easy image classification at the press of a button.
- Alamofire
- SwiftyJSON
Unfortunately, as I haven't found a way yet to deploy the ML Model (due to file size reasons mainly), the model has to be trained on the machine and the webpage scraped by installing the required pip packages and then :
- Use the script found at API/Crawler/src/main.py to scrape the pictures from the website
- Move the scraped image folder into a folder named Data in API/ImageClassifierML
- Run the script at API/ImageClassifierML/classifier.py to train the model and generate the label binarizer and the Keras model file
- Training parameters can be fine-tuned in the file at step 3, and I'd be more than happy to hear about whatever improvements to the model anyone can bring