我正在使用TensorFlow 2.0和Keras自学深度学习方法。我选择的方案是根据房屋的总电量读数来确定是否打开了微波炉。我会在colab notebook中对此进行更好的解释。
我的目标是复制colab笔记本中显示的图中显示的学习模型。笔记本解释了我的输入和目标数据。
我希望能够在我在图层中设置的内容上运行model.fit。但是,我得到The last dimension of the inputs to
密集should be defined. Found
无.
我一定会误会输入/输出形状。
我尝试了各种重塑。但是,我不明白如何正确地将张量设置到各层?
这是colab笔记本中的相关代码:
model = Sequential()
model.add(Reshape((-1,599,1)))
model.add(Conv2D(filters=30,kernel_size=(10,1),strides=(1,1),padding='same',activation='relu',input_shape=(599,1)))
model.add(Conv2D(filters=30,kernel_size=(8,1),strides=(1,1),padding='same',activation='relu'))
model.add(Conv2D(filters=40,kernel_size=(6,1),strides=(1,1),padding='same',activation='relu'))
model.add(Conv2D(filters=50,kernel_size=(5,1),strides=(1,1),padding='same',activation='relu'))
model.add(Conv2D(filters=50,kernel_size=(5,1),strides=(1,1),padding='same',activation='relu'))
model.add(Flatten())
model.add(Dense(1024,activation='relu'))
model.add(Dense(1, activation='linear', name='output'))
model.compile(optimizer='adam',
loss='mean_squared_error',
metrics=['accuracy'])
model.fit(dataset, epochs=10)
WARNING:tensorflow:Layer sequential_2 is casting an input tensor from dtype float64 to the layer's dtype of float32, which is new behavior in TensorFlow 2. The layer has dtype float32 because it's dtype defaults to floatx.
If you intended to run this layer in float32, you can safely ignore this warning. If in doubt, this warning is likely only an issue if you are porting a TensorFlow 1.X model to TensorFlow 2.
To change all layers to have dtype float64 by default, call `tf.keras.backend.set_floatx('float64')`. To change just this layer, pass dtype='float64' to the layer constructor. If you are the author of this layer, you can disable autocasting by passing autocast=False to the base Layer constructor.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-21-f8c5e0c71664> in <module>()
----> 1 model.fit(dataset, epochs=10)
11 frames
/tensorflow-2.0.0/python3.6/tensorflow_core/python/keras/layers/core.py in build(self, input_shape)
1013 input_shape = tensor_shape.TensorShape(input_shape)
1014 if tensor_shape.dimension_value(input_shape[-1]) is None:
-> 1015 raise ValueError('The last dimension of the inputs to `Dense` '
1016 'should be defined. Found `None`.')
1017 last_dim = tensor_shape.dimension_value(input_shape[-1])
ValueError: The last dimension of the inputs to `Dense` should be defined. Found `None`.
(谢谢)