【发布时间】:2020-05-24 06:04:46
【问题描述】:
我在阅读 TensorFlow 2.0 Tutorial 时遇到了创建 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)
然后定义的模型如何知道从训练数据中预期有多少属性/特征?
谢谢
【问题讨论】:
标签: python-3.x keras tensorflow2.0 tf.keras tensorflow2.x