DEV Community

Cover image for Deep Learning, Object detection with Python
petercour
petercour

Posted on

Deep Learning, Object detection with Python

Luminoth is a Deep Learning toolkit for Computer Vision. It uses tensorflow underneath, so install tensorflow or tensorflow-gpu (if you have a gpu).

pip install luminoth
Enter fullscreen mode Exit fullscreen mode

One of these then

pip install tensorflow
pip install tensorflow-gpu
Enter fullscreen mode Exit fullscreen mode

One of the things you'll need is a faster computer (and probably a GPU). In my case, running scripts like this sometimes freezes my computer.

Download an image, like this one

Then run the command

lumi predict bicycling-1160860_960_720.jpg
Enter fullscreen mode Exit fullscreen mode

Then confirm you want to download

Checkpoint not found. Check remote repository? [y/N]: y
Retrieving remote index... done.
2 new remote checkpoints added.
Checkpoint not present locally. Want to download it? [y/N]: y
Downloading checkpoint...  [####################################]  100%
Importing checkpoint... done.
Checkpoint imported successfully.
Enter fullscreen mode Exit fullscreen mode

Results in this json output:

{"objects": [{"prob": 0.9997, "bbox": [294.0, 231.0, 468.0, 536.0], "label": "person"}, {"prob": 0.9971, "bbox": [494.0, 289.0, 578.0, 439.0], "label": "person"}, {"prob": 0.997, "bbox": [727.0, 303.0, 800.0, 465.0], "label": "person"}, {"prob": 0.9965, "bbox": [555.0, 315.0, 652.0, 560.0], "label": "person"}, {"prob": 0.9934, "bbox": [569.0, 425.0, 636.0, 600.0], "label": "bicycle"}, {"prob": 0.9932, "bbox": [326.0, 410.0, 426.0, 582.0], "label": "bicycle"}, {"prob": 0.9334, "bbox": [744.0, 380.0, 784.0, 482.0], "label": "bicycle"}, {"prob": 0.8723, "bbox": [506.0, 360.0, 565.0, 480.0], "label": "bicycle"}, {"prob": 0.8142, "bbox": [848.0, 319.0, 858.0, 342.0], "label": "person"}], "file": "bicycling-1160860_960_720.jpg"}
Enter fullscreen mode Exit fullscreen mode

You can get the list of checkpoints

lumi checkpoint list
Enter fullscreen mode Exit fullscreen mode

you can run the progrma

#!/usr/bin/python
from luminoth import Detector, read_image, vis_objects

image = read_image('traffic-image.png')
detector = Detector(checkpoint='traffic')
objects = detector.predict(image)

print(objects)

vis_objects(image, objects).save('traffic-out.png')
Enter fullscreen mode Exit fullscreen mode

then outputs the objects like above.

Related links:

Top comments (0)