Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5-4 无法运行 #76

Open
vincent507cpu opened this issue Oct 14, 2020 · 0 comments
Open

5-4 无法运行 #76

vincent507cpu opened this issue Oct 14, 2020 · 0 comments

Comments

@vincent507cpu
Copy link

vincent507cpu commented Oct 14, 2020

在创建了 Linear 类以后,第一次实例化这个类的时候 linear = Linear(units=8),系统报错。反复与原始代码比较,没发现不同的地方。

class Linear(layers.Layer):
    def __init__(self, units=32, **kwargs):
        super(Linear, self).__init__(**kwargs)
        self.units = units
        
    def build(self, input_shape):
        self.w = self.add_weight('w', shape=(input_shape[-1], self.units),
                                initializer='random_normal',
                                trainable=True)
        self.b = self.add_weight('b', shape=(self.units,),
                                initializer='random_normal',
                                trainable=True)
        super(Linear, self).build(input_shape)
        
    @tf.function
    def call(self, inputs):
        return tf.matmul(inputs, self.w) + self.b
    
    def get_config(self):
        config = super(Linear, self).get_config()
        config.update({'units':self.units})
        return config
linear = Linear(units=8)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-efa0d9cd5402> in <module>
----> 1 linear = Linear(units=8)
      2 print(linear.built)
      3 linear.build(input_shape=(None, 16))
      4 print(linear.built)

TypeError: __call__() missing 1 required positional argument: 'inputs'

谢谢!

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

No branches or pull requests

1 participant