需要源码和数据集请点赞关注收藏后评论区留言私信~~~
图像分割(image segmentation)技术是计算机视觉领域的重要研究方向,是图像识别、图像语义理解的重要一环。图像分割是指将图像分成若干具有相似性质的区域的过程,从数学角度来看,图像分割是将图像划分成互不相交的区域的过程。如下图所示,图像中的每个像素被分到不同的类别。与目标检测算法相比较,图像分割算法更适合精细的图像识别任务,更适合目标的精确定位、复杂形状物体的识别、图像的语义理解任务。
图像分割可以进一步地分为语义分割与实例分割,语义分割是指需要进一步判断图像中哪些像素属于哪类目标,但是语义分割不区分属于相同类别的不同实例,与此不同的是,实例分割可以区分出属于不同实例的那些像素
对分割结果的评价其实就是对像素级分类的评价,基于像素点分类的MaxF1评价分割效果是比较常用的一种方式,F-Measure是一种统计量,F-Measure又称为F-Score,是准确率Precision和召回率Recall的加权调和平均,是信息检索领域常用的一个评价标准,常用于评价分类模型的好坏,在F-Measure函数中,当参数B=1时就是常见的F1,它综合了Precision和Recall的结果,当F1较高时则能说明试验方法比较有效,对于输出的置信度图,通过设置不同的像素级分类阈值可以选择出最大的F-Measure
下图为三种分割算法在VOC2012测试机上性能表示,其中DeepLab的分割准确率最高,FCN的分割速度最高,SegNet则在分割的准确率和速度中都是最低
需要全部源码请点赞关注收藏后评论区留言私信~~~
数据集简介
Cityscapes数据库拥有5000张在城市环境中驾驶场景的图像(2975train,500 val,1525test),如下图所示。可以利用下面的代码测试分割的图像中车辆、行人、自行车及街景。
from keras.applications import vgg16
from keras.models import Model,Sequential
from keras.layers import Conv2D, Conv2DTranspose, Input, Cropping2D, add, Dropout, Reshape, Activation
from keras.utils import plot_model
def FCN32(nClasses, input_height, input_width):
assert input_height % 32 == 0
assert input_width % 32 == 0
img_input = Input(shape=( input_height, input_width,3))
model = vgg16.VGG16(
include_top=False,
weights='imagenet',input_tensor=img_input,
pooling=None,
classes=1000)
assert isinstance(model,Model)
o=Conv2D(filters=4096,kernel_size=(7,7),padding="same",activation="relu",name="fc6")(model.output)
o=Dropout(rate=0.5)(o)
o = Conv2D(filters=4096, kernel_size=(1, 1), padding="same", activation="relu", name="fc7")(o)
o=Dropout(rate=0.5)(o)
o = Conv2D(filters=nClasses, kernel_size=(1,1), padding="same",activation="relu",kernel_initializer="he_normal",
name="score_fr")(o)
o=Conv2DTranspose(filters=nClasses,kernel_size=(32,32),strides=(32,32),padding="valid",activation=None,
name="score2")(o)
o=Reshape((-1,nClasses))(o)
o=Activation("softmax")(o)
fcn8=Model(inputs=img_input,outputs=o)
# mymodel.summary()
return fcn8
if __name__ == '__main__':
m = FCN32(15,320, 320)
m.summary()
plot_model(m, show_shapes=True, to_file='model_fcn32.png')
print(len(m.layers))
模型图如下
from keras.applications import vgg16
from keras.models import Model,Sequential
from keras.layers import Conv2D, Conv2DTranspose, Input, Cropping2D, add, Dropout, Reshape, Activation
def FCN8_helper(nClasses, input_height, input_width):
assert input_height % 32 == 0
assert input_width % 32 == 0
img_input = Input(shape=(input_height, input_width, 3))
model = vgg16.VGG16(
include_top=False,
weights='imagenet',input_tensor=img_input,
pooling=None,
classes=1000)
assert isinstance(model,Model)
o = Conv2D(filters=4096, kernel_size=(7, 7), padding="same", activation="relu", name="fc6")(model.output)
o = Dropout(rate=0.5)(o)
o = Conv2D(filters=4096, kernel_size=(1, 1), padding="same", activation="relu", name="fc7")(o)
o = Dropout(rate=0.5)(o)
o = Conv2D(filters=nClasses, kernel_size=(1, 1), padding="same", activation="relu", kernel_initializer="he_normal",
name="score_fr")(o)
o = Conv2DTranspose(filters=nClasses, kernel_size=(2, 2), strides=(2, 2), padding="valid", activation=None,
name="score2")(o)
fcn8 = Model(inputs=img_input, outputs=o)
# mymodel.summary()
return fcn8
def FCN8(nClasses, input_height, input_width):
fcn8=FCN8_helper(nClasses, input_height, input_width)
# Conv to be applied on Pool4
skip_con1 = Conv2D(nClasses, kernel_size=(1, 1), padding="same", activation=None,kernel_initializer="he_normal",
name="score_pool4")( fcn8.get_layer("block4_pool").output)
Summed = add(inputs=[skip_con1, fcn8.output])
x = Conv2DTranspose(nClasses, kernel_size=(2, 2), strides=(2, 2), padding="valid", activation=None,
name="score4")(Summed)
###
skip_con2 = Conv2D(nClasses, kernel_size=(1, 1), padding="same", activation=None,kernel_initializer="he_normal",
name="score_pool3")( fcn8.get_layer("block3_pool").output)
Summed2 = add(inputs=[skip_con2, x])
#####
Up = Conv2DTranspose(nClasses, kernel_size=(8, 8), strides=(8, 8),
padding="valid", activation=None, name="upsample")(Summed2)
Up = Reshape((-1, nClasses))(Up)
Up = Activation("softmax")(Up)
mymodel=Model(inputs=fcn8.input,outputs=Up)
return mymodel
if __name__ == '__main__':
m = FCN8(15,320, 320)
from keras.utils import plot_model
plot_model(m, show_shapes=True, to_file='model_fcn8.png')
print(len(m.layers))
创作不易 觉得有帮助请点赞关注收藏~~~