简体   繁体   English

使用 Keras Tuner RandomSearch 错误进行超参数调整

[英]Hyperparameter Tuning with Keras Tuner RandomSearch Error

I am using keras tuner to optimize hyperparameters: hidden layers, neurons, activation function, and learning rate.我正在使用 keras 调谐器来优化超参数:隐藏层、神经元、激活 function 和学习率。 I have time series regression problem with 31 inputs, 32 outputs with N number of data samples.我有 31 个输入、32 个输出和 N 个数据样本的时间序列回归问题。

My original X_train shape is (N,31) and Y_train shape is (N,32).我原来的 X_train 形状是 (N,31) 而 Y_train 形状是 (N,32)。 I transform it to work for keras shape and I reshape X_train and Y_train as following: X_train.shape: (N,31,1) Y_train.shape: (N,32).我将其转换为适用于 keras 形状,并将 X_train 和 Y_train 重塑如下:X_train.shape: (N,31,1) Y_train.shape: (N,32)。

代码

In the above code, X_train.shape(1) is 31 and Y_train.shape(1) is 32. When I used hyperparameter tuning, it says ValueError: Input 0 of layer lstm_1 is incompatible with the layer: expected ndim=3, found ndim=2.在上面的代码中,X_train.shape(1) 是 31,Y_train.shape(1) 是 32。当我使用超参数调整时,它说 ValueError: Input 0 of layer lstm_1 is incompatible with the layer: expected ndim=3, found ndim=2。 Full shape received: (None, 20).收到的完整形状:(无,20)。

Following Error exists:存在以下错误: 在此处输入图像描述

What I am missing and what is its issues.我错过了什么,它的问题是什么。

LSTM layers expects a 3D tensor input with the shape [batch, timesteps, feature]. LSTM 层需要一个 3D 张量输入,其形状为 [batch, timesteps, feature]。 Since you are using number of layers are a tuning parameter along with LSTM layers, when the number of LSTM layers is 2 and above, the LSTM layers after the first LSTM layer will also expect a 3D tensor as input which means that you will need to add the 'return_sequences=True' parameter to the setup so that the output tensor from previous LSTM layer has ndim=3 (ie batch size, timesteps, hidden state) which is fed into the next LSTM layer.由于您使用的层数是与 LSTM 层一起的调整参数,因此当 LSTM 层数为 2 及以上时,第一个 LSTM 层之后的 LSTM 层也将期望 3D 张量作为输入,这意味着您需要将 'return_sequences=True' 参数添加到设置中,以便来自前一个 LSTM 层的 output 张量具有 ndim=3(即批量大小、时间步长、隐藏状态),它被馈送到下一个 LSTM 层。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM