torch/lib/libgomp-d22c30c5.so.1:无法在静态 TLS 块中分配内存

Posted

技术标签:

【中文标题】torch/lib/libgomp-d22c30c5.so.1:无法在静态 TLS 块中分配内存【英文标题】:torch/lib/libgomp-d22c30c5.so.1: cannot allocate memory in static TLS block 【发布时间】:2022-01-23 12:15:04 【问题描述】:

我在我的 jetson nano 上安装了 YoloV5。出现此错误时,我想执行我的对象检测代码:python3.8/site-packages/torch/lib/libgomp-d22c30c5.so.1: cannot allocate memory in static TLS block。

为了解决我尝试放入 bashrc 的问题:

导出 LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1

没用

你还有别的想法吗?

这是我的代码:

import cv2
import numpy as np
from elements.yolo import OBJ_DETECTION

Object_classes = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
            'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
            'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
            'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
            'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
            'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
            'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
            'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
            'hair drier', 'toothbrush' ]

Object_colors = list(np.random.rand(80,3)*255)
Object_detector = OBJ_DETECTION('weights/yolov5s.pt', Object_classes)

def gstreamer_pipeline(
    capture_width=1280,
    capture_height=720,
    display_width=1280,
    display_height=720,
    framerate=60,
    flip_method=0,
    ):
    return (
        "nvarguscamerasrc ! "
        "video/x-raw(memory:NVMM), "
        "width=(int)%d, height=(int)%d, "
        "format=(string)NV12, framerate=(fraction)%d/1 ! "
        "nvvidconv flip-method=%d ! "
        "video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
        "videoconvert ! "
        "video/x-raw, format=(string)BGR ! appsink"
        % (
        capture_width,
        capture_height,
        framerate,
        flip_method,
        display_width,
        display_height,
      )
    )



print(gstreamer_pipeline(flip_method=0))
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
if cap.isOpened():
    window_handle = cv2.namedWindow("CSI Camera", cv2.WINDOW_AUTOSIZE)

    while cv2.getWindowProperty("CSI Camera", 0) >= 0:
        ret, frame = cap.read()
        if ret:
        
            objs = Object_detector.detect(frame)

        
            for obj in objs:
           
                label = obj['label']
                score = obj['score']
                [(xmin,ymin),(xmax,ymax)] = obj['bbox']
                color = Object_colors[Object_classes.index(label)]
                frame = cv2.rectangle(frame, (xmin,ymin), (xmax,ymax), color, 2)   
                frame = cv2.putText(frame, f'label (str(score))', (xmin,ymin), cv2.FONT_HERSHEY_SIMPLEX , 0.75, color, 1, cv2.LINE_AA)

                cv2.imshow("CSI Camera", frame)
           keyCode = cv2.waitKey(30)
           if keyCode == ord('q'):
                break
cap.release()
cv2.destroyAllWindows()

其他: print("无法打开相机")

【问题讨论】:

【参考方案1】:

export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1 不太可能解决您的问题。 因为您的问题发生在python3.8/site-packages/torch/lib/libgomp-d22c30c5.so.1。 所以需要的环境变量设置如下。

export LD_PRELOAD=<parent path to python3.8>/python3.8/site-packages/torch/lib/libgomp-d22c30c5.so.1

我确定python3.8 目录有父路径。您应该找到它并将其插入到上面的命令中。 如何找到它: How do I find the location of my Python site-packages directory?

默认为/usr/lib。在这种情况下,所需的命令是

export LD_PRELOAD=/usr/lib/python3.8/site-packages/torch/lib/libgomp-d22c30c5.so.1

【讨论】:

以上是关于torch/lib/libgomp-d22c30c5.so.1:无法在静态 TLS 块中分配内存的主要内容,如果未能解决你的问题,请参考以下文章

libgomp-d22c30c5.so.1.0.0:cannot allocate memory in static TLS block

第30题2019年OCP-12C-062最新考试原题-30

C语言 百炼成钢22

使用C语言在多个CSV文件之间读取翻译和写入数据。

ZZNUOJ_用C语言编写程序实现1211:日期排序(附完整源码)

第九周PSP