TensorFlow: Difference between revisions

Line 104: Line 104:
         w_pad,h_pad = self.padding
         w_pad,h_pad = self.padding
         return tf.pad(x, [[0,0], [h_pad,h_pad], [w_pad,w_pad], [0,0] ], 'REFLECT')
         return tf.pad(x, [[0,0], [h_pad,h_pad], [w_pad,w_pad], [0,0] ], 'REFLECT')
</syntaxhighlight>
}}
{{ hidden | BilinearUpsample |
<syntaxhighlight lang="python">
class BilinearUpsample(layers.Layer):
  def __init__(self):
    super().__init__()
    self.input_spec = [keras.layers.InputSpec(ndim=4)]
  def compute_output_shape(self, shape):
      return shape[0], 2 * shape[1], 2 * shape[2], shape[3]
  def call(self, inputs, training=None, mask=None):
    new_height = int(2 * inputs.shape[1])
    new_width = int(2 * inputs.shape[2])
    return tf.image.resize_images(inputs, [new_height, new_width])
</syntaxhighlight>
</syntaxhighlight>
}}
}}