Code Monkey home page Code Monkey logo

Comments (17)

Cartucho avatar Cartucho commented on May 13, 2024 4

Done! Have a look here.

Basically, all you have to do is add the result.txt to the folder extra/ and run the command python convert_pred_yolo.py

from map.

vadimen avatar vadimen commented on May 13, 2024 4

here is a simple code, works for yolov3 of v4 or any other, adjust the paths, time or even the command for yourself

import os
import subprocess
import time

image_paths_file = '/home/darknet/vadim_configs/test.txt'
path_to_save_images = '/home/darknet/results/'

im_paths = open(image_paths_file, "r").readlines()

obj_dat = "/home/darknet/vadim_configs/obj.data"
yolo_cnf = "/home/darknet/vadim_configs/yolov4-custom.cfg"
yolo_wghts = "/home/darknet/backup/yolov4-custom_best.weights"

for im in im_paths:
    cmd = "./darknet detector test {} {} {} -dont_show \"{}\"".format(obj_dat, yolo_cnf, yolo_wghts, im)

    # The os.setsid() is passed in the argument preexec_fn so
    # it's run after the fork() and before  exec() to run the shell.

    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, preexec_fn=os.setsid)

    # it must be adjuste to your inference speed
    # on my rtx2080 takes 6 seconds max
    time.sleep(6)
    # Send the signal to all the process groups
    #os.killpg(os.getpgid(p.pid), signal.SIGTERM)

    image_name = (im.split('/')[-1]).split('.')[0]
    os.rename("predictions.jpg", os.path.join(path_to_save_images, image_name+'.jpg'))
    print("img was saved")

from map.

cyrus303 avatar cyrus303 commented on May 13, 2024 3

Done! Have a look here.

Basically, all you have to do is add the result.txt to the folder extra/ and run the command python convert_pred_yolo.py

Hey, i am not able to find the page. could you redirect me please so that i can find the file

from map.

pratikbhave2 avatar pratikbhave2 commented on May 13, 2024

Hey, you can look at my repo:

https://github.com/pratikbhave2/darknet

from map.

EscVM avatar EscVM commented on May 13, 2024

I don't get it. What is in your repo?

from map.

pratikbhave2 avatar pratikbhave2 commented on May 13, 2024

I have Modified Yolo to run detector test on multiple images and save each image with bounding boxes, as well as co-ordinates of the bounding box in a text file(separate text file). You can run it with the same command
.
./darknet detector test cfg/voc.data yolo-voc.cfg yolo-voc.weights -dont_show -ext_output < data/train.txt > result.txt

from map.

Cartucho avatar Cartucho commented on May 13, 2024

Hello!

@EscVM I could help you parse that. Do you think you could send me the full file result.txt to here [email protected] ?

Another option, as mentioned by @pratikbhave2, is to modify the files to save the predictions into separate files.

from map.

EscVM avatar EscVM commented on May 13, 2024

Thank you @pratikbhave2 and @Cartucho. I'll try both solutions.

from map.

Cartucho avatar Cartucho commented on May 13, 2024

Btw I did the python script with a lot of comments so everything should be easy to understand!

from map.

EscVM avatar EscVM commented on May 13, 2024

Thank so much @Cartucho ! I really need to improve my Python skills 🤕

from map.

buzdarbalooch avatar buzdarbalooch commented on May 13, 2024

@Cartucho thanks alot for posts. just a question this is how my result.txt file looks like.
image

when i execute the script (python convert_pred_yolo.py) , i get this error below

image

from map.

Cartucho avatar Cartucho commented on May 13, 2024

@buzdarbalooch Hello!
Do you think you could send me a sample of the files? So that I can reproduce the error?

[email protected]

from map.

creabob avatar creabob commented on May 13, 2024

Done! Have a look here.

Basically, all you have to do is add the result.txt to the folder extra/ and run the command python convert_pred_yolo.py

so how to get result.txt in faster rcnn

from map.

cyrus303 avatar cyrus303 commented on May 13, 2024

Hey, you can look at my repo:

https://github.com/pratikbhave2/darknet

Hey when i run using your repo in yolov3 i am getting segmentation error.. could you help me out please?

/bin/bash: line 1: 1655 Segmentation fault (core dumped) ./darknet detector test data/obj.data cfg/yolov3_custom_test.cfg /mydrive/weapon_dataset/backup/yolov3_custom_train_last.weights -dont_show -save_labels < data/train.txt > result.txt

from map.

Temweka avatar Temweka commented on May 13, 2024

Hey, you can look at my repo:
https://github.com/pratikbhave2/darknet

Hey when i run using your repo in yolov3 i am getting segmentation error.. could you help me out please?

/bin/bash: line 1: 1655 Segmentation fault (core dumped) ./darknet detector test data/obj.data cfg/yolov3_custom_test.cfg /mydrive/weapon_dataset/backup/yolov3_custom_train_last.weights -dont_show -save_labels < data/train.txt > result.txt

I get the same error

from map.

tianlanlanlan avatar tianlanlanlan commented on May 13, 2024

i changed the code from vadimen a little bit, it no need for wait 6s every time, parent process continue after child process exit
and i copy the ground truth to prediction dir too as a comparison
it worked for me

import os
from os import getcwd
import subprocess
import time
import shutil

wd = getcwd()

image_paths_file = "data/train-second/test.txt"
obj_dat = "data/train-second/obj.data"
yolo_cnf = "cfg/yolov4-custom-3.cfg"
yolo_wghts = "backup/yolov4-custom-3_best.weights"
path_to_ground_truth = "data/pic_with_box"

im_paths = open(image_paths_file).read().strip().split('\n')
cfgfilename = yolo_cnf.split('/')[1].split('.')[0]
print(cfgfilename)
path_to_save_predictions = "predictions-%s/"%(cfgfilename)

if not os.path.exists(path_to_save_predictions):
    os.makedirs(path_to_save_predictions)

for im in im_paths:
    if len(im) == 0:
        continue
    cmd = "./darknet detector test %s %s %s -dont_show %s"%(obj_dat, yolo_cnf, yolo_wghts, im)
    print('cmd = %s'%(cmd))
    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, preexec_fn=os.setsid)
    # wait max 6s
    p.wait(6)
    # make sure child process exit normally
    if p.poll() != 0:
        print("picture %s predict fails\n"%(im))
        break
    image_name = (im.split('/')[-1]).split('.')[0]
    os.rename("predictions.jpg", os.path.join(path_to_save_predictions, image_name+'.jpg'))
    # cp groud truth near the predictions dir
    # already draw box and saved in path_to_ground_truth dir, if not want to copy, just comment the next line
    shutil.copy(path_to_ground_truth+'/'+image_name+'.jpg', path_to_save_predictions+'/'+image_name+"-truth.jpg")
    print(image_name)

Screenshot from 2022-04-14 23-14-31

from map.

DikshitV avatar DikshitV commented on May 13, 2024

here is a simple code, works for yolov3 of v4 or any other, adjust the paths, time or even the command for yourself

import os
import subprocess
import time

image_paths_file = '/home/darknet/vadim_configs/test.txt'
path_to_save_images = '/home/darknet/results/'

im_paths = open(image_paths_file, "r").readlines()

obj_dat = "/home/darknet/vadim_configs/obj.data"
yolo_cnf = "/home/darknet/vadim_configs/yolov4-custom.cfg"
yolo_wghts = "/home/darknet/backup/yolov4-custom_best.weights"

for im in im_paths:
    cmd = "./darknet detector test {} {} {} -dont_show \"{}\"".format(obj_dat, yolo_cnf, yolo_wghts, im)

    # The os.setsid() is passed in the argument preexec_fn so
    # it's run after the fork() and before  exec() to run the shell.

    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, preexec_fn=os.setsid)

    # it must be adjuste to your inference speed
    # on my rtx2080 takes 6 seconds max
    time.sleep(6)
    # Send the signal to all the process groups
    #os.killpg(os.getpgid(p.pid), signal.SIGTERM)

    image_name = (im.split('/')[-1]).split('.')[0]
    os.rename("predictions.jpg", os.path.join(path_to_save_images, image_name+'.jpg'))
    print("img was saved")

Thanks for the code. It works well. How to get output of bounding box coordinates for each image in this file itself?
I'm trying but not possible. Request to assist me.

from map.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.