NoneType对象不可调用-Python/CNN



朋友们,我是新手。你能帮我理解为什么这个代码:吗

#Construct the model
model_simple = Sequential()
model_simple.add(Conv2D(strides = 1, kernel_size = 3, filters = 12, use_bias = True, bias_initializer = tf.keras.initializers.RandomUniform(minval=-0.05, maxval=0.05) , padding = "valid", activation = tf.nn.relu))
model_simple.add(Conv2D(strides = 1, kernel_size = 3, filters = 12, use_bias = True, bias_initializer = tf.keras.initializers.RandomUniform(minval=-0.05, maxval=0.05) , padding = "valid", activation = tf.nn.relu))
model_simple.add(Conv2DTranspose(strides = 1, kernel_size = 3, filters = 12, use_bias = True, bias_initializer = tf.keras.initializers.RandomUniform(minval=-0.05, maxval=0.05) , padding = "valid", activation = tf.nn.relu))
model_simple.add(Conv2DTranspose(strides = 1, kernel_size = 3, filters = 3, use_bias = True, bias_initializer = tf.keras.initializers.RandomUniform(minval=-0.05, maxval=0.05) , padding = "valid", activation = tf.nn.relu))
#Compile the model
model_simple.compile(optimizer = tf.keras.optimizers.Adam(epsilon = 1e-8), loss = tf.losses.mean_squared_error)
model_simple.fit(imgs_for_input, imgs_for_output, epochs=3, batch_size=32)

创建此错误:

Epoch 1/3
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-33-957812893dc7> in <module>()
----> 1 model_simple.fit(imgs_for_input, imgs_for_output, epochs=3, batch_size=32)
1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
940       # In this case we have created variables on the first call, so we run the
941       # defunned version which is guaranteed to never create variables.
--> 942       return self._stateless_fn(*args, **kwds)  # pylint: disable=not-callable
943     elif self._stateful_fn is not None:
944       # Release the lock early so that multiple threads can perform the call
TypeError: 'NoneType' object is not callable

感谢您抽出时间!

您必须在训练前构建模型。例如

batch = 32
height = 32
width = 32
channels = 3
inputShape = (batch, height, width, channels)
model_simple.build(inputShape)
model_simple.fit(imgs_for_input, imgs_for_output, epochs=3)

最新更新