我正在实施FCN-8解码器(deeplearning作业。Tensorflow深度学习中的ai高级技术,计算机视觉课程,第3周,语义分段)
我实现了下面的代码,我怀疑存在一些维度问题:运行测试时它落在第行:
o = tf.keras.layers.Add()([o, o2])
错误为ValueError: Operands could not be broadcast together with shapes (8, 12, 11) (4, 6, 11)
,因此我想我正在尝试连接具有不同形状的对象
我也在测试的尸体下面复制,FCN8()
方法在imo中是安全的
你有什么提示吗
def fcn8_decoder(convs, n_classes):
# features from the encoder stage
f3, f4, f5 = convs
# number of filters
n = 512
# add convolutional layers on top of the CNN extractor.
o = tf.keras.layers.Conv2D(n , (7 , 7) , activation='relu' , padding='same', name="conv6", data_format=IMAGE_ORDERING)(f5)
o = tf.keras.layers.Dropout(0.5)(o)
o = tf.keras.layers.Conv2D(n , (1 , 1) , activation='relu' , padding='same', name="conv7", data_format=IMAGE_ORDERING)(o)
o = tf.keras.layers.Dropout(0.5)(o)
o = tf.keras.layers.Conv2D(n_classes, (1, 1), activation='relu' , padding='same', data_format=IMAGE_ORDERING)(o)
# Upsample `o` above and crop any extra pixels introduced
o = tf.keras.layers.Conv2DTranspose(n_classes , kernel_size=(4,4) , strides=(2,2) , use_bias=False )(f5)
o = tf.keras.layers.Cropping2D(cropping=(1,1))(o)
# load the pool 4 prediction and do a 1x1 convolution to reshape it to the same shape of `o` above
o2 = f4
o2 = tf.keras.layers.Conv2D(n_classes , ( 1 , 1 ) , activation='relu' , padding='same')(o2)
# add the results of the upsampling and pool 4 prediction
o = tf.keras.layers.Add()([o, o2])
# upsample the resulting tensor of the operation you just did
o = tf.keras.layers.Conv2DTranspose( n_classes , kernel_size=(4,4) , strides=(2,2) , use_bias=False)(o)
o = tf.keras.layers.Cropping2D(cropping=(1, 1))(o)
# load the pool 3 prediction and do a 1x1 convolution to reshape it to the same shape of `o` above
o2 = tf.keras.layers.Conv2D(n_classes , ( 1 , 1 ) , activation='relu' , padding='same')(o2)
# add the results of the upsampling and pool 3 prediction
o = tf.keras.layers.Add()([o, o2])
# upsample up to the size of the original image
o = tf.keras.layers.Conv2DTranspose(n_classes , kernel_size=(8,8) , strides=(8,8) , use_bias=False )(o)
o = tf.keras.layers.Cropping2D(((0, 0), (0, 96-84)))(o)
# append a sigmoid activation
o = (tf.keras.layers.Activation('sigmoid'))(o)
return o
测试代码
# TEST CODE
test_convs, test_img_input = FCN8()
test_fcn8_decoder = fcn8_decoder(test_convs, 11)
print(test_fcn8_decoder.shape)
del test_convs, test_img_input, test_fcn8_decoder
您必须首先加载池3预测,然后应用1*1 conv
def fcn8_解码器(convs,n_类):
编码器阶段的功能
f3、f4、f5=convs
过滤器数量
n=512
在CNN提取器顶部添加卷积层
o=tf.keras.layers.Conv2D(n,(7,7),activation='relu',padding='same',name='conv6',数据格式=图像排序)(f5) o=tf.keras.layers.Dropout(0.5)(o) o=tf.keras.layers.Conv2D(n,(1,1),activation='relu',padding='same',name='conv7',数据格式=图像排序)(o) o=tf.keras.layers.Dropout(0.5)(o) o=tf.keras.layers.Conv2D(n_类,(1,1),activation='relu',padding='same',data_format=IMAGE\u排序)(o)
向上采样
o
并裁剪引入的任何额外像素o=tf.keras.layers.Conv2DTranspose(n_类,内核大小=(4,4),跨步=(2,2),使用_bias=False)(f5) o=tf.keras.layers.croping2d(裁剪=(1,1))(o)
加载池4预测并执行1x1卷积,以将其重新整形为上面
o
的相同形状o2=f4 o2=tf.keras.layers.Conv2D(n_类,(1,1),激活class='relu',填充class='same')(o2)
添加上采样和池4预测的结果
o=tf.keras.layers.Add()([o,o2])
向上采样刚才所做操作的结果张量
o=tf.keras.layers.Conv2DTranspose(n_类,内核大小=(4,4),跨步=(2,2),使用_bias=False)(o) o=tf.keras.layers.croping2d(裁剪=(1,1))(o)
加载池3预测,并进行1x1卷积,以将其重塑为上面
o
的相同形状o2=f3 o2=tf.keras.layers.Conv2D(n_类,(1,1),激活class='relu',填充class='same')(o2)
添加上采样和池3预测的结果
o=tf.keras.layers.Add()([o,o2])
向上采样到原始图像的大小
o=tf.keras.layers.Conv2DTranspose(n_类,内核大小=(8,8),跨步=(8,8),使用_bias=False)(o) o=tf.keras.layers.crapping2d((0,0)、(0,96-84))(o)
附加乙状结肠激活
o=(tf.keras.layers.Activation('sigmoid'))(o)
返回o
相关问题 更多 >
编程相关推荐