我正在阅读TensorFlow 2.0 教程,并且遇到了模型子类化来创建 TensorFlow 2.0 模型。
我找到的代码是:
class MyModel(Model):
def __init__(self):
super(MyModel, self).__init__()
self.conv1 = Conv2D(32, 3, activation='relu')
self.flatten = Flatten()
self.d1 = Dense(128, activation='relu')
self.d2 = Dense(10, activation='softmax')
def call(self, x):
x = self.conv1(x)
x = self.flatten(x)
x = self.d1(x)
return self.d2(x)
# Create an instance of the model
model = MyModel()
现在,在这段代码中,我的困惑是,代码的作者没有定义输入?
没有——
self.input_layer = Input(
shape = (28, 28)
)
# OR-
self.conv1 = Conv2D(32, 3, activation='relu', input_dim = (28, 28)
然后,定义的模型如何知道从训练数据中期望有多少属性/特征?
谢谢