pjreddie / darknet

Convolutional Neural Networks
http://pjreddie.com/darknet/
Other
25.78k stars 21.33k forks source link

Load YOLO on local memory #762

Open Flock1 opened 6 years ago

Flock1 commented 6 years ago

Hi,

I want to use YOLO to get bounding box and use that information for further application. My main problem is, I'm not able to install YOLO on RAM and since I'm running YOLO on video, so for every frame it installs YOLO and then finds the bounding box. I want to install YOLO just once and then pass every frame through it to save time. Can someone suggest what should I do?

AmmarkoV commented 6 years ago

You want a wrapper for yolo basically I have a wrapper here , if you look at DarknetProcessor.c

You basically need to do a initArgs_DarknetProcessor(int argc, char argv[]) call only once to load the weights etc by giving the argc/argv values of your main(int argc, char argv[])

these for example could be ./yourExecutable path/yolo.weights path/yolo.cfg path/coco.data

and then there is a call addDataInput_DarknetProcessor where you can provide image arrays that will get processed as many times as you want without having to reload the yolo network every time..!

I hope this helps :)

Flock1 commented 6 years ago

@AmmarkoV, thanks for the reply. I am not very good with C/C++ builds. Will it be possible for you to give me some steps about how I should link it with YOLO?

Flock1 commented 6 years ago

@AmmarkoV, I also want to know how to work with this and Python? After running YOLO, I do some more processing and I need to do it now with a webcam in real time. So what do you suggest I should do?

TheMikeyR commented 6 years ago

@Flock1 python way https://github.com/pjreddie/darknet/issues/289#issuecomment-342448358

and for yolov3 https://github.com/pjreddie/darknet/issues/739#issuecomment-388628792

Flock1 commented 6 years ago

@TheMikeyR, thanks for the post. I have a question. I want to run YOLO, get the bounding box at the center and then pass that frame with the bounding box in the center into a CNN model. The final output needs to be displayed. So how do I tweak your code for that? This is the code that runs YOLO and get the center BB(I know that since I run the code to load the model on every frame, that's why it loads for every frame):

def run_yolo(file_path,column_name, output_file, data_file, output_img):
    put_header(column_name, output_file)
    images = basename(file_path)
    img = cv2.imread(file_path)
    os.chdir('/home/sarvagya/Desktop/RBC/darknet')
    comm = ['./darknet detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights', file_path]
    os.system(' '.join(comm))
    content = read_file(data_file)
    coords = []
    new_coords = []
    # new_img = np.copy(img)
    for i in range(0,len(content)):
        coords.append(content[i].split(","))
    print("THE COORDS ARE: ")
    print(coords)
    for i in range(len(coords)):
        for j in range(len(coords[i])):
            coords[i][j] = int(coords[i][j])
    half_way = img.shape[1]//2
    if(len(coords)==0):
        top_left = (0,0)
        bottom_right = (0,0)
        new_coords = (0,0,0,0)
    for i in range(len(coords)):
        for i in range(len(coords)):
            if(coords[i][0] < half_way and  half_way < coords[i][1]):
                top_left = (coords[i][0],coords[i][2])
                bottom_right = (coords[i][1],coords[i][3])
                new_coords = (coords[i][0],coords[i][1],coords[i][2],coords[i][3])
                cv2.rectangle(img,top_left,bottom_right,(0,255,0),3)
                # print("NEw coords (half-way): ")
                # print(new_coords)
                break
            else:
                new_coords = (0,0,0,0)
    write_to_csv(output_file, new_coords, images)

And then, I send that frame to get passed through a model and get an output. So what do you suggest I should do?

TheMikeyR commented 6 years ago

@Flock1 the code snippet here https://github.com/pjreddie/darknet/issues/289#issuecomment-369844329 is how I have done it with a webcam, but the way doesn't work with yolov3, the other link I sent in previous coordinate show it with python, it should be easy to adapt it to your code, just look at the main function

Flock1 commented 6 years ago

@TheMikeyR, I will try that. WIll let you know with an update soon.

Flock1 commented 6 years ago

@TheMikeyR, I found a keras implementation of darknet and wanted to know if you can help me with that.

TheMikeyR commented 6 years ago

I've never worked with keras framework, try to make an issue in the "keras implementation of darknet" repository.

mandywoo commented 3 years ago

@AmmarkoV How would these be called? And is there any way to preload different .weights, .cfg, and .data files and then selectively choose which one to use when inputting an image?