文章目录

  • 1、下载YAD2K
  • 2、模型转换
  • 3、将.h5模型文件转换为tfjs模型文件
  • 4、前端部署
  • 5、遇到的问题及解决办法

1、下载YAD2K

YAD2K是一个转换器,将darknet的权重(weights)和配置(cfg)文件转换为keras的模型文件(.h5)。
安装步骤:
具体安装步骤这里有介绍

# clone文件,再进入cd到文件夹
git clone https://github.com/allanzelener/yad2k.git
cd yad2k

2、模型转换

① 需要修改一些bug,将yad2k.py中,第83行buffer = weights_file.read(16) 改为buffer = weights_file.read(20);


从网址https://pjreddie.com/media/files/yolov2-tiny.weights下载yolov2-tiny的权重文件yolov2-tiny.weights;
从网址https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov2-tiny.cfg下载yolov2-tiny的配置文件yolov2-tiny.cfg;

③ 将这两个文件都放置在yad2k的根目录下,在根目录下打开终端,输入:

python yad2k.py yolov2-tiny.cfg yolov2-tiny.weights model_data/yolov2-tiny.h5

将darknet的模型文件转换为keras的模型文件;

⑤ 转换完之后记得运行检验一下

python test_yolo.py model_data/yolov2-tiny.h5

如果能够输出一些预测数据,则说明没有问题
如:

Using TensorFlow backend.
2019-10-15 17:04:09.704439: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2019-10-15 17:04:09.945269: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties:
name: GeForce GTX 1060 6GB major: 6 minor: 1 memoryClockRate(GHz): 1.7085
pciBusID: 0000:01:00.0
totalMemory: 6.00GiB freeMemory: 4.96GiB
2019-10-15 17:04:09.952606: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2019-10-15 17:04:10.295898: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-10-15 17:04:10.299511: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990]      0
2019-10-15 17:04:10.301350: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0:   N
2019-10-15 17:04:10.303334: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4706 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
WARNING:tensorflow:From D:\anaconda\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
D:\anaconda\lib\site-packages\keras\engine\saving.py:292: UserWarning: No training configuration found in save file: the model was *not* compiled. Compile it manually.warnings.warn('No training configuration found in save file: '
model_data/yolov2-tiny.h5 model, anchors, and classes loaded.
Found 6 boxes for dog.jpg
person 0.34 (66, 66) (97, 94)
car 0.40 (500, 101) (716, 176)
motorbike 0.44 (64, 78) (100, 120)
dog 0.44 (128, 212) (389, 531)
car 0.62 (455, 85) (669, 166)
bicycle 0.85 (45, 93) (596, 482)
Found 1 boxes for eagle.jpg
bird 0.87 (57, 127) (608, 465)
Found 2 boxes for giraffe.jpg
giraffe 0.62 (145, 0) (445, 416)
zebra 0.75 (262, 274) (418, 444)
Found 4 boxes for horses.jpg
horse 0.46 (224, 187) (437, 374)
horse 0.58 (7, 183) (171, 255)
horse 0.87 (421, 208) (589, 352)
horse 0.87 (9, 187) (292, 400)
Found 3 boxes for person.jpg
dog 0.66 (66, 258) (203, 349)
horse 0.75 (420, 133) (597, 335)
person 0.86 (184, 100) (277, 337)
Found 0 boxes for scream.jpg

3、将.h5模型文件转换为tfjs模型文件

首先需要有tensorflowjs API,可以pip install tensorflowjs安装,建议使用虚拟环境。

ensorflowjs_converter --input_format keras \         # keras的固定格式model_data/yolov2-tiny.h5 \     # .h5所在的路径tfjs_model_data                   # 转换后的模型保存路劲

具体转换方法可参考官网介绍

4、前端部署

在html文件中导入tfjs:

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"> </script>

调用:

<script>const url = "./tfjs_model_data/model.json";         // 模型路径async function func() {const model = await tf.loadLayersModel(url);    // 加载模型console.log(model);result = model.predict(img);                      // 模型预测}func();
</script>

5、遇到的问题及解决办法

FileNotFoundError: [Errno 2] No such file or directory: 'model_data/yolo_anchors.txt’
解决办法:
将model_data里面的yolov2_tiny_anchors.txt改为yolo_anchors.txt即可

PermissionError: [Errno 13] Permission denied: 'images\out’
解决办法:
将test_yolo.py的第118行前面加上 if os.path.isfile(os.path.join(test_path, image_file)): ,后面的代码相应对齐(119~190行)

将yolov2-tiny模型部署到前端相关推荐

  1. 基于web端和C++的两种深度学习模型部署方式

    深度学习Author:louwillMachine Learning Lab 本文对深度学习两种模型部署方式进行总结和梳理.一种是基于web服务端的模型部署,一种是基... 深度学习 Author:l ...

  2. 基于C++的PyTorch模型部署

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 引言 PyTorch作为一款端到端的深度学习框架,在1.0版本之后 ...

  3. 一文详解AI模型部署及工业落地方式

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 Hello大家好,我是老潘,好久不见各位~ 最近在复盘今年上半年做的一些事情,不管是训练模型.部署模型 ...

  4. 移动端video隐藏进度条_机器学习模型部署--打通前后端任督二脉

    前言 没有 GPU,没有服务器?滴滴云 GPU 服务器,8GB内存/8GB显卡,优惠期内2200元包年.别急,输入AI 大师码:8754,折扣价基础上,再加9折优惠.快速链接:滴滴云 AI 特权 学历 ...

  5. 【视频课】模型部署课程更新!ncnn框架快速实践!

    前言 欢迎大家关注有三AI的视频课程系列,我们的视频课程系列共分为5层境界,内容和学习路线图如下: 第1层:掌握学习算法必要的预备知识,包括Python编程,深度学习基础,数据使用,框架使用. 第2层 ...

  6. 【深度学习】基于web端和C++的两种深度学习模型部署方式

    深度学习 Author:louwill Machine Learning Lab 本文对深度学习两种模型部署方式进行总结和梳理.一种是基于web服务端的模型部署,一种是基于C++软件集成的方式进行部署 ...

  7. pytorch基于web端和C++的两种深度学习模型部署方式

    本文对深度学习两种模型部署方式进行总结和梳理.一种是基于web服务端的模型部署,一种是基于C++软件集成的方式进行部署. 基于web服务端的模型部署,主要是通过REST API的形式来提供接口方便调用 ...

  8. 为什么将表格的method改为post后就无法工作_用Python将Keras深度学习模型部署为Web应用程序...

    构建一个很棒的机器学习项目是一回事,但归根结底,你希望其他人能够看到你的辛勤工作.当然,你可以将整个项目放在GitHub上,但是怎么让你的祖父母也看到呢?我们想要的是将深度学习模型部署为世界上任何人都 ...

  9. 面向生产环境!深度学习模型部署资源全辑

    点上方计算机视觉联盟获取更多干货 仅作学术分享,不代表本公众号立场,侵权联系删除 转载于:机器学习实验室   Author:louwill Machine Learning Lab AI博士笔记系列推 ...

最新文章

  1. 【从零开始的ROS四轴机械臂控制】(七)- ROS与arduino连接
  2. Linux进阶 vim grep sed awk 正则表达式
  3. 让FX1.1的NotifyIcon支持BalloonTip(1)
  4. android高德地图显示多点标记,高德地图多点标记自定义地图
  5. 二极管名称中英文互译
  6. Matlab基本函数-conj函数
  7. (转)怎么实时查看mysql当前连接数
  8. Java实现单链表的合并(保证数据的有序性)
  9. python 去除所有的中文 英文标点符号
  10. php 接口说明文档,phpwind文章中心接口说明
  11. 数据结构算法的一些归纳
  12. Django - - - -视图层之视图函数(views)
  13. 什么?你项目还在用Date表示时间?!
  14. 百度百科推广大师 v1.7.6.1
  15. Running PostgreSQL using Docker Compose
  16. WPF特效-粒子动画
  17. 分清函数指针和指针函数
  18. MOSS 2010:Visual Studio 2010开发体验(32)——工作流开发最佳实践(四):可重用工作流...
  19. Visual C++ 2005 系列课程学习笔记-6
  20. UIFont各种字体

热门文章

  1. Android APP一键退出的方法总结分析
  2. 【C语言基础练习】100匹马驮100担货,大马一匹驮3担,中马一匹驮2担,小马两匹驮1担。试编写程序计算大、中、小马的数目。
  3. Ubuntu设置清华源
  4. Android开发之Activity的生命周期详解
  5. 一本好的“错题集”如何做?看这里
  6. 武汉地铁软件测试自学,武汉影视节目制作培训(视频剪辑是否好找工作)
  7. 架构道术-从心流视角看费曼学习法
  8. [小黄书后台]Insomnia及HelloWorld
  9. CSS 渐变色 (超好看)
  10. Unity 使用 Behaviac (二)让unity的行为能执行behaviac搭建的树的逻辑