编程语言
首页 > 编程语言> > 三分钟:极速体验JAVA版目标检测(YOLO4)

三分钟:极速体验JAVA版目标检测(YOLO4)

作者:互联网

欢迎访问我的GitHub

https://github.com/zq2599/blog_demos

内容:所有原创文章分类汇总及配套源码,涉及Java、Docker、Kubernetes、DevOPS等;

本篇概览

在这里插入图片描述

  1. 下载模型和配置文件
  2. 运行docker容器,这是个web服务,咱们用浏览器访问此服务,提交照片完成检测
  3. 验证效果(在浏览器上打开web页面,提交图片,等待检测结果)

风险提前告知

环境信息

  1. 操作系统:Ubuntu 16(MacBook Pro也可以,版本是11.2.3,macOS Big Sur)
  2. docker:20.10.2 Community

下载模型和配置文件

  1. YOLOv4配置文件: https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/yolov4.cfg
  2. YOLOv4权重: https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
  3. 分类名称: https://raw.githubusercontent.com/AlexeyAB/darknet/master/data/coco.names
/home/will/temp/202110/19/
├── images
└── model
    ├── coco.names
    ├── yolov4.cfg
    └── yolov4.weights

运行docker容器

sudo docker run \
--rm \
--name yolodemo \
-p 8080:8080 \
-v /home/will/temp/202110/19/images:/app/images \
-v /home/will/temp/202110/19/model:/app/model \
bolingcavalry/yolodemo:0.0.1
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.8)

2021-10-19 07:39:20.112  INFO 1 --- [           main] c.b.yolodemo.YoloDemoApplication         : Starting YoloDemoApplication using Java 1.8.0_292 on 06e6b68f43ca with PID 1 (/app started by root in /)
2021-10-19 07:39:20.115  INFO 1 --- [           main] c.b.yolodemo.YoloDemoApplication         : No active profile set, falling back to default profiles: default
2021-10-19 07:39:20.997  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-10-19 07:39:21.010  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-10-19 07:39:21.010  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.48]
2021-10-19 07:39:21.083  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-10-19 07:39:21.084  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 915 ms
2021-10-19 07:39:21.157 ERROR 1 --- [           main] c.b.y.controller.YoloServiceController   : file.encoding is utf-8
2021-10-19 07:39:23.449  INFO 1 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
2021-10-19 07:39:23.627  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-10-19 07:39:23.640  INFO 1 --- [           main] c.b.yolodemo.YoloDemoApplication         : Started YoloDemoApplication in 3.893 seconds (JVM running for 4.329)
2021-10-19 07:39:49.872  INFO 1 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-10-19 07:39:49.872  INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-10-19 07:39:49.873  INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms

验证效果

在这里插入图片描述

在这里插入图片描述

2021-10-19 07:39:57.830   : 文件 [person.jpg], 大小 [113880]
2021-10-19 07:39:59.303   : 一共检测到3个目标
2021-10-19 07:39:59.306   : 类别[person],置信度[99.78939%]
2021-10-19 07:39:59.307   : 类别[dog],置信度[99.45358%]
2021-10-19 07:39:59.307   : 类别[horse],置信度[98.37547%]

在这里插入图片描述

标签:10,39,JAVA,07,19,---,2021,YOLO4,极速
来源: https://www.cnblogs.com/bolingcavalry/p/15791011.html