Coder Social home page Coder Social logo

load images in batch size about yolov5 HOT 6 CLOSED

KnightInsight avatar KnightInsight commented on September 9, 2024
load images in batch size

from yolov5.

Comments (6)

glenn-jocher avatar glenn-jocher commented on September 9, 2024

@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! 🚀

from yolov5.

KnightInsight avatar KnightInsight commented on September 9, 2024

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

from yolov5.

glenn-jocher avatar glenn-jocher commented on September 9, 2024

@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! 🚀

from yolov5.

KnightInsight avatar KnightInsight commented on September 9, 2024

Hi, how about if I torch.hub.load() stream images. Every time I might load 4 to 8 images and detect concurrently, is it possible to do it? How can I load streaming image instead of image from folder(eg. batch=4 images)?
images = ['path/to/image1.jpg', 'path/to/image2.jpg']

from yolov5.

glenn-jocher avatar glenn-jocher commented on September 9, 2024

@KnightInsight hello! 😊

Absolutely, you can process a stream of images in batches with YOLOv5 using torch.hub.load. If your images are not directly from a folder but are streaming (say, from a camera or online source), you'll first need to fetch these images and convert them into a format that the model accepts (like PIL images or tensors).

Here's a basic approach for handling streams:

  1. Fetch your streaming images and store them temporarily in a list.
  2. Convert the list of images to a compatible format (PIL or tensors).
  3. Pass the batch to the model for detection.

Example for PIL Images:

from PIL import Image
import torch

# Assume 'fetch_stream_images()' is your custom function to fetch images from your stream
stream_images = fetch_stream_images(batch_size=4)  # Fetch 4 images
images = [Image.open(img) for img in stream_images]  # Convert to PIL Images

model = torch.hub.load('ultralytics/yolov5', 'yolov5s')  # Load the model
results = model(images)  # Process the batch of images

Ensure you adjust fetch_stream_images() to your specific method of fetching streaming images. This approach allows you to process 4 to 8 images concurrently as they arrive from your stream.

Happy streaming detection! 🚀

from yolov5.

github-actions avatar github-actions commented on September 9, 2024

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

from yolov5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.