代码链接: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)
绿色表示存在严重缺陷的区域。
蓝色表示缺陷更严重的区域。
红色区域显示出最严重的缺陷。
原始图像
二进制图像(地面真相)
、
具有严重性的预测输出
原始图像
二进制图像(地面真相)
具有严重性的预测输出
原始图像
二进制图像(地面真相)
具有严重性的预测输出
数据集介绍: 这24个数据集是由潘广汉、孙天生、托比·威德和丹尼尔·沙尔斯坦在2019-2021期间创建的。数据集包括11个场景,在许多不同的照明条件和曝光(包括移动设备的闪光灯和“手电筒”照明)下,从1-3个不同的观看方向成像。 References: [1] D. Scharstein and R. Szeliski. A taxonomy and evaluation of
m2caiSeg是根据真实世界外科手术的内窥镜视频源创建的。数据由 307 张图像组成,每张图像都针对场景中存在的器官和不同的手术器械进行了注释。 If you use this dataset in your work, kindly do cite our paper: @article{maqbool2020m2caiseg, title={m2caiSeg: Semantic Se
半自动生成的细胞核实例分割和分类数据集,包含 19 种不同组织类型的详尽细胞核标签。该数据集由 481 个视野组成,其中 312 个视野是从多个数据源的 20K 多个不同放大倍率的整张幻灯片图像中随机采样的。该数据集总共包含 205,343 个标记的核,每个核都有一个实例分割掩码。在 pannuke 上训练的模型可以帮助整个幻灯片图像组织类型分割,并推广到新组织。PanNuke 演示了首批成功半自
全国雨水情信息大江大河大型水库重点雨水情数据,全国水雨情信息监测系统提供由水利部信息中心编制的全国大江大河实时水情、全国大型水库实时水情、全国重点站实时雨情,水文监测站, 实时水情历史记录,包含水位、流量、警戒水位、库水位、蓄水量、入库流量、径流、日雨量、天气等信息