python-3.x - 不兼容的形状:[32] 与 [4536] [[{{nodelogistic_loss/mul}}]]
问题描述
我正在训练具有以下结构和参数的分类器:
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
encoder_input (InputLayer) (None, 567, 1) 0
__________________________________________________________________________________________________
conv1d_1 (Conv1D) (None, 189, 32) 128 encoder_input[0][0]
__________________________________________________________________________________________________
conv1d_2 (Conv1D) (None, 63, 64) 6208 conv1d_1[0][0]
__________________________________________________________________________________________________
conv1d_3 (Conv1D) (None, 21, 100) 19300 conv1d_2[0][0]
__________________________________________________________________________________________________
flatten_1 (Flatten) (None, 2100) 0 conv1d_3[0][0]
__________________________________________________________________________________________________
z_mean (Dense) (None, 20) 42020 flatten_1[0][0]
__________________________________________________________________________________________________
z_log_var (Dense) (None, 20) 42020 flatten_1[0][0]
__________________________________________________________________________________________________
z (Lambda) (None, 20) 0 z_mean[0][0]
z_log_var[0][0]
__________________________________________________________________________________________________
dense_1 (Dense) (None, 64) 1344 z[0][0]
__________________________________________________________________________________________________
dense_2 (Dense) (None, 128) 8320 dense_1[0][0]
__________________________________________________________________________________________________
dense_3 (Dense) (None, 200) 25800 dense_2[0][0]
__________________________________________________________________________________________________
dense_10 (Dense) (None, 4) 804 dense_3[0][0]
==================================================================================================
Total params: 145,944
Trainable params: 145,944
Non-trainable params: 0
除了层之外的所有dense
层都取自不同的模型。这里只有dense
层参数是可训练的。这是训练的代码片段:
for layer in classifier.layers[:-4]:
layer.trainable = False
classifier.fit(x_train, y_train,
epochs=50,
batch_size=8,
validation_data=(x_val, y_val)
)
classifier.save_weights('cnn_hhar.h5')
但我得到了这个InvalidArgumentError: Incompatible shapes: [32] vs. [4536]
[[{{node logistic_loss/mul}}]]
这段代码有什么问题?
编辑: 代码可在此处获得。它基本上改编自变分自动编码器的代码。我采用了编码器部分并向其中添加了 FC 层以执行分类任务。
解决方案
推荐阅读
- java - 如何在没有所有信息的情况下显示枚举
- pycharm - Overriding type of property in child class - Pycharm
- firebase - 如何将 Firebase 用户 UID 与 Firestore 文档 ID 匹配 - Flutter
- python - Ubuntu Cython compilation error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
- sql-server - Azure SQL Database not letting me create a Database Master Key
- python - Pandas .to_csv() 给出“文件类型没有引擎:'csv'”
- docker - Flink 全零监控
- python-3.x - 如何访问由 torchaudio.info(filepath) 返回的对象
- javascript - mutation observer wont do anything but no error is shown
- c# - 由 NPOI 编辑时,Excel 上的浅灰色背景颜色消失