当前位置:网站首页>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
边栏推荐
- 012_ Access denied for user ‘root‘@‘localhost‘ (using password: YES)
- 想用Mac学习sql,主要给自己个充足理由买Mac听听意见
- Modification du contenu de la recherche dans la boîte déroulante par PHP + MySQL
- 工业互联网+危化安全生产综合管理平台怎样建
- Looking for a job, writing a resume to an interview, this set of information is enough!
- IAR embedded development stm32f103c8t6 Lighting LED
- Leetcode cooking
- Halo open source project learning (I): project launch
- 程序设计天梯赛 L1-49 天梯赛分配座位(模拟),布响丸辣
- Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
猜你喜欢

The usage and difference of * and & in C language and the meaning of keywords static and volatile
![[XJTU計算機網絡安全與管理]第二講 密碼技術](/img/b0/263e8dcbfeb2ce9f504a9c8eb76b07.png)
[XJTU計算機網絡安全與管理]第二講 密碼技術

007_ Redis_ Jedis connection pool

重大危险源企业如何保障年底前完成双预防机制数字化建设任务

SQL server2019 cannot download the required files, which may indicate that the version of the installer is no longer supported. What should I do
![[untitled]](/img/60/421cda552055664357af47d1a956af.png)
[untitled]

Deploying sbert model based on torchserve < semantic similarity task >

使用Go语言构建Web服务器

Intelligent agricultural management model

The importance of ERP integration to the improvement of the company's system
随机推荐
PHP sorting of interview questions on April 20, 2022
Global, exclusive and local routing guard
Understanding process (multithreading primary)
Suggestion: block reference sorting is in the order of keywords
PIP install shutil reports an error
So library dependency
hack the box optimum靶机
Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
全局、独享、局部路由守卫
[wechat applet] set the bottom menu (tabbar) for the applet
【无标题】
Class initialization and instance initialization interview questions
能做多大的单片机项目程序开发,就代表了你的敲代码的水平
重大危险源企业如何保障年底前完成双预防机制数字化建设任务
Global, exclusive, local Routing Guard
Leetcode cooking
php+mysql对下拉框搜索的内容修改
想用Mac学习sql,主要给自己个充足理由买Mac听听意见
Web learning record (medium)
Parental delegation model [understanding]