在Tensorflow2.0中,我发现可以通过以下方式初始化模型中的变量
class MyModel(tf.keras.Model):
def __init__(self,*args,kwargs**):
""" some definition here """
self(tf.keras.Input(shape=(3,)))
def call(self,x):
""" some implementation """
但是我不能做
class MyModel(tf.keras.Model):
def __init__(self,kwargs**):
""" some definition here """
self.step(tf.keras.Input(shape=(3,)))
def step(self,x):
""" some implementation """
这将导致错误
我想做第二个原因的原因是我尝试从MyModel
继承tf.Module
,而__call__
没有可用的tf.Module
---即使定义了一个,也会出现相同的错误。我想知道是否可以像在第一个代码块中那样初始化从{
"Statement": [
{
"Effect": "Allow","action": [
"ec2:Createsnapshot","ec2:Createtags","ec2:Deletesnapshot","ec2:Describesnapshots","ec2:Describetags"
],"Resource": [
"*"
]
}
]
}
继承的类中的变量?