【问题标题】:Image Segmentation Tensorflow tutorials图像分割 Tensorflow 教程
【发布时间】:2020-10-25 05:44:52
【问题描述】:

在这个tf tutorial 中,U-net 模型被分为两部分,第一部分是他们使用 Mobilenet 并且不可训练的部分。在第二部分,我无法理解所有层都在训练什么。据我所见,只有最后一层 conv2dTranspose 似乎是可训练的。我说的对吗?

如果我是这样,怎么可能只有一层能够完成分割这样复杂的任务?

教程链接:https://www.tensorflow.org/tutorials/images/segmentation

【问题讨论】:

    标签: tensorflow conv-neural-network image-segmentation autoencoder unity3d-unet


    【解决方案1】:

    Image Segmentation Model 的代码,来自Tutorial,如下所示:

    def unet_model(output_channels):
      inputs = tf.keras.layers.Input(shape=[128, 128, 3])
      x = inputs
    
      # Downsampling through the model
      skips = down_stack(x)
      x = skips[-1]
      skips = reversed(skips[:-1])
    
      # Upsampling and establishing the skip connections
      for up, skip in zip(up_stack, skips):
        x = up(x)
        concat = tf.keras.layers.Concatenate()
        x = concat([x, skip])
    
      # This is the last layer of the model
      last = tf.keras.layers.Conv2DTranspose(
          output_channels, 3, strides=2,
          padding='same')  #64x64 -> 128x128
    
      x = last(x)
    
      return tf.keras.Model(inputs=inputs, outputs=x)
    

    模型的第一部分是Downsampling 不使用整个Mobilenet Architecture,而只使用Layers

    'block_1_expand_relu',   # 64x64
    'block_3_expand_relu',   # 32x32
    'block_6_expand_relu',   # 16x16
    'block_13_expand_relu',  # 8x8
    'block_16_project'
    

    预训练模型的Mobilenet,即non-trainable

    模型的第二部分(您感兴趣),在层之前,Conv2DTransposeUpsampling 部分,它存在于list 中,

    up_stack = [
        pix2pix.upsample(512, 3),  # 4x4 -> 8x8
        pix2pix.upsample(256, 3),  # 8x8 -> 16x16
        pix2pix.upsample(128, 3),  # 16x16 -> 32x32
        pix2pix.upsample(64, 3),   # 32x32 -> 64x64
    ]
    

    这意味着它正在从模块pix2pix 访问一个名为upsample 的函数。模块代码pix2pix 存在于此Github Link 中。

    函数代码upsample如下所示:

    def upsample(filters, size, norm_type='batchnorm', apply_dropout=False):
      """Upsamples an input.
      Conv2DTranspose => Batchnorm => Dropout => Relu
      Args:
        filters: number of filters
        size: filter size
        norm_type: Normalization type; either 'batchnorm' or 'instancenorm'.
        apply_dropout: If True, adds the dropout layer
      Returns:
        Upsample Sequential Model
      """
    
      initializer = tf.random_normal_initializer(0., 0.02)
    
      result = tf.keras.Sequential()
      result.add(
          tf.keras.layers.Conv2DTranspose(filters, size, strides=2,
                                          padding='same',
                                          kernel_initializer=initializer,
                                          use_bias=False))
    
      if norm_type.lower() == 'batchnorm':
        result.add(tf.keras.layers.BatchNormalization())
      elif norm_type.lower() == 'instancenorm':
        result.add(InstanceNormalization())
    
      if apply_dropout:
        result.add(tf.keras.layers.Dropout(0.5))
    
      result.add(tf.keras.layers.ReLU())
    
      return result
    

    这意味着Model 的第二部分由Upsampling Layers 组成,其功能在上面定义,Filters 的数量为512, 256, 128 and 64

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-26
      • 2016-07-23
      • 2018-11-14
      • 2021-06-08
      • 2022-01-02
      • 1970-01-01
      • 2022-10-17
      • 2021-03-26
      相关资源
      最近更新 更多