ultralytics / yolov3

YOLOv3 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
10.18k stars 3.44k forks source link

RuntimeErro r: Output 0 of SelectBackward is a view and is being modified inplace. #1805

Closed yuanqiyin closed 3 years ago

yuanqiyin commented 3 years ago

🐛 Bug

RuntimeError: Output 0 of SelectBackward is a view and is being modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one.

To Reproduce (REQUIRED)

Input:

def non_max_suppression(prediction, conf_thres=0.5, nms_thres=0.5):

    min_wh, max_wh = 2, 10000

    output = [None] * len(prediction)

    for image_i, pred in enumerate(prediction):    # image index , image inference

        class_conf, class_pred = pred[:, 5:].max(1)
        pred[:, 4] *= class_conf

        i = (pred[:, 4] > conf_thres) & (pred[:, 2:4] > min_wh).all(1) & (pred[:, 2:4] < max_wh).all(1) & \
            torch.isfinite(pred).all(1)
        pred = pred[i]

        # If none are remaining => process next image
        if len(pred) == 0:
            continue

        # Select predicted classes
        class_conf = class_conf[i]
        class_pred = class_pred[i].unsqueeze(1).float()

        # Box (center x, center y, width, height) to (x1, y1, x2, y2)
        pred[:, :4] = xywh2xyxy(pred[:, :4])

        # Detections ordered as (x1y1x2y2, obj_conf, class_conf, class_pred)
        pred = torch.cat((pred[:, :5], class_conf.unsqueeze(1), class_pred), 1)

        # Get detections sorted by decreasing confidence scores
        pred = pred[(-pred[:, 4]).argsort()]

Output:

Traceback (most recent call last):
  File "E:/PersonalFile/Code/deep_sort_yolov3_pytorch-master/deep_sort.py", line 186, in <module>
    det.detect(output_file)
  File "E:/PersonalFile/Code/deep_sort_yolov3_pytorch-master/deep_sort.py", line 98, in detect
    bbox_xxyy, cls_conf, cls_ids = self.yolo3.predict(im)
  File "E:\PersonalFile\Code\deep_sort_yolov3_pytorch-master\predict.py", line 54, in predict
    det = non_max_suppression(pred, self.conf_thres, self.nms_thres)[0]
  File "E:\PersonalFile\Code\deep_sort_yolov3_pytorch-master\utils\util.py", line 615, in non_max_suppression
    pred[:, 4] *= class_conf
RuntimeError: Output 0 of SelectBackward is a view and is being modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one.

Expected behavior

Used it to detect and Bug happened. Please help me~

Environment

github-actions[bot] commented 3 years ago

👋 Hello @yuanqiyin, thank you for your interest in YOLOv3 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

Environments

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

Status

CI CPU testing

If this badge is green, all YOLOv3 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv3 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 3 years ago

@yuanqiyin

Branch Notice

The ultralytics/yolov3 repository is now divided into two branches:

github-actions[bot] commented 3 years ago

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv3 🚀 resources:

Access additional Ultralytics ⚡ resources:

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 YOLOv3 🚀 and Vision AI ⭐!