Compare commits

..
7 Commits
Author SHA1 Message Date
scott 01ee36174b Merge pull request 'polish' (#1) from jazz/YOLOv8_test_example:fork into main
Reviewed-on: scott/YOLOv8_test_example#1
2026-09-17 11:26:35 -05:00
jazz f2cc5c141e update readme 2026-09-17 10:56:53 -05:00
jazz c590b6bb4b move all pictures to img/ 2026-09-17 10:47:14 -05:00
jazz 8a3dc4b067 filename capitalization 2026-09-17 10:46:36 -05:00
jazz caeab24e57 fix readme permission 2026-09-17 10:46:24 -05:00
jazz 67277c2862 more pictures 2026-09-17 10:45:15 -05:00
jazz 7df0ad92ae parse image path from argument 2026-09-17 10:44:51 -05:00
11 changed files with 73 additions and 9 deletions

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
# test
outputs `Yes` if the supplied image contains a bus and `No` if it does not
## usage
syntax: `./test.py [IMAGE]`
### example 1
testing with the following image:
![](img/bus.jpg)
```bash
./test.py img/bus.jpg
```
output:
```
image 1/1 /home/ja/git/YOLOv8_test_example/img/bus.jpg: 640x480 4 persons, 1 bus, 1 stop sign, 20.1ms
Speed: 1.0ms preprocess, 20.1ms inference, 0.7ms postprocess per image at shape (1, 3, 640, 480)
Yes
Confidence: 87.3%
```
### example 2
testing with the following image:
![](img/notabus.png)
```bash
./test.py img/notabus.png
```
output:
```
image 1/1 /home/ja/git/YOLOv8_test_example/img/notabus.png: 384x640 (no detections), 17.4ms
Speed: 0.9ms preprocess, 17.4ms inference, 0.4ms postprocess per image at shape (1, 3, 384, 640)
No
```
### example 3
testing with the following image:
![](img/bus2.png)
```bash
./test.py img/bus2.png
```
output:
```
image 1/1 /home/ja/git/YOLOv8_test_example/img/bus2.png: 384x640 (no detections), 16.4ms
Speed: 1.1ms preprocess, 16.4ms inference, 0.3ms postprocess per image at shape (1, 3, 384, 640)
No
```
Note that another cartoon image of a bus did register as a bus.
View File
File renamed without changes.
View File
File renamed without changes.
View File
File renamed without changes.
View File
File renamed without changes.
View File
File renamed without changes.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 414 KiB

View File
File renamed without changes.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1001 KiB

-7
View File
@@ -1,7 +0,0 @@
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")
Regular → Executable
+8 -2
View File
@@ -1,10 +1,16 @@
#!/usr/bin/env python3
import sys
from ultralytics import YOLO from ultralytics import YOLO
image_path = sys.argv[1]
# Load the small pretrained YOLOv8 object-detection model. # Load the small pretrained YOLOv8 object-detection model.
model = YOLO("yolov8n.pt") model = YOLO("yolov8n.pt")
# Run object detection on a test image. # Run object detection on a test image.
results = model("bus4.jpg") results = model(image_path)
has_bus = False has_bus = False
max_confidence = 0.0 max_confidence = 0.0
@@ -13,7 +19,7 @@ for result in results:
class_names = result.names class_names = result.names
detected_classes = result.boxes.cls.tolist() detected_classes = result.boxes.cls.tolist()
confidences = result.boxes.conf.tolist() confidences = result.boxes.conf.tolist()
# Check each detected object and its matching confidence score # Check each detected object and its matching confidence score
for cls_id, conf in zip(detected_classes, confidences): for cls_id, conf in zip(detected_classes, confidences):
if class_names[int(cls_id)] == "bus": if class_names[int(cls_id)] == "bus":