当前位置:网站首页>Actual combat of industrial defect detection project (IV) -- ceramic defect detection based on hrnet
Actual combat of industrial defect detection project (IV) -- ceramic defect detection based on hrnet
2022-04-23 02:41:00 【Summer melts the season】
be based on HRNet Ceramic defect detection
1. principle :
Refer to the articles of the big guys
HRNet: HRNet principle .
2. Data set preparation and code
Data download link :https://aistudio.baidu.com/aistudio/datasetdetail/32615
Code download link :https://gitee.com/wxyfmq123456/HRNet-Image-Classification?_from=gitee_search
3. Binarization of original graph
Here, the data set has provided a binary image png, We need to use png Image training . Because the original image is particularly inconspicuous .
in total 6 Categories .
4. Parameter configuration
(1) Data storage location :
(2) Data storage method :
Each folder represents a type , All the pictures inside are binary pictures (.png), Original picture (.jpg) It can be deleted or backed up elsewhere .
(3) Modify the code
open cls_hrnet.py, modify
self.classifier = nn.Linear(2048, 1000)
by
self.classifier = nn.Linear(2048, 6)
That is, the following parameters are Number of categories .
(4) Select profile
Let's pick the first one , namely :
cls_hrnet_w18_sgd_lr5e-2_wd1e-4_bs32_x100.yaml
Modify the parameters inside , take
DATASET:
DATASET: 'imagenet'
DATA_FORMAT: 'jpg'
ROOT: 'data/imagenet/'
TEST_SET: 'val'
TRAIN_SET: 'train'
It is amended as follows
DATASET:
DATASET: 'data'
DATA_FORMAT: 'png'
ROOT: 'imagenet'
TEST_SET: 'val'
TRAIN_SET: 'train'
The reason is that the path we set is different from the code .
The other parameters , Like the number of iterations epoch,bath_size etc. , You can adjust your parameters .
(5) stay train.py Add the following code to
train_dataset = datasets.ImageFolder(
traindir,
transforms.Compose([
transforms.RandomResizedCrop(config.MODEL.IMAGE_SIZE[0]),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
normalize,
])
)
# The following is the added code , The above lines are the original code
#print(train_dataset.classes) # The category is determined according to the name of the sub folder
with open("class.txt","w") as f1:
for classname in train_dataset.classes:
f1.write(classname + "\n")
#print(train_dataset.class_to_idx) # Define indexes for these categories in order as 0,1...
with open("classToIndex.txt", "w") as f2:
for key, value in train_dataset.class_to_idx.items():
f2.write(str(key) + " " + str(value) + '\n')
#print(train_dataset.imgs) # Returns the path and category of pictures from all folders
You can keep the corresponding index.
5. Training
python tools/train.py --cfg experiments/cls_hrnet_w18_sgd_lr5e-2_wd1e-4_bs32_x100.yaml
After training output In the folder
Weight offset file :final_state.pth.tar
6. test
Pictures of the test , Note that the verification set is still read here vaild, So to test a picture , We can turn the picture of the verification set into a , Put in, for example, a place called test In the folder of , The path is shown in the figure :
stay HRNet-Image-Classification-master\lib\core\function.py Inside def validate function , add to
print('class:{}'.format(output.argmax(1)))
Print the identified category index.
function :
python tools/vaild.py --cfg experiments/cls_hrnet_w18_sgd_lr5e-2_wd1e-4_bs32_x100.yaml
The of the category will be printed index.
版权声明
本文为[Summer melts the season]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220748368408.html
边栏推荐
- SQL server2019无法下载所需文件,这可能表示安装程序的版本不再受支持,怎么办了
- Servlet template engine usage example
- 基于Torchserve部署SBERT模型<语义相似度任务>
- Interim summary (Introduction + application layer + transportation layer)
- IAR嵌入式開發STM32f103c8t6之點亮LED燈
- WordPress calls the specified page content. 2 get_ children()
- Those years can not do math problems, using pyhon only takes 1 minute?
- 期中汇总(概论+应用层+运输层)
- 013_ Analysis of SMS verification code login process based on session
- 电源电路设计原来是这么回事
猜你喜欢
Fashion MNIST 数据集分类训练
The usage and difference of * and & in C language and the meaning of keywords static and volatile
windows MySQL8 zip安装
Global, exclusive, local Routing Guard
能做多大的单片机项目程序开发,就代表了你的敲代码的水平
【无标题】
LeetCode 1450 - 1453
SQL server2019无法下载所需文件,这可能表示安装程序的版本不再受支持,怎么办了
Usage of vector common interface
012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
随机推荐
The 16th day of sprint to the big factory, noip popularization Group Three Kingdoms game
工业互联网+危化安全生产综合管理平台怎样建
SQL server2019无法下载所需文件,这可能表示安装程序的版本不再受支持,怎么办了
谷雨
This is how the power circuit is designed
下载正版Origin Pro 2022 教程 及 如何 激 活
魔王冷饭||#078 魔王答上海、南京行情;沟通指导;得国和打杀筛选;赚钱的目的;改变别人看法
解决 注册谷歌邮箱 gmail 手机号无法用于验证
使用Go语言构建Web服务器
Understanding process (multithreading primary)
006_ redis_ Sortedset type
Push data from onenet cloud platform to database
重大危险源企业如何保障年底前完成双预防机制数字化建设任务
002_ Redis_ Common operation commands of string type
JZ22 链表中倒数最后k个结点
Cuisine leetcode
学习正则表达式选项、断言
First day of rhcsa
Log4j知识点记录
SO库依赖问题