|
from ultralytics import YOLO
|
|
import cv2
|
|
from load_model import load_model
|
|
|
|
def predict(model,image_path):
|
|
image = cv2.imread(image_path)
|
|
model = load_model(model)
|
|
results = model.predict(source=image,
|
|
save=True,
|
|
show=True,
|
|
conf=0.5)
|
|
|
|
for result in results:
|
|
print("检测到的对象:")
|
|
for box in result.boxes:
|
|
print(f"- 类别: {result.names[box.cls[0].item()]}, 置信度: {box.conf[0].item():.2f}")
|
|
|
|
if __name__ == '__main__':
|
|
predict(r'runs\detect\train9\weights\best.pt',r'..\yolo_hanzi_dataset\images\test\00800_243401.png')
|
|
|