将numpy数组从2D转换为3D

时间:2017-06-01 06:06:35

标签: python numpy keras

我尝试将2D numpy数组输入到基于3D数据集的模型中,但是我收到以下错误:

ValueError: Error when checking : expected gru_1_input to have 3 dimensions, but got array with shape (37L, 2L)

所以我扩展轴以尝试解决错误但是我得到一个新的错误:

ValueError: Error when checking : expected gru_1_input to have shape (None, None, 1) but got array with shape (1L, 37L, 2L)

我不确定如何解决这个问题,并且没有重新调整模型的技能而不会破坏某些东西。这是迄今为止从模型中产生预测的代码:

#Load in Libraries
import keras.models
import numpy as np
import matplotlib.pyplot as plt

##Input data
#a = np.random.random([1,24,1])

# Load CSV
filename = 'test1.csv'
raw_data = open(filename, 'rt')
b = np.loadtxt(raw_data, delimiter=",")
a = np.expand_dims(b, axis=0)


#Loads model and predicts forecast for future 12 points based on input data
MDL_NAME = "gru_relu"
model = keras.models.load_model("models/%s.mdl" % MDL_NAME)
pred = model.predict(a, batch_size=1, verbose=0)

#Plots the input data and forecast
plt.plot(pred[0], "b-o", label="Prediction")
plt.plot(a[0], "r-o", label="Past")

plt.show()

0 个答案:

没有答案