Logo
Section 1 / 3

使用卷积神经网络进行图像分割

从基础到高级的卷积神经网络技术,深入探索图像分割,理解模型架构,并使用Python实现一个简单的分割模型。

导入

使用卷积神经网络进行图像分割

从基础到高级的卷积神经网络技术,深入探索图像分割,理解模型架构,并使用Python实现一个简单的分割模型。

...
图像分割类型

分割技术对比

方面语义分割实例分割全景分割
目标将每个像素分类到特定类别区分不同的物体实例融合语义分割与实例分割
表示方式像素级分类精确的边界划分与分类类别与实例的唯一标识
模型示例U-Net, SegNetMask R-CNN, PointRend视觉Transformer(ViTs)
上下文信息能有效捕捉上下文信息关注局部与全局上下文同时整合类别与实例信息
...
特征图金字塔
1import tensorflow as tf 2import matplotlib.pyplot as plt 3from tensorflow.keras.preprocessing import image 4 5# 加载预训练的U-Net模型(本例中使用DenseNet121),并预处理示例图像 6model = tf.keras.applications.DenseNet121(weights='imagenet', include_top=False, input_shape=(256, 256, 3)) 7 8# 加载并预处理示例图像 9img_path = 'test2.jpg' 10img = image.load_img(img_path, target_size=(256, 256)) 11img_array = image.img_to_array(img) 12img_array = tf.expand_dims(img_array, 0) # 增加批次维度 13img_array /= 255.0 # 归一化像素值 14 15# 使用预训练模型对示例图像进行预测 16predictions = model.predict(img_array) 17 18# 并排显示原始图像与分割图 19plt.figure(figsize=(10, 5)) 20 21plt.subplot(1, 2, 1) 22plt.imshow(img) 23plt.title('原始图像') 24 25plt.subplot(1, 2, 2) 26plt.imshow(predictions[0][:, :, 0], cmap='gray') # 为简化,假设输出为单通道 27plt.title('分割图') 28 29plt.show()

Transformer在目标检测中的应用

使用Transformer进行图像分割