代码链接:https://github.com/malakar-soham/cnn-in-welding
对心脏(红色),肺部(绿色)和锁骨(蓝色)的胸部X光进行了分割
面积(或总强度)
质心
有关其方向的信息
来自“图像”的原始图像
图像分割
使用颜色显示严重性
使用图像矩测量严重性
使用的U-Net架构
每个蓝色框对应一个多通道特征图
通道数显示在框的顶部。
(x,y)尺寸位于框的左下边缘。
箭头表示不同的操作。
图层名称位于图层下方。
C1,C2,...。C7是卷积运算后的输出层
P1,P2,P3是最大池化操作的输出层
U1,U2,U3是上采样操作的输出层
A1,A2,A3是跳过连接。
左侧是收缩路径,其中应用了常规卷积和最大池化操作
图像尺寸逐渐减小,而深度逐渐增大。
右侧是扩展路径,在其中应用了(向上采样)转置卷积和常规卷积运算
在扩展路径中,图像尺寸逐渐增大,深度逐渐减小
为了获得更好的精确位置,在扩展的每个步骤中,我们都使用跳过连接,方法是将转置卷积层的输出与来自编码器的特征图在同一级别上连接:
A1 = U1 + C3
A2 = U2 + C2
A3 = U3 + C1
每次串联后,我们再次应用规则卷积,以便模型可以学习组装更精确的输出。
import numpy as np import cv2 import os import random import tensorflow as tf h,w = 512,512 def create_model(): inputs = tf.keras.layers.Input(shape=(h,w,3)) conv1 = tf.keras.layers.Conv2D(16,(3,3),activation='relu',padding='same')(inputs) pool1 = tf.keras.layers.MaxPool2D()(conv1) conv2 = tf.keras.layers.Conv2D(32,(3,3),activation='relu',padding='same')(pool1) pool2 = tf.keras.layers.MaxPool2D()(conv2) conv3 = tf.keras.layers.Conv2D(64,(3,3),activation='relu',padding='same')(pool2) pool3 = tf.keras.layers.MaxPool2D()(conv3) conv4 = tf.keras.layers.Conv2D(64,(3,3),activation='relu',padding='same')(pool3) upsm5 = tf.keras.layers.UpSampling2D()(conv4) upad5 = tf.keras.layers.Add()([conv3,upsm5]) conv5 = tf.keras.layers.Conv2D(32,(3,3),activation='relu',padding='same')(upad5) upsm6 = tf.keras.layers.UpSampling2D()(conv5) upad6 = tf.keras.layers.Add()([conv2,upsm6]) conv6 = tf.keras.layers.Conv2D(16,(3,3),activation='relu',padding='same')(upad6) upsm7 = tf.keras.layers.UpSampling2D()(conv6) upad7 = tf.keras.layers.Add()([conv1,upsm7]) conv7 = tf.keras.layers.Conv2D(1,(3,3),activation='relu',padding='same')(upad7) model = tf.keras.models.Model(inputs=inputs, outputs=conv7) return model images = [] labels = [] files = os.listdir('./dataset/images/') random.shuffle(files) for f in files: img = cv2.imread('./dataset/images/' + f) parts = f.split('_') label_name = './dataset/labels/' + 'W0002_' + parts[1] label = cv2.imread(label_name,2) img = cv2.resize(img,(w,h)) label = cv2.resize(label,(w,h)) images.append(img) labels.append(label) images = np.array(images) labels = np.array(labels) labels = np.reshape(labels, (labels.shape[0],labels.shape[1],labels.shape[2],1)) print(images.shape) print(labels.shape) images = images/255 labels = labels/255 model = tf.keras.models.load_model('my_model') #model = create_model() # uncomment this to create a new model print(model.summary()) model.compile(optimizer='adam', loss='binary_crossentropy',metrics=['accuracy']) model.fit(images,labels,epochs=100,batch_size=10) model.evaluate(images,labels) model.save('my_model')
该模型使用Adam优化器编译,由于只有两类(缺陷或没有缺陷),因此我们使用二进制交叉熵损失函数。我们使用10批次、100个epochs(在所有输入上运行模型的次数)。调整这些参数,模型性能可能会有很大的改善可能。
然后将图像转换为16位整数以便于图像操作。之后,算法将检测缺陷并通过颜色分级在视觉上标记缺陷的严重性,并根据缺陷的严重性为具有缺陷的像素分配权重。然后考虑加权像素,在此图像上计算图像力矩。最终将图像转换回8位整数,并以颜色分级及其严重性值显示输出图像。
import numpy as np import cv2 from google.colab.patches import cv2_imshow import os import random import tensorflow as tf h,w = 512,512 num_cases = 10 images = [] labels = [] files = os.listdir('./dataset/images/') random.shuffle(files) model = tf.keras.models.load_model('my_model') lowSevere = 1 midSevere = 2 highSevere = 4 for f in files[0:num_cases]: test_img = cv2.imread('./dataset/images/' + f) resized_img = cv2.resize(test_img,(w,h)) resized_img = resized_img/255 cropped_img = np.reshape(resized_img, (1,resized_img.shape[0],resized_img.shape[1],resized_img.shape[2])) test_out = model.predict(cropped_img) test_out = test_out[0,:,:,0]*1000 test_out = np.clip(test_out,0,255) resized_test_out = cv2.resize(test_out,(test_img.shape[1],test_img.shape[0])) resized_test_out = resized_test_out.astype(np.uint16) test_img = test_img.astype(np.uint16) grey = cv2.cvtColor(test_img, cv2.COLOR_BGR2GRAY) for i in range(test_img.shape[0]): for j in range(test_img.shape[1]): if(grey[i,j]>150 & resized_test_out[i,j]>40): test_img[i,j,1]=test_img[i,j,1] + resized_test_out[i,j] resized_test_out[i,j] = lowSevere elif(grey[i,j]<100 & resized_test_out[i,j]>40): test_img[i,j,2]=test_img[i,j,2] + resized_test_out[i,j] resized_test_out[i,j] = highSevere elif(resized_test_out[i,j]>40): test_img[i,j,0]=test_img[i,j,0] + resized_test_out[i,j] resized_test_out[i,j] = midSevere else: resized_test_out[i,j] = 0 M = cv2.moments(resized_test_out) maxMomentArea = resized_test_out.shape[1]*resized_test_out.shape[0]*highSevere print("0th Moment = " , (M["m00"]*100/maxMomentArea), "%") test_img = np.clip(test_img,0,255) test_img = test_img.astype(np.uint8) cv2_imshow(test_img) cv2.waitKey(0)
绿色表示存在严重缺陷的区域。
蓝色表示缺陷更严重的区域。
红色区域显示出最严重的缺陷。
原始图像
二进制图像(地面真相)
、
具有严重性的预测输出
原始图像
二进制图像(地面真相)
具有严重性的预测输出
原始图像
二进制图像(地面真相)
具有严重性的预测输出
该数据集包含 4242 张花卉图像。数据收集基于数据flicr、google images、yandex images。此数据集可用于从照片中识别植物。数据图片会分为五类:洋甘菊、郁金香、玫瑰、向日葵、蒲公英。每个种类大约有800张照片。 照片分辨率不高,约为 320x240 像素。 照片不会缩小到单一尺寸,它们有不同的比例。
湖北省主要雨量站雨情数据,2000年至2022年最新 湖北省雨情数据,总共6000+(月均为4000左右站点)监测站点,包含行政区编码名称,站点编码名称,时间,时段降水量mm,时段长,降水历时,日降水量mm,天气等信息,数据总量2.6亿条,11G。
上海财经大学中国省级财政透明度评估,包含中国省级财政透明度评估(2009), 中国省级财政透明度评估(2010),中国省级财政透明度评估(2011), 中国财政透明度评估(2012),中国财政透明度评估(2013),中国财政透明度评估(2014),中国财政透明度评估(2015),中国省级财政透明度评估(2016),中国省级财政透明度评估(2017)等上海财经大学团队针对中国省级财政透明度的年度评估。
包含全国水文监测点名称,行政区,流域,水系,编码,经度,纬度,河流,站类代码,站点类型,地址,时间,数据来源:全国雨水情信息