Giter VIP home page Giter VIP logo

Comments (4)

github-actions avatar github-actions commented on July 22, 2024

πŸ‘‹ Hello @dhouib-akram, thank you for your interest in Ultralytics YOLOv8 πŸš€! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a πŸ› Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

from ultralytics.

glenn-jocher avatar glenn-jocher commented on July 22, 2024

Hi @dhouib-akram,

Thank you for reaching out and providing a detailed description of your issue along with the code snippets. It's great to see your effort in hosting the YOLOv8-segmentation model on a Triton server and working through the post-processing steps.

To address your concern about the low-resolution masks, there are a few key points and suggestions to consider:

  1. Ensure Latest Versions: First, please make sure you are using the latest versions of torch and ultralytics. You can update them using:

    pip install --upgrade torch ultralytics
  2. Model Export and NMS: When exporting the model to ONNX and subsequently to TensorRT, ensure that the Non-Maximum Suppression (NMS) layer is correctly integrated. If the NMS is not properly handled, it might affect the quality of the masks.

  3. Resolution Handling: The low-resolution issue might be due to the resizing and reshaping operations. Ensure that the mask resolution is consistent throughout the process. Here’s a refined approach to handle the mask resolution:

    def get_mask(row, box, img_w, img_h):
        mask = row.reshape(160, 160)
        mask = sigmoid(mask)
        mask = (mask > 0.5).astype('uint8') * 255
    
        # Calculate the bounding box coordinates in the mask's scale
        mask_x1 = round(box.x1 / img_w * 160)
        mask_y1 = round(box.y1 / img_h * 160)
        mask_x2 = round(box.x2 / img_w * 160)
        mask_y2 = round(box.y2 / img_h * 160)
    
        # Crop the mask to the bounding box
        mask = mask[mask_y1:mask_y2, mask_x1:mask_x2]
    
        # Resize mask directly to the bounding box size
        desired_width = round(box.x2 - box.x1)
        desired_height = round(box.y2 - box.y1)
        mask_resized = cv2.resize(mask, (desired_width, desired_height), interpolation=cv2.INTER_LINEAR)
    
        return mask_resized
  4. Post-Processing Pipeline: Ensure that the post-processing pipeline maintains the resolution integrity. Here’s a refined version of your postprocess function:

    def postprocess(det_boxes, det_scores, det_classes, img_w, img_h, input_shape, masks):
        detected_objects = []
        polygons = []
    
        # Extracting box coordinates and converting to (x1, y1, x2, y2) format
        x, y, w, h = det_boxes[:, 0], det_boxes[:, 1], det_boxes[:, 2], det_boxes[:, 3]
        x1, y1, x2, y2 = (x - 0.5 * w), (y - 0.5 * h), (x + 0.5 * w), (y + 0.5 * h)
        boxes = np.stack([x1, y1, x2, y2], axis=-1)
    
        # Calculate the scale factors for width and height
        width_scale = img_w / input_shape[0]
        height_scale = img_h / input_shape[1]
    
        # Apply scale factors to adjust the bounding box coordinates
        boxes = boxes * np.array([width_scale, height_scale, width_scale, height_scale], dtype=np.float32)
    
        # Extract scores and classes
        scores = det_scores
        classes = det_classes
    
        for box, score, label, mask in zip(boxes, scores, classes, masks):
            # Ensure that box coordinates are within the image boundaries
            box = np.clip(box, 0, [img_w, img_h, img_w, img_h])
            box = BoundingBox(label, score, box[0], box[2], box[1], box[3], img_w, img_h)
            detected_objects.append(box)
    
            mask = get_mask(mask, box, img_w, img_h)
            polygons.append(get_polygon(mask))
    
        return detected_objects, polygons
  5. Comparison with Ultralytics Predict: If the predefined predict function from Ultralytics provides high-resolution masks, it might be beneficial to compare the internal steps of the predict function with your custom implementation. Ensure that the preprocessing and postprocessing steps align closely.

For further details on the AutoBackend class and dynamic backend selection, you can refer to the Ultralytics documentation.

If the issue persists, please provide a minimum reproducible example so we can investigate further. You can follow the guidelines here: Minimum Reproducible Example.

Feel free to reach out if you have any more questions or need further assistance! 😊

from ultralytics.

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.