yolov3+keras2.1.5+tensorflow1.14

**

yolov3+keras2.1.5+tensorflow1.14

用了这个方法来训练自己的数据集:
yolo3

如果忽略一堆关于版本问题的警告的话,然后就出现了以下报错
**

load_weights(),got an unexpected keyword argument skip_mismatch

然后解决方法是这样的:
因为keras旧版本没有这一定义,在新的版本中有这一关键字的定义,因此,更新keras版本至2.1.5即可解决。
source activate env

pip uninstall keras
pip install keras==2.1.5

再次运行,该问题解决,出现了这样的问题:

F:\python\Anaconda\python.exe E:/论文/其他文件/深度学习项目/yolo/keras-yolo3-master/train.py
Using TensorFlow backend.
WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:88: The name tf.reset_default_graph is deprecated. Please use tf.compat.v1.reset_default_graph instead.

WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:91: The name tf.placeholder_with_default is deprecated. Please use tf.compat.v1.placeholder_with_default instead.

WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:95: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:507: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:3831: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

2020-04-26 23:35:05.086547: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:1797: The name tf.nn.fused_batch_norm is deprecated. Please use tf.compat.v1.nn.fused_batch_norm instead.

WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:1940: The name tf.image.resize_nearest_neighbor is deprecated. Please use tf.compat.v1.image.resize_nearest_neighbor instead.

Create YOLOv3 model with 9 anchors and 20 classes.
Traceback (most recent call last):
  File "E:/论文/其他文件/深度学习项目/yolo/keras-yolo3-master/train.py", line 190, in <module>
    _main()
  File "E:/论文/其他文件/深度学习项目/yolo/keras-yolo3-master/train.py", line 33, in _main
    freeze_body=2, weights_path='model_data/yolo_weights.h5') # make sure you know what you freeze
  File "E:/论文/其他文件/深度学习项目/yolo/keras-yolo3-master/train.py", line 120, in create_model
    model_body.load_weights(weights_path, by_name=True, skip_mismatch=True)
  File "F:\python\Anaconda\lib\site-packages\keras\engine\topology.py", line 2647, in load_weights
    with h5py.File(filepath, mode='r') as f:
  File "F:\python\Anaconda\lib\site-packages\h5py\_hl\files.py", line 394, in __init__
    swmr=swmr)
  File "F:\python\Anaconda\lib\site-packages\h5py\_hl\files.py", line 170, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py\h5f.pyx", line 85, in h5py.h5f.open
OSError: Unable to open file (unable to open file: name = 'model_data/yolo_weights.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

Process finished with exit code 1

前面那一堆警告都不重要,重要的是你发现这个问题被解决了,然后出现的那个问题是因为我的权重模型以1Kb不到的速度下载了三小时没下载下来无奈被我自己关了让别人以快我网速8倍的速度去下载了,下载到什么时候能成还真不知道。
终于下载完了
开始操作:
转换权重.weights文件为.h5文件:

python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5

找张图片来test,运行代码:

python yolo_video.py --image #测试图片 其余可以用pthon yolo_video.py -h显示帮助

注:直接编译的话报错还是这样,使用cmd就可以
但是问题在于现在只能单张图片操作,我需要整个文件夹来操作。

Using TensorFlow backend.
WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:88: The name tf.reset_default_graph is deprecated. Please use tf.compat.v1.reset_default_graph instead.

WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:91: The name tf.placeholder_with_default is deprecated. Please use tf.compat.v1.placeholder_with_default instead.

WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:95: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:507: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:3831: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

2020-04-27 00:54:19.234162: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:1797: The name tf.nn.fused_batch_norm is deprecated. Please use tf.compat.v1.nn.fused_batch_norm instead.

WARNING:tensorflow:From F:\python\Anaconda\lib\site-packages\keras\backend\tensorflow_backend.py:1940: The name tf.image.resize_nearest_neighbor is deprecated. Please use tf.compat.v1.image.resize_nearest_neighbor instead.

Create YOLOv3 model with 9 anchors and 20 classes.
Traceback (most recent call last):
  File "E:/论文/其他文件/深度学习项目/yolo/keras-yolo3-master/train.py", line 190, in <module>
    _main()
  File "E:/论文/其他文件/深度学习项目/yolo/keras-yolo3-master/train.py", line 33, in _main
    freeze_body=2, weights_path='model_data/yolo_weights.h5') # make sure you know what you freeze
  File "E:/论文/其他文件/深度学习项目/yolo/keras-yolo3-master/train.py", line 120, in create_model
    model_body.load_weights(weights_path, by_name=True, skip_mismatch=True)
  File "F:\python\Anaconda\lib\site-packages\keras\engine\topology.py", line 2647, in load_weights
    with h5py.File(filepath, mode='r') as f:
  File "F:\python\Anaconda\lib\site-packages\h5py\_hl\files.py", line 394, in __init__
    swmr=swmr)
  File "F:\python\Anaconda\lib\site-packages\h5py\_hl\files.py", line 170, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py\h5f.pyx", line 85, in h5py.h5f.open
OSError: Unable to open file (unable to open file: name = 'model_data/yolo_weights.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

这个倒是行了
上面记录一些瞎撞的时候遇到的坑,下面这个是最终成功的版本
**

最后成功的版本

首先是配置:yolov3+keras2.1.5+tensorflow1.14+python3.7
**
超牛逼的八九不离十版本
对大佬的方法的一些补充:
注意自己图片的尺寸要修改
然后这一步:
train.txt文件夹里由于我第一次用的是之前做fastrcnn的该文件,里面的文件名字是这样的:
yolov3+keras2.1.5+tensorflow1.14_第1张图片

然后事实上这是不对的,会报错

No such file or directory: 'BloodImage_00147

而且是随缘报错文件名相关,每次错的都不一样,后来发现应该用大佬博客中缩写的那步生成的文件夹,里面文件格式是这样的:

E:\论文\其他文件\深度学习项目\yolo\yolov3t2\keras-yolo3-master/VOCdevkit/VOC2007/JPEGImages/BloodImage_00000.jpg 260,177,491,376,0 78,336,184,435,1 63,237,169,336,1 214,362,320,461,1 414,352,506,445,1 555,356,640,455,1 469,412,567,480,1 1,333,87,437,1 4,406,95,480,1 155,74,247,174,1 11,84,104,162,1 534,39,639,139,1 547,195,640,295,1 388,11,481,111,1 171,175,264,275,1 260,1,374,83,1 229,91,343,174,1 69,144,184,235,1 482,131,594,230,1 368,89,464,176,1

还有建议直接在python train.py之前先在train.py同级目录下建立logs文件夹,在这个文件夹下再建立000文件夹再执行train.py文件,要问为什么,反正我是直接建立没成功。

原博yolo项目里的yolo.py(测试训练结果用的)运行完可能是没有任何显示直接闪一下就又回到待输入状态,评论区大佬给出了新的版本,(因为翻不到评论区大佬的评论了,有谁知道请告诉我我放一下大佬的链接,感谢!)在这里放一下网盘链接:

链接:https://pan.baidu.com/s/1Il5e34rUA41uSCYtWnWCsQ
提取码:3f8c

指令:

python yolo_test.py

这个是可以用的。
如果训练完之后发现显示找不到目标,可以适当调整

"score" : 0.3,
"iou" : 0.45,

这两个参数,调整小了会比较容易看到,如果圈的不好,可能是因为你的训练结果不够好,建议继续训练或者调整参数。

修改yolov3.cfg这个文件的时候,按照大佬说的搜索yolo你很可能只能看见classes这一种,并不能找到修改filters的地方,直接搜索filters的话又会出现一堆filters,所以综合

filters:3*(5+len(classes));

这个公式,建议搜索255,然后将3个255的地方改成自己的filters即可。

注意cuda和cudnn的下载配置
这里放个链接:
cudnn10.0

链接:https://pan.baidu.com/s/19BbXJDZ9VnaYdoBRRKZZvg
提取码:1icr
复制这段内容后打开百度网盘手机App,操作更方便哦

cuda 10.0

链接:https://pan.baidu.com/s/1PDchbxPHzk1H7iPvH1VSNQ
提取码:k04z

注:yolo方法运行速度慢,但精度大,如果不需要很大的精度,但追求速度的话,可以去试着使用yolo tiny进行运算。

你可能感兴趣的:(深度学习,tensorflow,python)