cv::Exception at memory location due to net.forward()

Hello, I’m using OpenCV 4.9 and I’ve been getting a Exception at memory location error whenever I use the net.forward() method. I’ve built OpenCV with CUDA support if that matters. Here is the code:

#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <opencv2/imgproc.hpp>
#include "opencv2/dnn/all_layers.hpp"
#include "opencv2/dnn.hpp"
#include <Windows.h>

#include <iostream>
#include <fstream>
using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    string model_path = "C:/Users/behas/Downloads/darknet-master/darknet-master/cfg/yolov4-tiny-custom_best2.weights";
    string cfg_path = "C:/Users/behas/Downloads/darknet-master/darknet-master/cfg/yolov4-tiny-custom.cfg";
    vector<string> class_names;
    ifstream ifs(string("names.txt").c_str());
    string line;
    Mat image = imread("C:/Users/behas/PycharmProjects/bott/BrawlStarsBot/positive/test1.jpg");
    while (getline(ifs, line)) {

        cout << line << endl;
        class_names.push_back(line);

    } 


    cv::dnn::Net net = cv::dnn::readNetFromDarknet(cfg_path, model_path);
    net.setPreferableBackend(dnn::DNN_BACKEND_CUDA);
    net.setPreferableTarget(dnn::DNN_TARGET_CUDA);
   
    
    net.setInput(image);
    Mat out = net.forward();
    cv::imshow("test", out);
    waitKey(0);

As soon as it reaches the “Mat out = net.forward();” line I get the error. I’m new to OpenCV so pointing me in the right direction would be a great help :pray:
Thanks in advance

unfortunately, those lines are entirely broken,
neither input nor output are images, but 4d tensors

please look up, how to parse YOLO results, then try again

Your big meta problem is that you code does not check at all whether the function calls succeed, what they return and are your data and variables ok…