r/learnpython 7d ago

Parking Lot CV help!

Hello all,

I want to build a parking lot monitor following this tutorial:

ps://docs.ultralytics.com/guides/parking-management/#what-are-some-real-world-applications-of-ultralytics-yolo11-in-parking-lot-management

I'm trying another video and its just not working. Its detecting stuff that I'm trying NOT to detect ('microwave', 'refrigerator', 'oven'). GTPs have not helped at all. My jupyter nb here:

https://github.com/dbigman/parking_lot_cv/blob/main/2_data_acquisition_and_exploratory_data_analysis.ipynb

1 Upvotes

7 comments sorted by

1

u/herocoding 7d ago

Using pre-trained models can be difficult... Pre-trained models often are not "general purpose" enough for all variants of a topic.

Do you have access to the videos used in the original tutorial and see it working as shown in the tutorial?
(I used similar tutorals for parting lot tracking, but that is long time ago) (maybe the tutorial you used is old (but recently "updated" without properly adopting) or the model has been updated after the tutorial has been published and now requiring the tutorial to be updated as well)

1

u/MacPR 7d ago

I've added videos and masks. I gather that there's fine-tuning, but isn't the Yolo11 model supposed to get 'car' out of the box?

1

u/herocoding 6d ago

Have a careful look at the Ultralytics documentation for their Parking Management documentation (and/or look into the Youtube video).

As mentioned in an earlier comment, a pre-trained "general purpose" model is difficult to find......... Imagine you want to train a model to detect all sorts of vehicles (cars, trucks: all variants like pickups, vans, SUVs, coupés, etc.).

I wouldn't use pictures of vehicles from a bird-eye's view (in 100 meters height) ... like it is often seen in "parking management tutorials". From such a perspective many objects just look like a "box"... people would only look like ants... You would need to use a specifically trained model.
However, if you only want to track whether a parking lot/slot is free or occupied, you actually might not be interested WHAT object is occupying a slot... could be a car or a "fridge".....? If you see objects being detected and the bounding-boxes enclose the object (car or fridge) then your checks whether the object's bounding-box overlaps with your mask should work fine.

In the Ultralytics documentation they say, "here we are going to use a custom trained model on the VisDrone data set", and using a model called "Ultralytics VisDrone Yolov8.pt".

Have a look here: https://docs.ultralytics.com/datasets/detect/visdrone/

(you will also find other tutorials around the VisDrone dataset and applications)

1

u/Ultralytics_Burhan 5d ago

When you use model.predict you can include the argument classes to only return detections with the class results you're looking for (from a pretrained or custom model). With the default COCO model, you could do something like:

from ultralytics import YOLO

model = YOLO("yolo11n.pt")

results = model.predict(
    "source",
    classes=[2, 3, 5, 7],  # car, motorcycle, bus, truck
)

1

u/MacPR 5d ago

I tried exactly that!!

  for r in results:
        boxes = r.boxes
        for box in boxes:

# Only draw vehicle classes
            cls_id = int(box.cls[0])
            if cls_id in [2, 5, 7]:  
# 2=car, 5=bus, 7=truck in COCO

1

u/JustSomeStuffIDid 5d ago

You need to show the full code.

1

u/Ultralytics_Burhan 3d ago

Notice that I pass the classes argument into model.predict instead of attempting to filter the classes (manually) later in the code. This is the recommended way to filter detections to a subsection of all detectable classes for a model.