Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

求解 self(inputs) #9

Open
OpenWaygate opened this issue Mar 3, 2019 · 1 comment
Open

求解 self(inputs) #9

OpenWaygate opened this issue Mar 3, 2019 · 1 comment

Comments

@OpenWaygate
Copy link

TensorFlow模型>基础示例:多层感知机(MLP)的一处代码

class MLP(tf.keras.Model):
    def __init__(self):
        super().__init__()
        self.dense1 = tf.keras.layers.Dense(units=100, activation=tf.nn.relu)
        self.dense2 = tf.keras.layers.Dense(units=10)

    def call(self, inputs):
        x = self.dense1(inputs)
        x = self.dense2(x)
        return x

    def predict(self, inputs):
        logits = self(inputs) # 这一行要怎么理解?
        return tf.argmax(logits, axis=-1)

倒数第二行代码, 是不是等价于self.call(inputs)?

@snowkylin
Copy link
Owner

相当于self.__call__(inputs),不过意思差不多啦

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants