获取ValueError:训练RNN时无法将NumPy数组转换为张量(不支持的对象类型numpy.ndarray)

时间:2020-08-18 05:36:56

标签: numpy tensorflow keras lstm recurrent-neural-network

from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import Dropout
regressor=Sequential()
regressor.add(LSTM(units=50,return_sequences=True,input_shape=(X_train.shape[1],1)))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units=50,return_sequences=True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units=50,return_sequences=True))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units=50))
regressor.add(Dropout(0.2))
regressor.add(Dense(units=1))
regressor.compile(optimizer='adam',loss='mean_squared_error')
X_train = np.asarray(X_train).astype(np.float32)
regressor.fit(X_train,y_train,epochs=100,batch_size=32)

使用fit方法后,出现此错误:

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

如果有人有任何出路,请在这方面提供帮助

0 个答案:

没有答案