本文主要是介绍2023/8/2 复现一个“基于Paddleclas完成半导体晶圆图谱缺陷种类识别”的项目(自己学习记录版),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
数据集下载:半导体晶圆缺陷图谱 - 飞桨AI Studio
环境配置:开始使用_飞桨-源于产业实践的开源深度学习平台
用git 下载paddleclas:
https://gitee.com/paddlepaddle/PaddleClas
1.开发环境准备:
1.1 在anaconda prompt中创造python 3.9.13
conda create -n PD python==3.9.13
1.2 CUDA10.2下载以及补丁使用
安装教程参考博客:Win10安装CUDA 10.2_菜鸟学飞ing去看世界的博客-CSDN博客
CUDA官网下载地址:CUDA Toolkit Archive | NVIDIA Developer
10.2下载地址:CUDA Toolkit 10.2 Download | NVIDIA Developer
安装补丁1(发布于2020年8月26日,选装)
此修补程序解决了CUDA 10.2中捆绑的cuBLAS库中的一个问题,该问题在罕见的极端情况下导致数据无提示损坏。
补丁2(发布于2020年11月17日,选装)
此修补程序解决了cuBLAS库批处理的GEMM APIs中的一个问题,该问题在混合精度和快速数学的大批量计数的罕见情况下,导致数据无提示损坏。
(我都安装了)
安装补丁过程中的注意事项:
参考博客Win10安装CUDA 10.2_菜鸟学飞ing去看世界的博客-CSDN博客
1.如果本机已经有了Visual Studio Integration
文件,要取消勾选,避免冲突了。
2.取消勾选NVIDIA GeForce Experience
3.点开Driver components
,Display Driver
这一行,前面显示的是CUDA新驱动版本。
- 如果本机当前驱动版本大于(新于) 新版本,要取消勾选。
- 如果本机当前驱动版本小于(旧于) 新版本,并且没有勾选,电脑可能会蓝屏或死机。
- 两个版本相同的话,可以勾选。
2.Windows 下的 Conda 安装
2.2.1 确认 Python 安装路径
确认您的 conda 虚拟环境和需要安装 PaddlePaddle 的 Python 是您预期的位置,因为您计算机可能有多个 Python。进入 Anaconda 的命令行终端,输入以下指令确认 Python 位置。
输出 Python 路径的命令为:
where python
根据您的环境,您可能需要将说明中所有命令行中的 python 替换为具体的 Python 路径
2.2.2 确认 Python 安装路径和检查系统环境
确认版本
python --version
检查系统环境
python -c "import platform;print(platform.architecture()[0]);print(platform.machine())"
2.2.3 安装GPU 版的 PaddlePaddle
PaddlePaddle官方安装指南:开始使用_飞桨-源于产业实践的开源深度学习平台
对于 CUDA 10.2
,需要搭配 cuDNN 7.6.5,安装命令为:
conda install paddlepaddle-gpu==2.5.1 cudatoolkit=11.2 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/ -c conda-forge
2.2.4 安装相应的依赖
转路径,安装requirements.txt
(PaddleClas_GPU) C:\Users\61714>d:(PaddleClas_GPU) D:\>cd D:\12C301\PaddleClas(PaddleClas_GPU) D:\12C301\PaddleClas>pip install --upgrade -r requirements.txt -i https://mirror.baidu.com/pypi/simple
查看paddle版本
python -c "import paddle; print(paddle.__version__)"
2.5.1
3.使用Resnet50模型进行训练
用paddleclas开发套件,将对应模型的yaml文件按照自己的项目配置进行更改即可。主要是要指定数据集的位置以及相应的优化器配置。
Resnet50模型的config文件位置为:PaddleClas/ppcls/configs/ImageNet/ResNet/ResNet50.yaml
参数配置:
- epochs:200(所有的数据走一遍前向计算和反向梯度更新为一个epoch)
- learning rate: 0.01
- learning rate schduler: PiecewiseDecay
- batch_size:20
一些路径的设置
image_root: D:/12C301/PaddleClas/dataset/waferMap/img #这里改成绝对路径,指定了数据集的路径cls_label_path: D:/12C301/PaddleClas/dataset/waferMap/train.txt #类标签信息储存位置cls_label_path: D:/12C301/PaddleClas/dataset/waferMap/val.txtinfer_dir: D:/12C301/PaddleClas/dataset/waferMap/testclass_id_map_file: D:/12C301/PaddleClas/dataset/waferMap/label_list.txt
其中遇到问题参考的博客:
win10安装cuda10.2和对应的cudnn版本_cuda10.2对应的cudnn_精分天秤座的mystery的博客-CSDN博客
利用Anaconda安装pytorch和paddle深度学习环境+pycharm安装---免额外安装CUDA和cudnn(适合小白的保姆级教学)_yolov5是算法还是框架_炮哥带你学的博客-CSDN博客
史上最详细yolov5环境配置搭建+配置所需文件_想到好名再改的博客-CSDN博客
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence_unicodedecodeerror: 'gbk' codec can't decode byte _落花雨12138的博客-CSDN博客UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xa7 in position 265: illegal multibyte sequence_落花雨12138的博客-CSDN博客yaml 文本报错 UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte : illegal multibyte sequence_liujingqiu的博客-CSDN博客
记录yolov5出现UnicodeDecodeError中gbk解码问题的解决_Mr.zwX的博客-CSDN博客
最重要的其中一个change Tensor.numpy()[0] to float(Tensor). by ShawnNew · Pull Request #2891 · PaddlePaddle/PaddleClas · GitHub
3.1 Resnet50模型训练完成
3.2训练日志生成位置
这个vdl是可视化文件
3.2.1 在conda 创建的虚拟环境下,使用pip 安装
pip install --upgrade visualdl
3.2.2 在anaconda prompt 中运行
进入paddle环境,
命令行输入visualdl --logdir ./vdl_log_dir/scalar_1 --port 8080
./vdl_log_dir/scalar_1 --port 8080(改为自己的vdl文件路径)
(PD) C:\Users\61714>visualdl --logdir D:\12C301\PaddleClas\tools\output\vdl
复制网址打开
内容如下:
后续会继续更新
--------------------------------2023/8/9更新----------------------------------
在未更新的时间里面想进行评估模型,发现不断报一个错误ModuleNotFoundError: No module named ‘paddle‘,在网络上尝试了许多办法都无法解决,所以重新搭建了一个新的虚拟环境(PD),再次运行评估模型就没有出现报错了。
其中还遇到了ModuleNotFoundError: No module named ‘tqdm‘,参考办法【解决错误】ModuleNotFoundError: No module named ‘tqdm‘_modulenotfounderror: no module named 'tqdm_浮云就是一切的博客-CSDN博客
4.评估模型
用eval.py来评估模型
第一步: cd 到 PaddleClas 所在路径
例:(PD) D:\12C301\PaddleClas>
第二步:
python tools/eval.py
-c /home/aistudio/PaddleClas/ppcls/configs/ImageNet/ResNet/ResNet50.yaml
-o Global.pretrained_model=/home/aistudio/PaddleClas/output/ResNet50/best_model
其中:
/home/aistudio/PaddleClas/ppcls/configs/ImageNet/ResNet(改成自己ResNet50模型的路径)
/home/aistudio/PaddleClas/output/ResNet50/best_model(改成自己的路径)
4.1 评估模型中出现的警告
在评估模型的时候出现报错,ModuleNotFoundError: No module named ‘paddle‘,在网络上找了很多办法都无法解决,于是重新创建一个新的环境,再次评估模型,出现了新的警告
具体是:
“Warning:: 0D Tensor cannot be used as 'Tensor.numpy()[0]' . In order to avoid this problem, 0D Tensor will be changed to 1D numpy c urrently, but it's not correct and will be removed in release 2.6. For Tensor contain only one element, Please modify 'Tensor.numpy()[0]' to 'float(Tensor)' as soon as possible, o therwise 'Tensor.numpy()[0]' will raise error in release 2.6.”
解决方法:参考博客:[PaddlePaddle] [学习笔记] [上] 手写数字识别(Warning:: 0D Tensor cannot be used as ‘Tensor.num、全流程、softmax、问题)_Le0v1n的博客-CSDN博客
4.2 评估模型后的数据:
[2023/08/09 11:40:04] ppcls INFO: [Eval][Epoch 0][Avg]CELoss: 0.37495, loss: 0.37495, top1: 0.91818, top5: 1.00000
根据提供的日志信息,这是一个模型评估的结果。以下是对该日志的解读:
- 时间戳:2023年8月9日上午11:40:04。
- 模型评估指标:
- 平均交叉熵损失(CELoss):0.37495。
- Loss:0.37495。
- Top-1准确率:0.91818(即分类正确的样本占总样本数的比例)。
- Top-5准确率:1.00000(即在预测的前五个类别中包含了正确的类别)。
这些指标用于衡量模型对数据集进行分类任务时的性能表现。其中,交叉熵损失越低表示模型的预测结果与真实标签越接近;准确率越高表示模型的分类能力越强。
根据提供的日志信息,该模型在评估阶段取得了较好的性能,平均交叉熵损失较低,并且在Top-1和Top-5准确率上都取得了较高的分数。
- 注意,模型评估时模型在验证集上的测试结果,通过对比模型的预测值和图片的真实标签计算模型的精度等指标
- 模型评估主要用于判断训练完成后的模型精度等指标是否满足部署要求,主要关注Loss,TopK精度以及速度ips等指标
5. 模型预测
完成评估后,可以使用tools/infer.py脚本进行单张图片或者多张图片批量预测。 在预测脚本中传入使用的模型和测试的图片路径即可。
5.1 具体命令:
第一步: cd 到具体文件路径
第二步:使用Python的PaddleClas工具中的infer.py脚本进行推理。
python tools/infer.py -c D:/12C301/PaddleClas/ppcls/configs/ImageNet/ResNet/ResNet50.yaml -o Global.pretrained_model=D:/12C301/PaddleClas/tools/output/R
esNet50/best_model-o Infer.infer_imgs=D:/12C301/PaddleClas/dataset/waferMap/test/Center_85238.jpg
传递的参数包括:
配置文件路径(-c)
预训练模型路径(-o Global.pretrained_model)
待推理的图像路径(-o Infer.infer_imgs)。
配置文件的路径为D:/12C301/PaddleClas/ppcls/configs/ImageNet/ResNet/ResNet50.yaml
预训练模型的路径为D:/12C301/PaddleClas/tools/output/ResNet50/best_model
待推理的图像路径为D:/12C301/PaddleClas/dataset/waferMap/test/Center_85238.jpg
预测结果如图:# 单张图片
[{'class_ids': [4, 0, 1, 2, 5], 'scores': [0.63691, 0.34245, 0.02052, 0.00012, 1e-05],
'file_name': 'D:/12C301/PaddleClas/dataset/waferMap/test/Center_85238.jpg',
'label_names': ['Loc', 'Center', 'Donut', 'Edge-Loc', 'Random']}]
根据推理结果,具体的解释如下:
- 预测结果显示该图像的类别标签索引为4、0、1、2和5,对应的类别标签名称分别为'Loc', 'Center', 'Donut', 'Edge-Loc', 'Random'。
- 根据置信度(scores),可以看出模型对于'LOC'类别的预测置信度最高(0.63691),其次是'Center'类别(0.34245),接下来分别是'Donut'类别(0.02052)、'Edge-Loc'类别(0.00012)和'Random'类别(1e-05)。
tips:
根据图片和缺陷的名称,可以大概了解每种缺陷的分类方法,例如:
-
0. Center: 表示芯片表面有中心型的缺陷。既大部分缺陷的芯粒位于晶圆圆心附近
1. Donut: 表示芯片表面有圆环型的缺陷。既缺陷的芯粒空间分布类似于一个甜甜圈
2. Edge-Loc: 表示芯片边缘区域有缺陷。
3. Edge-Ring: 表示芯片边缘环绕区域有缺陷。
4. Loc: 表示芯片表面有局部缺陷。既局部出现缺陷芯粒聚集
5. Random: 表示芯片表面有随机分布的缺陷。
6. Scratch: 表示芯片表面有划痕型的缺陷。
7. Near-full: 表示芯片表面有近乎全覆盖的缺陷。 -
PS:这个图片找到好辛苦:(
这些类别标签用于描述芯片表面的不同缺陷类型。在图像推理任务中,模型会预测图像属于哪种缺陷类型,并给出相应的置信度。
- 推理的图像文件路径为'D:/12C301/PaddleClas/dataset/waferMap/test/Center_85238.jpg'。
综上所述,模型预测该图像最有可能属于'LOC'类别,并且置信度较高。同时,还预测了其他几个类别的可能性,但置信度较低。
6. 模型导出部署
paddlepaddle支持导出 inference 模型用于部署推理场景,相比于训练调优场景,inference 模型会将网络权重与网络结构进行持久化存储,并且 PaddlePaddle 支持使用预测引擎加载 inference 模型进行预测推理。
在paddleclas套件中通过tools/export_model.py导出模型。导出后,将生成以下三个文件:
- inference.pdmodel:用于存储网络结构信息;
- inference.pdiparams:用于存储网络权重信息;
- inference.pdiparams.info:用于存储模型的参数信息,在分类模型和识别模型中可忽略.
6.1 导出ResNet50模型
具体命令:
1. cd 到 PaddleClas 所在的具体路径
2. 使用Python运行`export_model.py`脚本,执行模型的导出操作。
python tools/export_model.py
-c D:/12C301/PaddleClas/ppcls/configs/ImageNet/ResNet/ResNet50.yaml
-o Global.pretrained_model=D:/12C301/PaddleClas/tools/output/ResNet50/best_model
-o Global.save_inference_dir=D:/12C301/PaddleClas/deploy/models/ResNet50
通过运行这段代码,你可以导出已经训练好的ResNet50模型,并把它保存在指定的路径中,以便后续使用该模型进行推理任务。
运行成功如图:
显示模型已经成功导出,并告知了导出的模型文件保存的路径。
7.推理
- 使用导出的模型
- 脚本位于deploy/python.predict_cls.py
- 修改配置文件
7.1 使用ResNet50模型
第一步:cd 到deploy的路径
第二步: 使用Python运行`predict_cls.py`脚本,执行模型的导出操作。
7.1.1 出现报错
7.1.2 解决办法:安装了paddleclas
pip install paddleclas
7.1.3 接着就出现了新的报错
具体错误:ImportError: DLL load failed while importing _swigfaiss: 找不到指定的模块。
7.1.3.1 解决办法:参考博客windows安装Faiss,swigfaiss: 找不到指定的模块_importerror: dll load failed while importing _swig_AlanLiu6的博客-CSDN博客
1、卸载所有已安装的包.
pip uninstall faiss-cpu
conda uninstall faiss
windows安装Faiss,swigfaiss: 找不到指定的模块_importerror: dll load failed while importing _swig_AlanLiu6的博客-CSDN博客
2.更换anaconda国内源【没更换源时,使用第3步的命令,会报错,在我尝试更改后,解决问题】
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
3. 在conda中添加这个源,再去安装faiss
conda install faiss-cpu -c pytorch
问题就解决了
7.2 使用ResNet50模型识别缺陷
命令:
1. 转到 \PaddleClas\deploy 路径
2. python python/predict_cls.py -c configs/inference_cls.yaml
成功运行
- Center_119628.jpg: class id(s): [0, 6, 4, 2, 1], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Center', 'Scratch', 'Loc', 'Edge-Loc', 'Donut']
- Center_119714.jpg: class id(s): [0, 4, 2, 6, 1], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Center', 'Loc', 'Edge-Loc', 'Scratch', 'Donut']
- Center_187048.jpg: class id(s): [0, 2, 6, 4, 3], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Center', 'Edge-Loc', 'Scratch', 'Loc', 'Edge-Ring']
- Center_190340.jpg: class id(s): [0, 1, 4, 2, 6], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Center', 'Donut', 'Loc', 'Edge-Loc', 'Scratch']
- Center_202124.jpg: class id(s): [0, 1, 4, 2, 5], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Center', 'Donut', 'Loc', 'Edge-Loc', 'Random']
- Center_49.jpg: class id(s): [0, 4, 2, 6, 3], score(s): [0.99, 0.01, 0.00, 0.00, 0.00], label_name(s): ['Center', 'Loc', 'Edge-Loc', 'Scratch', 'Edge-Ring']
- Center_7290.jpg: class id(s): [0, 4, 1, 2, 6], score(s): [0.97, 0.02, 0.01, 0.00, 0.00], label_name(s): ['Center', 'Loc', 'Donut', 'Edge-Loc', 'Scratch']
- Center_83419.jpg: class id(s): [0, 4, 2, 5, 1], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Center', 'Loc', 'Edge-Loc', 'Random', 'Donut']
- Center_85238.jpg: class id(s): [4, 0, 1, 2, 5], score(s): [0.64, 0.34, 0.02, 0.00, 0.00], label_name(s): ['Loc', 'Center', 'Donut', 'Edge-Loc', 'Random']
- Center_96002.jpg: class id(s): [0, 4, 2, 1, 6], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Center', 'Loc', 'Edge-Loc', 'Donut', 'Scratch']
- Donut_116252.jpg: class id(s): [1, 4, 6, 2, 0], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Donut', 'Loc', 'Scratch', 'Edge-Loc', 'Center']
- Donut_244230.jpg: class id(s): [1, 4, 2, 5, 6], score(s): [0.92, 0.08, 0.00, 0.00, 0.00], label_name(s): ['Donut', 'Loc', 'Edge-Loc', 'Random', 'Scratch']
- Donut_278979.jpg: class id(s): [1, 4, 6, 2, 5], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Donut', 'Loc', 'Scratch', 'Edge-Loc', 'Random']
- Donut_279135.jpg: class id(s): [1, 4, 2, 6, 0], score(s): [0.89, 0.11, 0.00, 0.00, 0.00], label_name(s): ['Donut', 'Loc', 'Edge-Loc', 'Scratch', 'Center']
- Donut_279770.jpg: class id(s): [1, 5, 6, 4, 2], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Donut', 'Random', 'Scratch', 'Loc', 'Edge-Loc']
- Donut_279845.jpg: class id(s): [1, 4, 5, 6, 2], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Donut', 'Loc', 'Random', 'Scratch', 'Edge-Loc']
- Donut_680504.jpg: class id(s): [1, 5, 2, 4, 6], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Donut', 'Random', 'Edge-Loc', 'Loc', 'Scratch']
- Donut_683294.jpg: class id(s): [1, 4, 5, 2, 0], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Donut', 'Loc', 'Random', 'Edge-Loc', 'Center']
- Donut_7334.jpg: class id(s): [1, 5, 4, 2, 7], score(s): [0.85, 0.15, 0.00, 0.00, 0.00], label_name(s): ['Donut', 'Random', 'Loc', 'Edge-Loc', 'Near-full']
- Donut_7936.jpg: class id(s): [1, 4, 6, 2, 3], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Donut', 'Loc', 'Scratch', 'Edge-Loc', 'Edge-Ring']
- Edge-Loc_24967.jpg: class id(s): [2, 3, 4, 6, 0], score(s): [0.99, 0.01, 0.00, 0.00, 0.00], label_name(s): ['Edge-Loc', 'Edge-Ring', 'Loc', 'Scratch', 'Center']
- Edge-Loc_29429.jpg: class id(s): [2, 4, 3, 6, 5], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Edge-Loc', 'Loc', 'Edge-Ring', 'Scratch', 'Random']
- Edge-Loc_36.jpg: class id(s): [2, 6, 4, 0, 5], score(s): [0.76, 0.16, 0.08, 0.00, 0.00], label_name(s): ['Edge-Loc', 'Scratch', 'Loc', 'Center', 'Random']
- Edge-Loc_41932.jpg: class id(s): [2, 4, 6, 1, 0], score(s): [0.92, 0.06, 0.02, 0.00, 0.00], label_name(s): ['Edge-Loc', 'Loc', 'Scratch', 'Donut', 'Center']
- Edge-Loc_45091.jpg: class id(s): [2, 3, 4, 6, 5], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Edge-Loc', 'Edge-Ring', 'Loc', 'Scratch', 'Random']
- Edge-Loc_48272.jpg: class id(s): [6, 4, 2, 0, 5], score(s): [0.48, 0.41, 0.06, 0.05, 0.00], label_name(s): ['Scratch', 'Loc', 'Edge-Loc', 'Center', 'Random']
- Edge-Loc_54178.jpg: class id(s): [2, 3, 4, 5, 1], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Edge-Loc', 'Edge-Ring', 'Loc', 'Random', 'Donut']
- Edge-Loc_58508.jpg: class id(s): [3, 2, 6, 4, 5], score(s): [0.81, 0.19, 0.00, 0.00, 0.00], label_name(s): ['Edge-Ring', 'Edge-Loc', 'Scratch', 'Loc', 'Random']
- Edge-Loc_7369.jpg: class id(s): [2, 4, 0, 6, 1], score(s): [0.97, 0.03, 0.00, 0.00, 0.00], label_name(s): ['Edge-Loc', 'Loc', 'Center', 'Scratch', 'Donut']
- Edge-Loc_7413.jpg: class id(s): [4, 2, 0, 6, 5], score(s): [0.79, 0.18, 0.03, 0.00, 0.00], label_name(s): ['Loc', 'Edge-Loc', 'Center', 'Scratch', 'Random']
- Edge-Ring_12619.jpg: class id(s): [3, 6, 5, 4, 2], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Edge-Ring', 'Scratch', 'Random', 'Loc', 'Edge-Loc']
- Edge-Ring_12668.jpg: class id(s): [3, 6, 5, 2, 1], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Edge-Ring', 'Scratch', 'Random', 'Edge-Loc', 'Donut']
- Edge-Ring_12709.jpg: class id(s): [3, 5, 2, 6, 4], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Edge-Ring', 'Random', 'Edge-Loc', 'Scratch', 'Loc']
- Edge-Ring_12712.jpg: class id(s): [3, 6, 2, 1, 4], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Edge-Ring', 'Scratch', 'Edge-Loc', 'Donut', 'Loc']
- Edge-Ring_12713.jpg: class id(s): [3, 1, 2, 6, 4], score(s): [0.99, 0.01, 0.00, 0.00, 0.00], label_name(s): ['Edge-Ring', 'Donut', 'Edge-Loc', 'Scratch', 'Loc']
- Edge-Ring_14164.jpg: class id(s): [3, 5, 2, 6, 4], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Edge-Ring', 'Random', 'Edge-Loc', 'Scratch', 'Loc']
- Edge-Ring_20649.jpg: class id(s): [3, 2, 4, 5, 6], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Edge-Ring', 'Edge-Loc', 'Loc', 'Random', 'Scratch']
- Edge-Ring_20826.jpg: class id(s): [3, 2, 4, 6, 5], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Edge-Ring', 'Edge-Loc', 'Loc', 'Scratch', 'Random']
- Edge-Ring_20829.jpg: class id(s): [3, 2, 4, 5, 6], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Edge-Ring', 'Edge-Loc', 'Loc', 'Random', 'Scratch']
- Edge-Ring_8409.jpg: class id(s): [3, 2, 4, 5, 1], score(s): [0.98, 0.02, 0.00, 0.00, 0.00], label_name(s): ['Edge-Ring', 'Edge-Loc', 'Loc', 'Random', 'Donut']
- Loc_107555.jpg: class id(s): [4, 2, 3, 5, 1], score(s): [0.98, 0.02, 0.00, 0.00, 0.00], label_name(s): ['Loc', 'Edge-Loc', 'Edge-Ring', 'Random', 'Donut']
- Loc_107665.jpg: class id(s): [4, 0, 2, 6, 1], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Loc', 'Center', 'Edge-Loc', 'Scratch', 'Donut']
- Loc_37961.jpg: class id(s): [4, 2, 0, 6, 5], score(s): [0.98, 0.01, 0.01, 0.00, 0.00], label_name(s): ['Loc', 'Edge-Loc', 'Center', 'Scratch', 'Random']
- Loc_40.jpg: class id(s): [4, 0, 2, 1, 5], score(s): [0.87, 0.08, 0.05, 0.00, 0.00], label_name(s): ['Loc', 'Center', 'Edge-Loc', 'Donut', 'Random']
- Loc_40462.jpg: class id(s): [4, 0, 2, 6, 1], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Loc', 'Center', 'Edge-Loc', 'Scratch', 'Donut']
- Loc_66389.jpg: class id(s): [6, 4, 1, 2, 0], score(s): [0.86, 0.08, 0.06, 0.00, 0.00], label_name(s): ['Scratch', 'Loc', 'Donut', 'Edge-Loc', 'Center']
- Loc_66672.jpg: class id(s): [4, 2, 0, 1, 5], score(s): [0.97, 0.02, 0.00, 0.00, 0.00], label_name(s): ['Loc', 'Edge-Loc', 'Center', 'Donut', 'Random']
- Loc_87260.jpg: class id(s): [4, 1, 2, 0, 6], score(s): [0.98, 0.01, 0.00, 0.00, 0.00], label_name(s): ['Loc', 'Donut', 'Edge-Loc', 'Center', 'Scratch']
- Loc_87266.jpg: class id(s): [4, 1, 2, 0, 5], score(s): [0.88, 0.11, 0.00, 0.00, 0.00], label_name(s): ['Loc', 'Donut', 'Edge-Loc', 'Center', 'Random']
- Loc_94941.jpg: class id(s): [4, 2, 0, 1, 6], score(s): [0.52, 0.39, 0.09, 0.01, 0.00], label_name(s): ['Loc', 'Edge-Loc', 'Center', 'Donut', 'Scratch']
- Near-full_250273.jpg: class id(s): [7, 2, 5, 4, 3], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Near-full', 'Edge-Loc', 'Random', 'Loc', 'Edge-Ring']
- Near-full_714300.jpg: class id(s): [7, 5, 2, 4, 1], score(s): [0.76, 0.24, 0.00, 0.00, 0.00], label_name(s): ['Near-full', 'Random', 'Edge-Loc', 'Loc', 'Donut']
- Near-full_733946.jpg: class id(s): [7, 2, 5, 3, 4], score(s): [0.99, 0.01, 0.00, 0.00, 0.00], label_name(s): ['Near-full', 'Edge-Loc', 'Random', 'Edge-Ring', 'Loc']
- Near-full_762971.jpg: class id(s): [7, 2, 5, 1, 4], score(s): [0.93, 0.04, 0.03, 0.00, 0.00], label_name(s): ['Near-full', 'Edge-Loc', 'Random', 'Donut', 'Loc']
- Near-full_809157.jpg: class id(s): [7, 2, 5, 4, 3], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Near-full', 'Edge-Loc', 'Random', 'Loc', 'Edge-Ring']
- Random_178268.jpg: class id(s): [5, 1, 3, 2, 0], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Random', 'Donut', 'Edge-Ring', 'Edge-Loc', 'Center']
- Random_19120.jpg: class id(s): [5, 7, 2, 1, 4], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Random', 'Near-full', 'Edge-Loc', 'Donut', 'Loc']
- Random_19201.jpg: class id(s): [5, 2, 0, 1, 7], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Random', 'Edge-Loc', 'Center', 'Donut', 'Near-full']
- Random_19203.jpg: class id(s): [5, 2, 1, 7, 4], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Random', 'Edge-Loc', 'Donut', 'Near-full', 'Loc']
- Random_19287.jpg: class id(s): [5, 7, 2, 1, 4], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Random', 'Near-full', 'Edge-Loc', 'Donut', 'Loc']
- Random_19414.jpg: class id(s): [5, 7, 2, 1, 0], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Random', 'Near-full', 'Edge-Loc', 'Donut', 'Center']
- Random_219919.jpg: class id(s): [5, 1, 2, 0, 4], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Random', 'Donut', 'Edge-Loc', 'Center', 'Loc']
- Random_219922.jpg: class id(s): [5, 2, 1, 0, 4], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Random', 'Edge-Loc', 'Donut', 'Center', 'Loc']
- Random_243242.jpg: class id(s): [5, 1, 2, 0, 4], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Random', 'Donut', 'Edge-Loc', 'Center', 'Loc']
- Random_243261.jpg: class id(s): [5, 1, 7, 6, 2], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Random', 'Donut', 'Near-full', 'Scratch', 'Edge-Loc']
- Random_4788.jpg: class id(s): [5, 7, 2, 1, 4], score(s): [0.99, 0.01, 0.00, 0.00, 0.00], label_name(s): ['Random', 'Near-full', 'Edge-Loc', 'Donut', 'Loc']
- Scratch_150649.jpg: class id(s): [6, 1, 4, 0, 2], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Scratch', 'Donut', 'Loc', 'Center', 'Edge-Loc']
- Scratch_164102.jpg: class id(s): [6, 1, 0, 5, 4], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Scratch', 'Donut', 'Center', 'Random', 'Loc']
- Scratch_174933.jpg: class id(s): [6, 4, 1, 2, 0], score(s): [0.99, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Scratch', 'Loc', 'Donut', 'Edge-Loc', 'Center']
- Scratch_177754.jpg: class id(s): [6, 4, 2, 0, 1], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Scratch', 'Loc', 'Edge-Loc', 'Center', 'Donut']
- Scratch_23516.jpg: class id(s): [6, 1, 4, 0, 5], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Scratch', 'Donut', 'Loc', 'Center', 'Random']
- Scratch_270947.jpg: class id(s): [6, 1, 4, 0, 2], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Scratch', 'Donut', 'Loc', 'Center', 'Edge-Loc']
- Scratch_283006.jpg: class id(s): [6, 4, 1, 0, 2], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Scratch', 'Loc', 'Donut', 'Center', 'Edge-Loc']
- Scratch_302544.jpg: class id(s): [6, 1, 4, 2, 0], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Scratch', 'Donut', 'Loc', 'Edge-Loc', 'Center']
- Scratch_355662.jpg: class id(s): [6, 2, 5, 4, 1], score(s): [0.99, 0.01, 0.00, 0.00, 0.00], label_name(s): ['Scratch', 'Edge-Loc', 'Random', 'Loc', 'Donut']
- Scratch_366023.jpg: class id(s): [6, 4, 2, 0, 1], score(s): [1.00, 0.00, 0.00, 0.00, 0.00], label_name(s): ['Scratch', 'Loc', 'Edge-Loc', 'Center', 'Donut']
- 此处可以对照文件名和推理的结果来判断预测是否正确,对于ResNet模型,可以统计出75张图片,有4张预测错误(已标红)
- 下面会将预测错误的图片可视化,用于后期寻找原因,进行改进
8. 推理结果处理以及可视化
8.1 Resnet模型错误结果可视化分析
此处主要是将分类错误的图片单独拿出来分析,直观的分析错误的原因,便于改进。
import os
import pandas as pd
import cv2
import matplotlib.pyplot as pltimg_root = "D:/12C301/PaddleClas/dataset/waferMap/test"
wrong_list = ['Edge-Loc_48272.jpg', 'Edge-Loc_58508.jpg', 'Edge-Loc_7413.jpg', 'Loc_87266.jpg', 'Scratch_355662.jpg']
wrong_label = ['Loc','Edge-Ring','Loc','Donut','Loc']plt.figure(figsize = (15,6))
for i in range(len(wrong_list)):img_path = os.path.join(img_root, wrong_list[i])img = cv2.imread(img_path)plt.subplot(1,len(wrong_list), i+1)plt.imshow(img[:,:, ::-1])plt.xlabel(wrong_list[i])plt.title("Predict Result: " + wrong_label[i], fontsize = 12)plt.show()
#在这个修改后的版本中,我们删除了`%matplotlib inline`魔术命令,并在代码的末尾添加了`plt.show()`函数,以便在运行时显示图像窗格。#希望这次修改对您有所帮助!如果还有其他问题,请随时提问。
与项目作者不同,修改后的版本中,我删除了`%matplotlib inline`魔术命令,并在代码的末尾添加了`plt.show()`函数,以便在运行时显示图像窗格。
主要是将分类错误的图片单独拿出来分析,直观的分析错误的原因,便于改进。
- 通过比较,可以发现分类错误的图谱大部分是Loc, Edge-Loc等图片
- 这种现象与晶圆图谱分类的特殊性有关,与普通的图片分类不同,晶圆图谱的失效模式类别和区域位置强相关。
- 对此,后期可以通过增加相应类别的样本数量来达到一定的改善
后续待更新
8.2 单张图片检测以及可视化结果
这里主要进行单张图片检测,以及将结果可视化出来
这里使用PaddleClas工具中的infer.py脚本进行检测。
获得检测结果:
[{'class_ids': [6, 1, 4, 0, 5], 'scores': [1.0, 0.0, 0.0, 0.0, 0.0], 'file_name': 'D:/12C301/PaddleClas/dataset/waferMap/test/Scratch_23516.jpg', 'label_names': ['Scratch', 'Donut', 'Loc', 'Center', 'Random']}]
接着写了个可视化脚本(ksh.py),来直观的展示检测结果
python ksh.py "[{'class_ids': [6, 1, 4, 0, 5], 'scores': [1.0, 0.0, 0.0, 0.0, 0.0], 'file_name': 'D:/12C301/PaddleClas/dataset/waferMap/test/Scratch_23516.jpg', 'label_names': ['Scratch', 'Donut', 'Loc', 'Center', 'Random']}]"
具体图片
这篇关于2023/8/2 复现一个“基于Paddleclas完成半导体晶圆图谱缺陷种类识别”的项目(自己学习记录版)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!