ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite

Home Page:https://docs.ultralytics.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

load images in batch size

KnightInsight opened this issue Β· comments

Search before asking

Question

Hi, I would like to ask when using torch.hub.load to load a model, is there a method to process images in batches, accommodating scenarios where 3 or 5 images arrive simultaneously, allowing parallel execution instead of queuing?

Additional

No response

@KnightInsight hello! 😊

Great question! When using torch.hub.load to load a YOLOv5 model, you can indeed process images in batches. After loading the model, you can simply pass a list of image paths or a batch of images (as a tensor) to the model's .predict() method. This allows for parallel processing of the images, leveraging the batch processing capabilities of PyTorch and the underlying hardware acceleration (like GPUs) for efficiency.

Here's a quick example for clarity:

model = torch.hub.load('ultralytics/yolov5', 'yolov5s')  # Load the model
images = ['path/to/image1.jpg', 'path/to/image2.jpg']  # List of image paths
results = model(images)  # Process images in batch

Or, if you have images as tensors:

# Assuming 'imgs' is a batch of images as a tensor
results = model(imgs)

This approach should help you process multiple images simultaneously without queuing them. For more detailed information and examples, please refer to our documentation at https://docs.ultralytics.com/yolov5/.

Happy coding! πŸš€

Hi, may I know can yolov8 still able to use torch.hub.load? For example, 1 image request incoming then detect.

@KnightInsight hello 😊!

Yes, you can use torch.hub.load with YOLOv8 to load the model and perform detection on incoming images. Here's a quick example:

model = torch.hub.load('ultralytics/yolov8', 'yolov8s', pretrained=True) # Load YOLOv8 model
results = model('path/to/your/image.jpg')  # Perform detection on an image
results.show()  # Display the results

This will load the YOLOv8 model and allow you to detect objects in a single image. For detailed documentation, please check our official docs. Happy coding! πŸš€