torch/lib/libgomp-d22c30c5.so.1: cannot allocate memory in static TLS block
Asked Answered
J

1

5

I installed YoloV5 on my jetson nano. I wanted to execute my object detection code when this error appeared: python3.8/site-packages/torch/lib/libgomp-d22c30c5.so.1: cannot allocate memory in static TLS block.

To fix the problem I tried to put in the bashrc:

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

It didn't work

Do you have another idea?

Here is my code:

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()

else: print("Unable to open camera")

Jell answered 22/12, 2021 at 8:35 Comment(0)
T
9

export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1 is not likely to fix your problem.
Because your problem occurred at python3.8/site-packages/torch/lib/libgomp-d22c30c5.so.1.
So required env variable setting is below.

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

I'm sure there's parent path to python3.8 directory. You should find it and insert it into command above.
how to find it : How do I find the location of my Python site-packages directory?

By default, it will be /usr/lib. In this case, required command is

export LD_PRELOAD=/usr/lib/python3.8/site-packages/torch/lib/libgomp-d22c30c5.so.1
Twoup answered 25/12, 2021 at 3:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.