版权声明:本文为博主原创文章,转载 请注明出处:https://blog.csdn.net/sc2079/article/details/90480140
- 写在前面
本科毕业设计终于告一段落了。特写博客记录做毕业设计(路面裂纹识别)期间的踩过的坑和收获。希望对你有用。
目前有:
1.Tensorflow&CNN:裂纹分类
2.Tensorflow&CNN:验证集预测与模型评价
3.PyQt5多个GUI界面设计
本篇博客主要是评估所训练出来的CNN分类模型的性能。主要有几点:验证集预测、多分类混淆矩阵、多分类评价指标、预测结果堆叠图。
- 环境配置安装
运行环境:Python3.6、Spyder
依赖模块:Skimage、Tensorflow(CPU)、Numpy 、Matlpotlib等
- 开始工作
1.读取验证集图片
在验证集数据目录下有五个文件夹,分别以数字0-4命名,代表裂纹类型。其中,每个文件夹下各有100张图片。
def read_img(path):
cate=[path+x for x in os.listdir(path)]
imgs=[]
labels=[]
for idx,folder in enumerate(cate):
for im in glob.glob(folder+'/*.jpg'):
#print('reading the images:%s'%(im))
img=io.imread(im)
img=transform.resize(img,(100,100))
#img=normlization(img)
imgs.append(img)
labels.append(idx)
return np.asarray(imgs,np.float32),np.asarray(labels,np.int32)
path='d://test//img2//'
data,label=read_img(path)
#打乱顺序
num_example=data.shape[0]
arr=np.arange(num_example)
np.random.shuffle(arr)
data=data[arr]
label=label[arr]
x_val=data
y_val=list(label)
y_val即为每张图片的实际裂纹类型所