ViTAttention

Erstellt Diff läuft nie ab
4 Entfernungen
26 Zeilen
0 Hinzufügungen
26 Zeilen
class TFViTMAEAttention(tf.keras.layers.Layer):
class TFViTAttention(tf.keras.layers.Layer):
def __init__(self, config: ViTMAEConfig, **kwargs):
def __init__(self, config: ViTConfig, **kwargs):
super().__init__(**kwargs)
super().__init__(**kwargs)


self.self_attention = TFViTMAESelfAttention(config, name="attention")
self.self_attention = TFViTSelfAttention(config, name="attention")
self.dense_output = TFViTMAESelfOutput(config, name="output")
self.dense_output = TFViTSelfOutput(config, name="output")


def prune_heads(self, heads):
def prune_heads(self, heads):
raise NotImplementedError
raise NotImplementedError


def call(
def call(
self,
self,
input_tensor: tf.Tensor,
input_tensor: tf.Tensor,
head_mask: tf.Tensor,
head_mask: tf.Tensor,
output_attentions: bool,
output_attentions: bool,
training: bool = False,
training: bool = False,
) -> Tuple[tf.Tensor]:
) -> Tuple[tf.Tensor]:
self_outputs = self.self_attention(
self_outputs = self.self_attention(
hidden_states=input_tensor, head_mask=head_mask, output_attentions=output_attentions, training=training
hidden_states=input_tensor, head_mask=head_mask, output_attentions=output_attentions, training=training
)
)
attention_output = self.dense_output(
attention_output = self.dense_output(
hidden_states=self_outputs[0], input_tensor=input_tensor, training=training
hidden_states=self_outputs[0], input_tensor=input_tensor, training=training
)
)
outputs = (attention_output,) + self_outputs[1:] # add attentions if we output them
outputs = (attention_output,) + self_outputs[1:] # add attentions if we output them


return outputs
return outputs