Giter Club home page Giter Club logo

peterh0323 / smart_construction Goto Github PK

View Code? Open in Web Editor NEW
2.1K 26.0 463.0 108.27 MB

Base on YOLOv5 Head Person Helmet Detection on Construction Sites,基于目标检测工地安全帽和禁入危险区域识别系统,🚀😆附 YOLOv5 训练自己的数据集超详细教程🚀😆2021.3新增可视化界面❗❗

License: GNU General Public License v3.0

Python 99.90% Shell 0.10%
yolov5 helmet pytorch python detection object-detection yolo

smart_construction's Introduction

Hi, 👋 I'm HinGwenWoong

📖 路漫漫其修远兮,吾将上下而求索。——《离骚》屈原


PeterH0323's Stats


Something about me

  • 🖋️ 笔名:HinGwenWoong,因为种种原因,Github 一直没改过来 🤣
  • 🔠 信奉的一句话:共同进步!
  • 👷 Hot 作品: 🔥安全帽检测 - Smart_Construction | STM32 HTTPS | 请帮我点星星 🌟
  • 👨‍💻 技术栈:机械结构设计&制造🤖 + 嵌入式软硬件开发⚡ + 云端服务开发☁️ + AI算法开发🎯 + CI/CD🎡
  • 📓 个人技术博客:CSDN
  • 💬 微信 ID:HinGwenWoong

获取的荣誉

  • OpenMMLab 2022 年度贡献之星 🥇 Website
  • OpenMMLab 2022.4 月度贡献之星 🌟
  • OpenMMLab 2022.5 月度贡献之星 🌟
  • PaddleOCR 2W星公庆会活动 贡献者三等奖 🎖

参与贡献的项目


发表论文

  • An integrated underwater structural multi-defects automatic identification and quantification framework for hydraulic tunnel via machine vision and deep learning
    Yangtao Li, Tengfei Bao, Xianjun Huang, Ruijie Wang, Xiaosong Shu, Bo Xu, Jiuzhou Tu, Yuhang Zhou, and Kang Zhang
    Structural Health Monitoring, Sep 2022 ( JCR Q1 / SCI 一区 Top ) [Website]

  • Underwater crack pixel-wise identification and quantification for dams via lightweight semantic segmentation and transfer learning
    Yangtao Li, Tengfei Bao, Xianjun Huang, Hao Chen, Bo Xu, Xiaosong Shu, Yuhang Zhou, Qingbo Cao, Jiuzhou Tu, Ruijie Wang, Kang Zhang
    Automation in Construction, Volume 144, December 2022 ( JCR Q1 / SCI 一区 Top ) [Website]

  • High Precision Cervical Precancerous Lesion Classification Method Based on ConvNeXt
    Jing Tang, Ting Zhang, Zeyu Gong and Xianjun Huang
    Bioengineering, 15 December 2023 ( Q2, IF=4.6 ) [Website]


比赛获奖经历

  • comming soon...

技术栈

Languages and Frameworks

Python PyTorch PaddlePaddle TensorFlow Flask
C++ C Qt OpenCV TensorRT ROS FreeRTOS
HTML CSS Vue.js

Tools

kubernetes Jenkins Git Docker Linux CircleCI
VS Code PyCharm CLion Vim
Keil Altium Designer Autodesk CAD SolidWorks

smart_construction's People

Contributors

peterh0323 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smart_construction's Issues

Some errors:当我pip install -r requirements.txt 后,运行报错

Traceback (most recent call last):
File "visual_interface.py", line 464, in
weight_root = [str(weight_file[0])] # 权重文件位置
IndexError: list index out of range

(pytorch) E:\Smart_Construction-master>python visual_interface.py
QFont::setPointSize: Point size <= 0 (-1), must be greater than 0
QFont::setPointSize: Point size <= 0 (-1), must be greater than 0
qt.qpa.fonts: Unable to open default EUDC font: "EUDC.TTE"
Using CUDA device0 _CudaDeviceProperties(name='GeForce MX230', total_memory=2048MB)

Traceback (most recent call last):
File "visual_interface.py", line 471, in
main_window = MainWindow(weight_root, out_file_root, real_time_show_predict)
File "visual_interface.py", line 268, in init
real_time_show_predict_flag
File "visual_interface.py", line 115, in init
self.predict_model = YOLOPredict(weight_path, out_file_path)
File "E:\Smart_Construction-master\detect_visual.py", line 41, in init
self.model, self.half, self.names, self.colors, self.device = self.load_model()
File "E:\Smart_Construction-master\detect_visual.py", line 59, in load_model
model = attempt_load(weights, map_location=device) # load FP32 model
File "E:\Smart_Construction-master\models\experimental.py", line 133, in attempt_load
model.append(torch.load(w, map_location=map_location)['model'].float().fuse().eval()) # load FP32 model
File "D:\ANACONDA\envs\pytorch\lib\site-packages\torch\serialization.py", line 592, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "D:\ANACONDA\envs\pytorch\lib\site-packages\torch\serialization.py", line 851, in _load
result = unpickler.load()
AttributeError: Can't get attribute 'C3' on <module 'models.common' from 'E:\Smart_Construction-master\models\common.py'>

about start train

hello when i start train ,i get a issue (FileNotFoundError: [Errno 2] No such file or directory: '/home/pytorch/Smart_Construction/score/labels/train.cache'
)
how about train.cache? please help!thanks!!

加载预训练模型出错

您好,我在训练过程中加载预训练模型时,报错:RuntimeError: ./weights/yolov5s.pt is a zip archive (did you mean to use torch.jit.load()? 运行环境是cuda:10.0, pytorch:1.5.1, 请问这是怎么回事呢?

数据集增加分类

你好,能不能再详细点介绍下怎么数据集增加分类,还有您自己的数据集可以提供吗?
谢谢!!

生成person类别问题

你好,我在进行person类别生成时遇到了
torch.nn.modules.module.ModuleAttributeError: 'Conv' object has no attribute '_non_persistent_buffers_set'
也是因为权重版本的问题吗

关于数据集类别的问题

您好,十分感谢您开源的项目代码。请问您是如何在SHWD数据集中添加person的类别标注的,我印象中这个SHWD数据集中只有两类。

重新训练无person检测框的问题

您好,重新训练了您公开的数据集,里面好像仅标注了head和helmat,期初以为按照python train.py --img 640 --batch 16 --epochs 10 --data ./data/custom_data.yaml --cfg ./models/custom_yolov5.yaml --weights ./weights/yolov5s.pt训练,--weights ./weights/yolov5s.pt包括了person的检测。可训练完发现并没有person框,只有head和helmat框。
README.md里面的5. 增加数据集的分类中的说明,是不是就解决person检测问题的,利用原始yolov5生成person标注信息?

true test results about this project

关于本项目训练效果一般问题,这其实是没有正确使用文件:./data/gen_data/merge_data.py,因为在提取人体类别和坐标的时候会生成一次人体标签文件,如果操作多次,会重复生成人体标签文件。另一个原因是若用其它数据库制作人体标签时,是不能和Safety-Helmet-Wearing-Dataset数据库合并的,而是各自数据要单独标签。我迁移训练一轮测试结果:

            Class      Images     Targets           P           R      [email protected]  [email protected]:.95: 100%
             all     3.3e+03    2.07e+04       0.516       0.858       0.815        0.47
          person     3.3e+03    1.08e+04       0.408       0.811       0.729        0.44
            head     3.3e+03    9.18e+03        0.48       0.862       0.814       0.345
          helmet     3.3e+03         747       0.658       0.902       0.902       0.624

这里Safety-Helmet-Wearing-Dataset数据是把train和test合在一起(当然单幅图像标签是独立的),大概数量69k,用val数据(约0.6k)测试。coco train提取的人体标签文件约6万多个,这样共7.1万训练集,验证集共33k,这里需要从生成的标签文件名对应到图像名文件,用作custom_data.yaml,这里建议用yolov5项目训练,https://github.com/ultralytics/yolov5。

所以,作者的测试结果是真实可信的,我没有用custom_yolov5.yaml,只用了yolov5s.yaml,当然也没有./data/gen_anchors/clauculate_anchors.py,聚类得出先验框。

when I run ''python visual_interface.py'',it shows this error,I don't know how to solve it.

(py3.8) E:\Smart_Construction-master>python visual_interface.py
QFont::setPointSize: Point size <= 0 (-1), must be greater than 0
QFont::setPointSize: Point size <= 0 (-1), must be greater than 0
qt.qpa.fonts: Unable to open default EUDC font: "EUDC.TTE"
Using CUDA device0 _CudaDeviceProperties(name='GeForce MX230', total_memory=2048MB)

Traceback (most recent call last):
File "visual_interface.py", line 471, in
main_window = MainWindow(weight_root, out_file_root, real_time_show_predict)
File "visual_interface.py", line 256, in init
self.predict_handler_thread = PredictHandlerThread(self.input_player,
File "visual_interface.py", line 115, in init
self.predict_model = YOLOPredict(weight_path, out_file_path)
File "E:\Smart_Construction-master\detect_visual.py", line 41, in init
self.model, self.half, self.names, self.colors, self.device = self.load_model()
File "E:\Smart_Construction-master\detect_visual.py", line 59, in load_model
model = attempt_load(weights, map_location=device) # load FP32 model
File "E:\Smart_Construction-master\models\experimental.py", line 133, in attempt_load
model.append(torch.load(w, map_location=map_location)['model'].float().fuse().eval()) # load FP32 model
File "D:\ANACONDA\envs\py3.8\lib\site-packages\torch\serialization.py", line 592, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "D:\ANACONDA\envs\py3.8\lib\site-packages\torch\serialization.py", line 851, in _load
result = unpickler.load()
AttributeError: Can't get attribute 'C3' on <module 'models.common' from 'E:\Smart_Construction-master\models\common.py'>

python detect.py 得到错误:Exception: ./weights/yolov5x.pt missing, try downloading from https://drive.google.com/drive/folders/1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J

我不打算自己定义数据集,想直接拿过来用,于是使用代码:python detect.py,我没用过YOLO,所以不知道你后面那些内容到底是干嘛的,实在看不懂你的教程。
--source 0 # webcam file.jpg # image file.mp4 # video path/ # directory path/*.jpg # glob rtsp://170.93.143.139/rtplive/470011e600ef003a004ee33696235daa # rtsp stream http://112.50.243.8/PLTV/88888888/224/3221225900/1.m3u8 # http stream
您能解释一下这个是干啥的么?最好附上一个示例。
结果得到了错误如下:
`(pytorch) PS C:\Users\彭张智computational AI\Desktop\Smart_Construction-master> python detect.py
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='', img_size=640, iou_thres=0.5, output='inference/output', save_txt=False, source='inference/images', update=False, view_img=False, weights='./weights/yolov5x.pt')
Using CUDA device0 _CudaDeviceProperties(name='GeForce GTX 1660 Ti', total_memory=6144MB)

Downloading https://drive.google.com/uc?export=download&id=1mM8aZJlWTxOg7BZJvNUMrTnA2AbeCVzS as ./weights/yolov5x.pt... 系统找不到指定的路径。
Download error
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: 'storage.googleapis.com
Traceback (most recent call last):
File "detect.py", line 161, in
detect()
File "detect.py", line 23, in detect
model = attempt_load(weights, map_location=device) # load FP32 model
File "C:\Users\彭张智computational AI\Desktop\Smart_Construction-master\models\experimental.py", line 132, in attempt_load
google_utils.attempt_download(w)
File "C:\Users\彭张智computational AI\Desktop\Smart_Construction-master\utils\google_utils.py", line 36, in attempt_download
raise Exception(msg)
Exception: ./weights/yolov5x.pt missing, try downloading from https://drive.google.com/drive/folders/1Drs_Aiu7xx6S-ix95f9kNsA6ueKRpN2J`
我尝试去这个链接上自己下载,结果网很慢,翻墙出去也不行...
您有什么好的办法么?
另外,这个教程对我这样的小白不太友好,我实在看不太懂!
最后,感谢您开源的代码,这个模型很有用!谢谢!

python caculate_anchors.py

when i run this,python caculate_anchors.py, the anchors.txt is empty, and the program did not exit automaticly

安全帽颜色检测

小白请问大佬,如果我想对安全帽的颜色进行检测(红、黄、白、蓝),除了要改变classes,网络的结构需要作何改变吗?

`#训练集和验证集的 labels 和 image 文件的位置
train: ./score/images/train
val: ./score/images/val

#number of classes
nc: 6

#class names
names: ['person', 'no_helmet', 'red_helmet', 'yellow_helmet', 'blue_helmet', 'white_helmet']`

pytorch版本问题

您好博主,在进行推理时,使用CPU没问题,使用GPU时会报错,错误如下:
UserWarning: CUDA initialization: The NVIDIA driver on your system is too old (found version 10010). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver. (Triggered internally at /pytorch/c10/cuda/CUDAFunctions.cpp:100.)
return torch._C._cuda_getDeviceCount() > 0
Traceback (most recent call last):
File "area_detect.py", line 170, in
detect()
File "area_detect.py", line 17, in detect
device = torch_utils.select_device(opt.device)
File "/home/rfh/Smart_Construction-master/utils/torch_utils.py", line 30, in select_device
assert torch.cuda.is_available(), 'CUDA unavailable, invalid device %s requested' % device # check availablity
AssertionError: CUDA unavailable, invalid device 2 requested

torch==1.5.1,cuda是10.0版本,想问下是什么问题?是pytorch和cuda版本不匹配吗?

train problem

using yolov5s.pt as initial weights, it occurs error。
could you provide yolov5s.pt with torch-1.5.1 version?
thanks

why was not it successful to head detection?

training one epoch result:

Class Images Targets P R [email protected] [email protected]:.95: 100%
all 3.3e+03 2.07e+04 0.516 0.858 0.815 0.47
person 3.3e+03 1.08e+04 0.408 0.811 0.729 0.44
head 3.3e+03 9.18e+03 0.48 0.862 0.814 0.345
helmet 3.3e+03 747 0.658 0.902 0.902 0.624

but no head and helmet detection, only detecting person.
and head detection is not synchronized with person detection
if relating to anchors calculation or not.

计算anchors

您好。你的说明里面需要自己计算新数据的anchors,但YOLOv5训练代码里面不是有自动计算新anchors的功能吗?训练参数 --noautoanchor ,utils/utils.py 里的 check_anchors 函数,这里应该会重新计算model里的 anchors。
不知道我的理解是否正确,谢谢指教。

Can't download weights

Are there any other ways to download the trained weights for yolov5l? I cant seem to download from baidu cloud without an account. Thank you!

完全背景数据的问题

请问,如果我的数据图片里有一些(完全无标注的)背景图,那我的label应该设置成什么样子呢?谢谢作者!

运行出错!

你好,运行detect.py 出现这个错误
'Detect' object has no attribute 'm'
怎么处理?

加载预训练模型出错

您好,我在训练过程中加载预训练模型时,报错:RuntimeError: ./weights/yolov5s.pt is a zip archive (did you mean to use torch.jit.load()? 运行环境是cuda:10.0, pytorch:1.5.1, 请问这是怎么回事呢?

python detect.py --save-txt --source ./自己数据集的文件目录 --weights ./weights/yolov5x.pt

C:\Users\10783\PycharmProjects\pythonProject\Smart_Construction-master>python detect.py --save-txt --source ./C:/Users/10783\PycharmProjects/pythonProject/Smart_Construction-master
/VOC2028/JPEGImages/ --weights ./weights/yolov5x.pt
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='', img_size=640, iou_thres=0.5, output='inference/output', save_txt=True, source='./C:/Users/10783\Pych
armProjects/pythonProject/Smart_Construction-master/VOC2028/JPEGImages/', update=False, view_img=False, weights=['./weights/yolov5x.pt'])
Using CUDA device0 _CudaDeviceProperties(name='GeForce GTX 1650', total_memory=4096MB)

C:\Users\10783\Anaconda3\lib\site-packages\torch\serialization.py:657: SourceChangeWarning: source code of class 'models.yolo.Model' has changed. you can retrieve the original source code
by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
C:\Users\10783\Anaconda3\lib\site-packages\torch\serialization.py:657: SourceChangeWarning: source code of class 'models.yolo.Detect' has changed. you can retrieve the original source cod
e by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
Fusing layers... Model Summary: 284 layers, 8.89222e+07 parameters, 8.89222e+07 gradients
Traceback (most recent call last):
File "detect.py", line 161, in
detect()
File "detect.py", line 52, in detect
_ = model(img.half() if half else img) if device.type != 'cpu' else None # run once
File "C:\Users\10783\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "C:\Users\10783\PycharmProjects\pythonProject\Smart_Construction-master\models\yolo.py", line 99, in forward
return self.forward_once(x, profile) # single-scale inference, train
File "C:\Users\10783\PycharmProjects\pythonProject\Smart_Construction-master\models\yolo.py", line 119, in forward_once
x = m(x) # run
File "C:\Users\10783\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "C:\Users\10783\PycharmProjects\pythonProject\Smart_Construction-master\models\yolo.py", line 27, in forward
x[i] = self.mi # conv
File "C:\Users\10783\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 593, in getattr
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'Detect' object has no attribute 'm'

你好,在pytorch1.5下 又遇到了这个问题 权重用的也是你v2.0的权重,这又是什么问题谢谢!

关于危险区域判断的问题

大佬好呀,

大概读了一遍代码,想确认一下我的理解是否正确。危险区域判断的方法是不是首先需要人工村注得到图片上的多边形的危险区域,然后看人的检测bbox的中心是否在危险区域多边形里面,如果在的话就认为人是处在危险区域了,也就是说危险区域不是使用算法得到的,是在每张图片上面预先定义好的?

数据集

请问可以分享一下数据集吗

文档小错误

安装环境那块应该是pip install -r requirements.txt,requirement少了一个s

训练的精度不正常

你好,感谢你的开源!
我在按照你的文件配置之后,对你提供的安全帽进行训练,发现训练不正常。希望你能帮助我解决一下这个问题
image

安全帽颜色检测

小白请问大佬,如果我想对安全帽的颜色进行检测(红、黄、白、蓝),除了要改变classes,网络的结构需要作何改变吗?

训练集和验证集的 labels 和 image 文件的位置

train: ./score/images/train
val: ./score/images/val

number of classes

nc: 6

class names

names: ['person', 'no_helmet', 'red_helmet', 'yellow_helmet', 'blue_helmet', 'white_helmet']

问一下大佬,数据集分类的问题

原始的数据集只有people和hat两个分类,我看readme文件里面的custom_data.yaml的里面分类是三个分类,还有测试的图片也是三个分类,不知道大佬数据集这块是加入了自己标注的还是其他怎么处理的,希望解答一下,万分感谢!

onnx export can work

python ./models/export.py --weights ./weights/helmet_head_person_s.pt --img 640 --batch 1

File "demo_onnx.py", line 301, in
detections = detect_onnx(official=False, image_path=image_path)
File "demo_onnx.py", line 180, in detect_onnx
session = onnxruntime.InferenceSession('./weights/helmet_head_person_s.onnx')
File "C:\Users\vision\Anaconda3\envs\pt_gpu\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 283, in init
self._create_inference_session(providers, provider_options, disabled_optimizers)
File "C:\Users\vision\Anaconda3\envs\pt_gpu\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 310, in _create_inference_session
sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from ./weights/helmet_head_person_s.onnx failed:Node (Mul_882) Op (Mul) [ShapeInferenceError] Incompatible dimensions

when use the yolov5s.pt, it can work.
python ./models/export.py --weights ./weights/yolov5s.pt --img 640 --batch 1
tested by below
demo_onnx.zip

When use the official model, set the official True
detections = detect_onnx(official=True, image_path=image_path)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.