代码链接: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)
绿色表示存在严重缺陷的区域。
蓝色表示缺陷更严重的区域。
红色区域显示出最严重的缺陷。
原始图像
二进制图像(地面真相)
、
具有严重性的预测输出
原始图像
二进制图像(地面真相)
具有严重性的预测输出
原始图像
二进制图像(地面真相)
具有严重性的预测输出
海水水质监测数据提供2017,2018,2019,2020,2021,2022年渤海、黄海、东海、南海等海域水质信息,包含海区,省份,地市,点位编码,实测经度,实测纬度,监测时间,pH,溶解氧,化学需氧量,无机氮,活性磷酸盐,石油类,水质类别等信息
全国雨水情信息大江大河大型水库重点雨水情数据,全国水雨情信息监测系统提供由水利部信息中心编制的全国大江大河实时水情、全国大型水库实时水情、全国重点站实时雨情,水文监测站, 实时水情历史记录,包含水位、流量、警戒水位、库水位、蓄水量、入库流量、径流、日雨量、天气等信息
包含全国水文监测点名称,行政区,流域,水系,编码,经度,纬度,河流,站类代码,站点类型,地址,时间,数据来源:全国雨水情信息
CASIA-HWDB-T包括56,469个二字或多字触摸字符串,其中1,818个字符串有多个触摸字符。 作者还将接触字符串划分为 50,157 个全中文字符串、2,788 个全数字字符串、328 个全字母字符串和 3,196 个混合字符字符串。 所有的字符串都标注了字符类、触摸点的位置以及字符串高度和平均笔画宽度等辅助值。 Publication: Liang Xu, Fei Yin, Qiu