代码拉取完成,页面将自动刷新
使用 torch>=1.8.0,python>=3.7
git clone https://gitee.com/XiongfeiBai/jx_pic_classification.git
1.数据集:焊缝金相组织数据集(也可使用自制数据集)
将数据集划分为train_data和test_data以此放入相应的文件夹中
2.训练过程:直接运行train.py,相应的超参数在train.py的main函数中进行修改即可
data_path = "train_data" # 训练数据集存放的位置
batch_size = 32
learning_rate = 0.001 #初始学习率
epochs = 100 训练轮数
k = 5 # to set the ratio ==>train dataset/val dataset=(k-1)/1
num_class = 3 # 缺陷种类数
label_smooth = False # 是否使用labelsmoothing
lr_scheduler = True # 是否使用动态学习率
训练过程:
Train: 100%|████████████████████████████████████████████████████| 64.0/64.0 [00:39<00:00, 1.61img/s]
Train [epoch:6, iter:384] [total] : Loss: 0.6198 | Acc: 0.7100 | Precision: 0.3619 | Recall: 0.3606 | F1_score: 0.3464
Train [epoch:6, iter:384] [hole] : Loss: 0.6198 | Acc: 0.7100 | Precision: 0.6521 | Recall: 0.5785 | F1_score: 0.5757
Train [epoch:6, iter:384] [crack] : Loss: 0.6198 | Acc: 0.7100 | Precision: 0.6561 | Recall: 0.6655 | F1_score: 0.6202
Train [epoch:6, iter:384] [normal] : Loss: 0.6198 | Acc: 0.7100 | Precision: 0.8633 | Recall: 0.9195 | F1_score: 0.8823
Val: 100%|██████████████████████████████████████████████████████| 16.0/16.0 [00:06<00:00, 2.55img/s]
Val [epoch:6, iter:336] [total] : Loss: 1.1346 | Acc: 0.5176 | Precision: 0.5879 | Recall: 0.4979 | F1_score: 0.4625
Val [epoch:6, iter:336] [hole] : Loss: 1.1346 | Acc: 0.5176 | Precision: 0.4793 | Recall: 0.3387 | F1_score: 0.3875
Val [epoch:6, iter:336] [crack] : Loss: 1.1346 | Acc: 0.5176 | Precision: 0.7938 | Recall: 0.2525 | F1_score: 0.3689
Val [epoch:6, iter:336] [normal] : Loss: 1.1346 | Acc: 0.5176 | Precision: 0.4906 | Recall: 0.9024 | F1_score: 0.6311
3.测试过程:运行predict.py,运行之前需要修改的参数为:
path="test_data"
packpath="checkpoint_path"#存放模型文件的文件夹路径
batch_size=32
num_class=3 #待分类图片的类别数
count=10 #预测次数,最终的预测精度取count次预测的精度的平均值
测试过程:
############# loading model : result/2700+/train_data+LR\ResNet18+ELR\ResNet18_val0.9593.pt ###########
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:02<00:00, 2.68img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:02<00:00, 2.68img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:02<00:00, 2.70img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:02<00:00, 2.69img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:02<00:00, 2.68img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:02<00:00, 2.69img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:02<00:00, 2.68img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.57img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:02<00:00, 2.71img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.62img/s]
acc:0.954688 hole:0.949795 crack:0.935920 normal:0.967683 total:0.951133
Testing ResNet18_PRO+ELR model , please waiting.....
############# loading model : result/2700+/train_data+LR\ResNet18_PRO+ELR\ResNet18_PRO_val0.9901.pt ###########
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.62img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.57img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.63img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.56img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.56img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.52img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.55img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.42img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.47img/s]
Val: 100%|██████████████████████████████████████████████████████| 8.00/8.00 [00:03<00:00, 2.53img/s]
acc:0.978125 hole:0.975934 crack:0.972866 normal:0.979740 total:0.976180
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。