call(inputs, training=None, mask=None) 의 시그니처 기억. training flag 는 Dropout / BatchNorm 같이 train/eval 다른 layer 가 알아야 함. 직접 호출 시 self.dropout(x, training=training) 같이 전달. mask 는 RNN / attention 의 padding 처리.
call 안에 자유로운 Python — if/for 가능. if training: x = self.dropout(x). dynamic shape 도 OK — tf.shape(x)[0] 같이. 이 자유가 Subclass 의 본질.
백엔드 노트:
⚙️ Backend Note
Code
class <span class="dc">ConditionalLayer</span>(keras.layers.Layer):
def call(self, inputs, training=False):
# Use keras.ops for backend-agnostic code!
x = keras.ops.relu(inputs)
if training:
x = keras.ops.nn.dropout(x, rate=0.5)
return x