Tensorboard - pai-plznw4me/tensorflow_basic GitHub Wiki

tf.Module κ³Ό Tensorboard μ‹œκ°ν™”

μ‚¬μš© νŒ¨ν„΄ 3

: λ³€μˆ˜(tf.Variable) 에 계측적인 이름을 λΆ€μ—¬ν•  λ•Œ

@tf.Module.with_name_scope

μœ„ method 을 μ‚¬μš©ν•΄ 이름을 λΆ€μ—¬

  1. tensor, operator 을 group ν™”ν•΄ μ‹œκ°ν™” ν•  μ‹œ
  2. 계측적인(hierarchies) λ³€μˆ˜ 관리λ₯Ό ν•˜κ³  싢을 λ•Œ

2κ°€μ§€ 방법을 톡해 λ³€μˆ˜λ₯Ό κ΄€λ¦¬ν• μˆ˜ μžˆλŠ”λ°

  1. tf.name_scope(name=)

    class Dense(tf.Module):
        def __init__(self, in_features, out_features, name=None):
            super().__init__(name=name)
            with tf.name_scope(name=name):
                self.w = tf.Variable(
                    tf.random.normal([in_features, out_features]), name='w')
                self.b = tf.Variable(tf.zeros([out_features]), name='b')
    
        def __call__(self, x):
            y = tf.matmul(x, self.w) + self.b
            return tf.nn.relu(y)
    
    
  2. tf.Module.name_scope

    class MLP(tf.Module):
      def __init__(self, input_size, sizes, name=None):
        super(MLP, self).__init__(name=name)
        self.layers = []
        with self.name_scope:
          for size in sizes:
            self.layers.append(Dense(input_dim=input_size, output_size=size))
            input_size = size
      @tf.Module.with_name_scope
      def __call__(self, x):
        for layer in self.layers:
          x = layer(x)
        return x
    

    λ³€μˆ˜λ§Œ 묢을 건지 μ—°μ‚°μž κΉŒμ§€ λͺ¨λ‘ name_scope 에 묢을건지 κ²°μ • ν•  수 μžˆλ‹€.

    λ‹€λ§Œ ν•΄λ‹Ή 방법은 λͺ¨λ‘ Module μ΄λ¦„μœΌλ‘œ λ¬Άμ—¬μ§„λ‹€λŠ” 단점이 μžˆλ‹€.

    ν•΄λ‹Ή μ΄μœ λŠ” 이름 생성 μ‹œκΈ° λ•Œλ¬Έμ΄λ‹€. μžμ„Έν•œ λ‚΄μš©μ€ μ•„λž˜ tensorflow issue 을 μ‚΄νŽ΄ 보자