【发布时间】:2020-06-30 11:39:01
【问题描述】:
我有一个非常简单的模型,如下所示:
import tensorflow as tf
class Model(tf.keras.Model):
def __init__(self, input_shape=None, name="cus_model", **kwargs):
super(Model, self).__init__(name=name, **kwargs)
def build(self, input_shape):
self.dense1 = tf.keras.layers.Dense(input_shape=input_shape, units=32)
def call(self, input_tensor):
return self.dense1(input_tensor)
input_shape=(1,10)
model = Model()
model.build(input_shape=input_shape) # Note the .build call
model.summary()
我已经按照this answer 添加了model.build() 调用,但我仍然收到以下错误:
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling `fit()` with some data, or specify an `input_shape` argument in the first layer(s) for automatic build.
我在这里错过了什么?
【问题讨论】:
标签: python tensorflow tensorflow2.0