Giter Club home page Giter Club logo

Comments (5)

glenn-jocher avatar glenn-jocher commented on May 21, 2024

Hey there! 😊 It sounds like you're encountering a shape mismatch issue during concurrent image processing. This often happens when images being processed in parallel do not have consistent dimensions or when batch processing is expected to have uniform input sizes.

For sending multiple images concurrently for detection, ensure all images are preprocessed to have the same dimensions before they are fed into the model. If you're using batching, this step is crucial. Here's a quick tip on preprocessing your images to match dimensions:

import cv2

# Example resizing function
def resize_image(image_path, size=(640, 640)):
    image = cv2.imread(image_path)
    return cv2.resize(image, size)  # Resizes image to the specified size

# Preprocess your images
preprocessed_images = [resize_image(img) for img in images_to_detect]

After preprocessing, you can proceed with your concurrent detection. Remember, consistency in input dimensions is key when processing multiple images. If the issue persists, ensure that the concurrent processing logic isn't altering the input tensors in a way that would cause dimension mismatches.

Hope this helps! Let us know if you have any more questions.

from yolov5.

KnightInsight avatar KnightInsight commented on May 21, 2024

I'm not using batch processing but sending simultaneously for detection. I did resized to 640 which are rectangular images inside function. Sometimes it runs without error. Besides, I realized that when detecting concurrently, the inference will takes longer to process compared to sequential. Why?

from yolov5.

glenn-jocher avatar glenn-jocher commented on May 21, 2024

Hi again! 😊 When concurrently processing images without batching, it's crucial to maintain consistent image dimensions across all threads. Since you've resized your images to 640, ensure that aspect ratios are preserved to avoid any unexpected shape mismatches. Rectangular images may still cause issues if the model expects square input.

Regarding the longer inference times during concurrent processing: this can happen due to resource contention, where multiple threads compete for GPU/CPU resources, leading to inefficiencies. Also, depending on how you're implementing concurrency, there might be overhead from thread management that affects performance.

For a smoother experience with concurrent detections, consider:

  • Ensuring all preprocessing, including aspect ratio preservation, is consistently applied.
  • Using a fixed input size that matches the model's expectations if not already doing so.
  • Exploring Python's concurrent.futures or multiprocessing to efficiently manage threads or processes, if you're not already.

Keep in mind, hardware limitations can also play a role in how effectively you can run detections concurrently.

Hope this helps clarify things! If there's anything else, feel free to reach out.

from yolov5.

KnightInsight avatar KnightInsight commented on May 21, 2024

Hi again! Is it suitable to use thread local storage or Thread-Safe Inference to solve the unexpected shape mismatches issue?

from yolov5.

glenn-jocher avatar glenn-jocher commented on May 21, 2024

@KnightInsight hi there! 😊

Absolutely, using thread local storage (TLS) or ensuring thread-safe inference can be a practical approach to addressing shape mismatches in concurrent processing scenarios. This way, each thread can maintain its own instance of necessary data, avoiding interference between threads.

For TLS in Python, you might consider using the threading module's local storage to keep each thread's data isolated:

import threading

thread_local_data = threading.local()

def process_image(image):
    if not hasattr(thread_local_data, "model"):
        # Load the model per thread, ensuring it's isolated
        thread_local_data.model = your_model_loading_function()
    # Your image processing logic here

This ensures that each thread has its own version of the model (or any other data), reducing the risk of clashes and mismatches.

Just remember, while TLS can help with managing data per thread, it's also important to ensure that all images are correctly preprocessed and consistent before being fed into the model to avoid shape mismatches.

Hope that helps! Let us know if you need further assistance.

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.