Skip to content

pgari/lobe-python

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lobe Python API

Code to run exported Lobe models in Python using the TensorFlow, TensorFlow Lite, or ONNX options.

Install

Linux

# Install Python3
sudo apt update
sudo apt install -y python3-dev python3-pip

# Install Pillow dependencies
sudo apt update
sudo apt install -y \
    libatlas-base-dev \
    libopenjp2-7 \
    libtiff5 \
    libjpeg62-dev

# Install lobe-python
pip3 install setuptools git
pip3 install git+https://github.com/lobe/lobe-python

Note for Raspbian OS (Raspberry Pi): Please install libjpeg62-turbo instead of libjpeg62-dev

Mac/Windows

Use a virtual environment with Python 3.7

python3 -m venv .venv

# Mac:
source .venv/bin/activate

# Windows:
.venv\Scripts\activate

Install the library

# make sure pip is up to date
python -m pip install --upgrade pip
# install
pip install git+https://github.com/lobe/lobe-python

Usage

from lobe import ImageModel

model = ImageModel.load('path/to/exported/model')

# OPTION 1: Predict from an image file
result = model.predict_from_file('path/to/file.jpg')

# OPTION 2: Predict from an image url
result = model.predict_from_url('http://url/to/file.jpg')

# OPTION 3: Predict from Pillow image
from PIL import Image
img = Image.open('path/to/file.jpg')
result = model.predict(img)

# Print top prediction
print(result.prediction)

# Print all classes
for label, confidence in result.labels:
    print(f"{label}: {confidence*100}%")

Note: model predict functions should be thread-safe. If you find bugs please file an issue.

Resources

See the Raspberry Pi Trash Classifier example, and its Adafruit Tutorial.

About

Python toolset for working with Lobe models

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Python 100.0%