How to convert the darknet yolo model to keras?
How to convert the darknet yolo model to keras?
I am using yad2k to convert the darknet YOLO model to a keras .h5 format. I have yolov3-voc.cfg, yolov3.weights, and yolov3.cfg all in the directory above the one that contains the yad2k script. When I run the following command:
python3 yad2k.py -p ../yolov3-voc.cfg ../yolov3.weights model_data/yolov3.h5
or:
python3 yad2k.py -p ../yolov3.cfg ../yolov3.weights model_data/yolov3.h5
I get the following error:
Traceback (most recent call last):
File "yad2k.py", line 271, in <module>
_main(parser.parse_args())
File "yad2k.py", line 90, in _main
cfg_parser.read_file(unique_config_file)
File "/Users/tobykrieman/anaconda/lib/python3.6/configparser.py", line 718, in read_file
self._read(f, source)
File "/Users/tobykrieman/anaconda/lib/python3.6/configparser.py", line 1080, in _read
raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: '<???>', line: 7
'<!DOCTYPE html>n'
How can I fix this?
3 Answers
3
Your darknet .cfg
files likely aren't correct. They should look something like this:
.cfg
[net]
batch=128
subdivisions=1
height=227
width=227
channels=3
momentum=0.9
decay=0.0005
max_crop=256
learning_rate=0.01
policy=poly
power=4
max_batches=800000
angle=7
hue = .1
saturation=.75
exposure=.75
aspect=.75
[convolutional]
filters=96
...
(taken from https://github.com/pjreddie/darknet/blob/master/cfg/alexnet.cfg)
Your .cfg
file seems like it has HTML in it.
.cfg
You cannot convert YOLOv3 to Keras model using YAD2K. This is because YOLOv3's configuration file has a [shortcut]
header. The yad2k.py file has no method to handle this header as it was written in the times of YOLOv2 (which doesn't have this layer/header).
[shortcut]
However, in your case, you seem to be reading a different kind of configuration file, which apparently has a <!DOCTYPE html>n
tag. But in any case, even if you try it with the YOLOv3 cfg, it won't work for the reason i mentioned above. Tried it myself!
<!DOCTYPE html>n
You should try the instructions in this Github repository, which is a "A Keras implementation of YOLOv3"
git clone https://github.com/qqwweee/keras-yolo3.git
cd keras-yolo3
wget https://pjreddie.com/media/files/yolov3.weights
python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5
python yolo.py OR python yolo_video.py [video_path] [output_path(optional)]
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment