tahaemara / yolo-custom-object-detector

Making custom object detector using Yolo (Java and Python)
http://emaraic.com/blog/yolov3-custom-object-detector
92 stars 67 forks source link

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

Closed joaopalma5 closed 5 years ago

joaopalma5 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

DocGrenas commented 4 years ago

@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 commented 4 years ago

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

ADLTU commented 4 years ago

Please do this and send a screenshot.

Screenshot 2020-01-07 at 23 27 25
DocGrenas commented 4 years ago

Hi.

I am using the yolov3.cfg

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

ADLTU commented 4 years ago

Hi it won’t appear there, I had the same problem open the file in terminal and you’ll see.

Hadi On Wed, 8 Jan 2020 at 19:40, DocGrenas notifications@github.com wrote:

Hi.

I am using the yolov3.cfg

[image: Screen Shot 2020-01-08 at 1 38 38 PM] https://user-images.githubusercontent.com/59627002/72009887-600a9200-321c-11ea-9b20-fe0a7e4f0772.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tahaemara/yolo-custom-object-detector/issues/1?email_source=notifications&email_token=AIDB4NK4YSFKN5COW5M7WN3Q4YTZVA5CNFSM4GOOIKB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEINXJSI#issuecomment-572224713, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIDB4NKTU3DUV2NFSLFUJ3TQ4YTZVANCNFSM4GOOIKBQ .

bikramb98 commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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 commented 3 years ago

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

yolov3.cfg.zip

LahiruPradeePSenadhiraLankeshwara commented 3 years ago

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

yolov3.cfg.zip

Thank You it works

ShashikatReddy commented 3 years ago

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 commented 3 years ago

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

sujitvasanth commented 3 years ago

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 commented 3 years ago

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

charlie6echo commented 3 years ago

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

andyrey commented 2 years ago

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 commented 2 years ago

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

image

trabelsim commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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