Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV(3.4.5) + DNN (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgStream' #1

Closed
joaopalma5 opened this issue Jan 7, 2019 · 32 comments

Comments

@joaopalma5
Copy link

joaopalma5 commented Jan 7, 2019

python3 yolo_opencv.py -c custom/yolov3-tiny.cfg -w backup/yolov3-tiny_120000.weights -cl custom/objects.names
['bola']
Traceback (most recent call last):
File "yolo_opencv.py", line 47, in
net = cv2.dnn.readNet(args.weights,args.config)
cv2.error: OpenCV(3.4.5) /io/opencv/modules/dnn/src/darknet/darknet_io.cpp:507: error: (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgStream'

I have this error on try your code... In darknet we can Run inference, and get results. You know the reason?

@tahaemara
Copy link
Owner

Did you set the number of anchors to 6?. Tiny yolo uses 6 anchors instead of 9 anchors in case of normal Yolo here

@ajaykaarthic
Copy link

ajaykaarthic commented Sep 15, 2019

I have set it to 6 and yet i get the error !, how can i resolve this?
Screenshot from 2019-09-15 16-50-34

@Rakhesh96
Copy link

Though i tried anchor values to be 6 and 9 still it is not working, the same error is being show ...kindly help me out @tahaemara
unnamed

@ADLTU
Copy link

ADLTU commented Dec 4, 2019

Hi, if you are using mac I found that if you use the textEdit.app, it adds a few lines at the top(you can't see them unless you use another editor) that are causing an issue, simply remove them and it will be fine.

@gmatesunny
Copy link

gmatesunny commented Jan 7, 2020

I have set following in yolov3-tiny.cfg

[yolo]
mask = 3,4,5
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=4
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1

[yolo]
mask = 0,1,2
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=4
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1

still I get the error:

Traceback (most recent call last):
File "yolo_opencv.py", line 49, in
net = cv2.dnn.readNet(args.weights,args.config)
cv2.error: OpenCV(4.1.0) /io/opencv/modules/dnn/src/darknet/darknet_io.cpp:509: error: (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgStream'

I have also checked whether any extra line is added. I am on Ubuntu 16.04
Suggest me what shall I do next?

@gmatesunny
Copy link

Though i tried anchor values to be 6 and 9 still it is not working, the same error is being show ...kindly help me out @tahaemara
unnamed

Did you able to solve the problem?

@gmatesunny
Copy link

gmatesunny commented Jan 7, 2020

Did you set the number of anchors to 6?. Tiny yolo uses 6 anchors instead of 9 anchors in case of normal Yolo here

This issue shall be reopened.

@DocGrenas
Copy link

I have the same problem

net = cv2.dnn.readNetFromDarknet(_net_weights_path, _net_cfg_path)
cv2.error: OpenCV(3.4.2) /opt/concourse/worker/volumes/live/9523d527-1b9e-48e0-7ed0-a36adde286f0/volume/opencv-suite_1535558719691/work/modules/dnn/src/darknet/darknet_io.cpp:511: error: (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgFile'

Have any idea?

Please tell me more

@ADLTU
Copy link

ADLTU commented Jan 7, 2020

@gmatesunny did you check what I said before, do that if you are using mac

@DocGrenas
Copy link

@gmatesunny did you check what I said before, do that if you are using mac

HI.
I am using Mac and I have checked your suggestion but i can not see the xtra lines.

I have run my program on Vstudio

Another suggestion ?

@gmatesunny
Copy link

@ADLTU : I checked and it doesn't have extra lines. I am using vscode as editor.

@ADLTU
Copy link

ADLTU commented Jan 7, 2020

Please do this and send a screenshot.
Screenshot 2020-01-07 at 23 27 25

@DocGrenas
Copy link

Hi.

I am using the yolov3.cfg

Screen Shot 2020-01-08 at 1 38 38 PM

@ADLTU
Copy link

ADLTU commented Jan 9, 2020 via email

@bikramb98
Copy link

@DocGrenas Facing the exact same problem as this:

net = cv2.dnn.readNetFromDarknet(_net_weights_path, _net_cfg_path)
cv2.error: OpenCV(3.4.2) /opt/concourse/worker/volumes/live/9523d527-1b9e-48e0-7ed0-a36adde286f0/volume/opencv-suite_1535558719691/work/modules/dnn/src/darknet/darknet_io.cpp:511: error: (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgFile'

Have you managed to solve it? Thanks!

@MorshedBabu
Copy link

MorshedBabu commented Apr 24, 2020

Use absolute path, it would work. For example,

For Loading Yolo

net = cv2.dnn.readNetFromDarknet("/home/babu/darknet/cfg/yolov3-tiny.cfg","/home/babu/darknet/yolov3-tiny.weights")

For Loading image

img = cv2.imread("/home/babu/darknet/data/dog.jpg")

@pra-dan
Copy link

pra-dan commented Apr 30, 2020

@MorshedBabu

Use absolute path, it would work. For example,

For Loading Yolo

net = cv2.dnn.readNetFromDarknet("/home/babu/darknet/cfg/yolov3-tiny.cfg","/home/babu/darknet/yolov3-tiny.weights")

For Loading image

img = cv2.imread("/home/babu/darknet/data/dog.jpg")

I get this

Failed to parse NetParameter file: ~/docker/tiny_yolo_dark/yolov2-tiny.cfg in function 'readNetFromDarknet'

@hrithikppawar
Copy link

Use absolute path, it would work. For example,

For Loading Yolo

net = cv2.dnn.readNetFromDarknet("/home/babu/darknet/cfg/yolov3-tiny.cfg","/home/babu/darknet/yolov3-tiny.weights")

For Loading image

img = cv2.imread("/home/babu/darknet/data/dog.jpg")

I did this but still getting the same error...

config_path = '/home/rozer/dev/ML Projects/YOLO_Object_Detection/yolov3.cfg'
weight_path = '/home/rozer/dev/ML Projects/YOLO_Object_Detection/yolov3.weights'
net = cv2.dnn.readNetFromDarknet(config_path, weight_path)
cv2.error: OpenCV(4.4.0) /tmp/pip-install-t2n0bol9/opencv-python/opencv/modules/dnn/src/darknet/darknet_io.cpp:628: error: (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgStream'

I tried all above steps, but nothing worked, can anyone help me with this... Thank You!

@fedeos
Copy link

fedeos commented Nov 10, 2020

Try using this yolov3.cfg file. You will have to unzip it first.

yolov3.cfg.zip

@LahiruPradeePSenadhiraLankeshwara

Try using this yolov3.cfg file. You will have to unzip it first.

yolov3.cfg.zip

Thank You it works

@ShashikatReddy
Copy link

ShashikatReddy commented Jan 1, 2021

Even i'm getting same error while performing prediction on trained YOLOv3 Tiny. I i have checked number of anchor are 6 only.

Could someone help me on this please .

I have trained model in my virtual machine Ubuntu 20.04

Command
darknet$ python3 yolo_opencv.py -c /home/ai/darknet/training/yolov3-tiny.cfg -w /home/ai/darknet/backup/yolov3-tiny_60000.weights -cl /home/ai/darknet/training/objects.names

Error

Traceback (most recent call last):
File "yolo_opencv.py", line 47, in
net = cv2.dnn.readNet(args.weights,args.config)
cv2.error: OpenCV(4.2.0) ../modules/dnn/src/darknet/darknet_io.cpp:519: error: (-215:Assertion failed) separator_index < line.size() in function 'ReadDarknetFromCfgStream'

@fedeos
Copy link

fedeos commented Jan 6, 2021

Try with this yolov3-tiny.cfg file:
yolov3-tiny.zip

@sujitvasanth
Copy link

Thannks @fadeos your cfg file worked...for me...
i read the original cfg file downloaded from darknet website and it was a html file.....

@fedeos
Copy link

fedeos commented Jan 24, 2021

Great! I hope you can move on and complete your project.

@charlie6echo
Copy link

charlie6echo commented Apr 7, 2021

the Original file that is on pjreddie's repo has been corrupted, please refer this one yolov3.cfg.

@andyrey
Copy link

andyrey commented Nov 25, 2021

Just check up your .cfg file carefully. In my case, I accidentally removed # before word Testing. When transfer configuration file from training mode to testing one, we can do very simple error inadvertently.

@Vinod95-git
Copy link

I get the same error but I am using yolov4 model. Any suggestions please?

image

@trabelsim
Copy link

trabelsim commented Jan 2, 2022

I had the same issue and even trying with the new .cfg file did not work.
Have a look at the order of the argument You are providing!

OpenCv in its documentation states that the order of model and config arguments does not matter, HOWEVER in my case it did matter. First config file and then weights (for DarkNet).

This works for me:
Net net = readNetFromDarknet(modelConf, modelWeig);

@smallbook
Copy link

I think this is due to a few # in the cfg file that you need to remove,
and try again,
it worked for me.

@Soroosh-N
Copy link

I think the problem is that some of us are downloading the "PAGE OF FILE". not the file itself! I mean, for downloading the cfg file, don't use this link:
https://github.com/pjreddie/darknet/blob/master/cfg/yolov3.cfg
Instead, use this link (The exact same file. but its file address. not page address):
https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov3.cfg
Hope it works for you.

@K-GOKULAPPADURAI
Copy link

Try with this yolov3-tiny.cfg file: yolov3-tiny.zip

ya that error gone but a new error came

cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\darknet\darknet_io.cpp:933: error: (-213:The function/feature is not implemented) Transpose the weights (except for convolutional) is not implemented in function 'cv::dnn::darknet::ReadDarknetFromWeightsStream'

@Emyyr
Copy link

Emyyr commented May 7, 2023

Hi ,

I tried this method and this solved my problem but I want to talk about another solution. Configs are not broken. This is my idea. Just change your anchors from from your .cfg file. I put COCO anchors from yolov3-tiny.cfg to my cfg and it worked for me. You can try this options:

  1. Control your .cfg file (spaces, comments "#" )
  2. Control batch and subdivision (batch=1, subdivisions=1). I am writing this but didn't try :) . Because yolov3-tiny.cfg's batch and subdivison like this.
  3. Control your .cfg and .weight file path in your code.
  4. Control your anchors.

Try with this yolov3-tiny.cfg file: yolov3-tiny.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests