pythonoutputstdoutyoloyolov8

Hide Ultralytics' Yolov8 model.predict() output from terminal


I have this output that was generated by model.predict()

0: 480x640 1 Hole, 234.1ms
Speed: 3.0ms preprocess, 234.1ms inference, 4.0ms postprocess per image at shape (1, 3, 640, 640)

0: 480x640 1 Hole, 193.6ms
Speed: 3.0ms preprocess, 193.6ms inference, 3.5ms postprocess per image at shape (1, 3, 640, 640)

...

How do I hide the output from the terminal?

I can't find out the information in this official link: https://docs.ultralytics.com/modes/predict/#arguments


Solution

  • The Ultralytics docs are sadly not up to date, as of today. The right way of doing this is:

    from ultralytics import YOLO
    
    model = YOLO('yolov8m-seg.pt')
    results = model.predict(source='0', verbose=False)
    for result in results:
        masks = result.masks.masks
        print(masks.shape)
    

    Notice the verbose=False argument. This won't print the default output

    ...
    0: 480x640 1 Hole, 193.6ms
    Speed: 3.0ms preprocess, 193.6ms inference, 3.5ms postprocess per image at shape (1, 3, 640, 640)
    ...
    

    In this case only:

    ...
    torch.Size([4, 480, 640])
    ...