Skip to main content

Lobe Python SDK

Project description

Lobe Python API

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

Works with Python 3.6, 3.7, 3.8, and 3.9 untested for other versions.

Install

Backend options with pip

You can install each of the backends on an individual basis, or all together through pip like so:

# For all of the supported backends (TensorFlow, TensorFlow Lite, ONNX)
pip install lobe[all]

# For TensorFlow only
pip install lobe[tf]

# For TensorFlow Lite only -- this requires two steps for the runtime and for lobe (note for Raspberry Pi see our setup script in scripts/lobe-rpi-install.sh)
pip install --index-url https://google-coral.github.io/py-repo/ tflite_runtime 
pip install lobe

# For ONNX only
pip install lobe[onnx]

Installing lobe-python without any options (pip install lobe) will only install the base requirements, no backends will be installed. If you try to load a model with a backend that hasn't been installed, an error message will show you the instructions to install the correct backend.

Linux

Before running these commands, make sure that you have git installed.

# 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
# Swap out the 'all' option here for your desired backend from 'backend options with pip' above.
pip3 install lobe[all]

For Raspberry Pi OS (Raspian) run:

cd ~
wget https://raw.githubusercontent.com/lobe/lobe-python/master/scripts/lobe-rpi-install.sh
chmod 755 lobe-rpi-install.sh
sudo ./lobe-rpi-install.sh

Mac/Windows

We recommend using a virtual environment:

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
# Swap out the 'all' option here for your desired backend from 'backend options with pip' above.
pip install lobe[all]

Usage

from lobe import ImageModel

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

# 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}%")

# Visualize the heatmap of the prediction on the image 
# this shows where the model was looking to make its prediction.
heatmap = model.visualize(img)
heatmap.show()

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lobe-0.6.1.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

lobe-0.6.1-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file lobe-0.6.1.tar.gz.

File metadata

  • Download URL: lobe-0.6.1.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for lobe-0.6.1.tar.gz
Algorithm Hash digest
SHA256 d8deb04f3345dcb16d8a8663d82cd6ea7792e329047d2323a7cfae40a8df3e18
MD5 d2eb1858aa7b9246a23cd5c92d5eb622
BLAKE2b-256 58dd65d3fd73b422f54202926db9ff22aca97abfd3940ce3b2efd97c9e43c7c9

See more details on using hashes here.

File details

Details for the file lobe-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: lobe-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for lobe-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fbab43f5379ef634f05e228840ee8351715a491a2c70ffd07c5abe6c97ae3336
MD5 ea56b20912fe4e73c877aa815097f776
BLAKE2b-256 b9a83c05fe6bef29e0bc28d146b18a5650420efa97c451ede78988366c3aa85c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page