first commit
This commit is contained in:
commit
a9a3f2142b
9 files changed
+37
No files matched your search
BIN
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
@@ -0,0 +1,7 @@
|
|||||||
|
it works on pictures of busses but not the hand-drawn image i made.
|
||||||
|
|
||||||
|
This program tells you whether or not the selected image is a bus.
|
||||||
|
|
||||||
|
python3 test.py
|
||||||
|
|
||||||
|
To change the file to run the operation on, change this line in the source code: results = model("bus4.jpg")
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
from ultralytics import YOLO
|
||||||
|
|
||||||
|
# Load the small pretrained YOLOv8 object-detection model.
|
||||||
|
model = YOLO("yolov8n.pt")
|
||||||
|
|
||||||
|
# Run object detection on a test image.
|
||||||
|
results = model("bus4.jpg")
|
||||||
|
|
||||||
|
has_bus = False
|
||||||
|
max_confidence = 0.0
|
||||||
|
|
||||||
|
for result in results:
|
||||||
|
class_names = result.names
|
||||||
|
detected_classes = result.boxes.cls.tolist()
|
||||||
|
confidences = result.boxes.conf.tolist()
|
||||||
|
|
||||||
|
# Check each detected object and its matching confidence score
|
||||||
|
for cls_id, conf in zip(detected_classes, confidences):
|
||||||
|
if class_names[int(cls_id)] == "bus":
|
||||||
|
has_bus = True
|
||||||
|
# Keep track of the highest confidence if there are multiple buses
|
||||||
|
if conf > max_confidence:
|
||||||
|
max_confidence = conf
|
||||||
|
|
||||||
|
# Output the Yes/No answer and the confidence percentage
|
||||||
|
if has_bus:
|
||||||
|
print("Yes")
|
||||||
|
print(f"Confidence: {max_confidence * 100:.1f}%")
|
||||||
|
else:
|
||||||
|
print("No")
|
||||||
BIN
Binary file not shown.
Reference in new issue
Block a user