Closed chricke closed 5 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)
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!
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.
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)
We now have an official example in the tutorial :)
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?