Files
2024-08-25 22:23:26 +07:00

5.0 KiB

In [5]:
from ultralytics import YOLO

# Initialize a YOLO-World model
model = YOLO("yolov8l-world.pt")  # or choose yolov8m/l-world.pt
In [18]:
# Define custom classes
model.set_classes(["there is 3 cups in the image, detect the cup at the left most"])

# Execute prediction for specified categories on an image
results = model.predict("manycups.jpg")

# Show results
results[0].show()
image 1/1 /home/minhducnguyen/WORK/ComfyUI/custom_nodes/ComfyUI-YoloWorld-EfficientSAM/manycups.jpg: 384x640 4 there is 3 cups in the image, detect the cup at the left mosts, 43.9ms
Speed: 5.3ms preprocess, 43.9ms inference, 2.7ms postprocess per image at shape (1, 3, 384, 640)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_TIME = "vi_VN",
	LC_MONETARY = "vi_VN",
	LC_ADDRESS = "vi_VN",
	LC_TELEPHONE = "vi_VN",
	LC_NAME = "vi_VN",
	LC_MEASUREMENT = "vi_VN",
	LC_IDENTIFICATION = "vi_VN",
	LC_NUMERIC = "vi_VN",
	LC_PAPER = "vi_VN",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
In [7]:
from inference.models import YOLOWorld
YOLO_WORLD_MODEL = YOLOWorld(model_id="yolo_world/l")
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_TIME = "vi_VN",
	LC_MONETARY = "vi_VN",
	LC_ADDRESS = "vi_VN",
	LC_TELEPHONE = "vi_VN",
	LC_NAME = "vi_VN",
	LC_MEASUREMENT = "vi_VN",
	LC_IDENTIFICATION = "vi_VN",
	LC_NUMERIC = "vi_VN",
	LC_PAPER = "vi_VN",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
Creating inference sessions
UserWarning: Specified provider 'OpenVINOExecutionProvider' is not in available provider names.Available providers: 'TensorrtExecutionProvider, CUDAExecutionProvider, AzureExecutionProvider, CPUExecutionProvider'
CLIP model loaded in 2.09 seconds
2024-08-22 12:23:42.474786966 [W:onnxruntime:, transformer_memcpy.cc:74 ApplyImpl] 3 Memcpy nodes are added to the graph torch_jit for CUDAExecutionProvider. It might have negative impact on performance (including unable to run CUDA graph). Set session_options.log_severity_level=1 to see the detail logs before this message.
In [8]:
YOLO_WORLD_MODEL.set_classes('person')
results = YOLO_WORLD_MODEL.infer("holland_.jpg", confidence=0.001)
In [9]:
results
Out [9]:
ObjectDetectionInferenceResponse(visualization=None, frame_id=None, time=1.3525681463070214, image=InferenceResponseImage(width=1500, height=1000), predictions=[])
In [ ]: