tryolabs / luminoth

Deep Learning toolkit for Computer Vision.
https://tryolabs.com
BSD 3-Clause "New" or "Revised" License
2.4k stars 399 forks source link

Adding examples for using Python API #175

Closed chricke closed 5 years ago

chricke commented 6 years ago

There is a hint "Use the Python API to call Luminoth models within Python." in the docs but i did not found any example how to use a self trained model / checkpoint in my python code.

Could you please add this?

joaqo commented 6 years ago

Hello @chricke, currently we don't have any examples on how to use the python api in our documentation as we are actively working on improving the api. We plan to add them asap though, and I'll make sure to ping you when they are done.

On the meantime you can check https://github.com/tryolabs/luminoth/blob/master/luminoth/predict.py for an example on how to use the PredictorNetwork class that we use to get predictions from a network, though it basically sums up to:

from luminoth.utils.predicting import PredictorNetwork
from PIL import Image

network = PredictorNetwork(config)
image = Image.open(f).convert('RGB')
objects = network.predict_image(image)
chricke commented 6 years ago

ok, so if i understand the code correctly i can give the checkpoint for my self trained network as parameter to the the predict function, right?

I will give it a try, thanks!

joaqo commented 6 years ago

Yeah, when you create your network object you pass a config file to the PredictorNetwork class, which then loads the checkpoint defined in that config. Then its just a matter of calling network.predict_image(image).

We have some helper methods for helping with loading the config file, which you can look at in the predict.py file I linked to earlier.

chricke commented 6 years ago

Just as a hint for others: you also have to use get_checkpoint_config to get the config of your checkpoint, so the whole example would look like this:

from PIL import Image

from luminoth.tools.checkpoint import get_checkpoint_config
from luminoth.utils.predicting import PredictorNetwork

config = get_checkpoint_config(checkpoint)
network = PredictorNetwork(config)
image = Image.open(f).convert('RGB')
objects = network.predict_image(image)
dekked commented 5 years ago

We now have an official example in the tutorial :)