检查输入时出错:预期density_34_input具有形状(33,),但数组形状为(1,)

时间:2020-05-18 15:11:36

标签: python pandas numpy tensorflow keras

我想在训练有素的模型上插入数组,但出现此错误

Error when checking input: expected dense_34_input to have shape (33,) but got array with shape (1,)

我重现此问题的代码是:

    def start(self):
        self.df = pd.read_csv('data_use.csv')
        self.all_Algorithm = self.df
        d = 0
        self.ResultArray = self.all_Algorithm.loc[1+d:11+d]
        self.reversed_df = self.ResultArray.iloc[::-1]
        print(self.reversed_df)
        model = load_model('trained_model.h5')
        model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

        self.Array = pd.DataFrame() 
        for i in range(1,12):
            print(i)
            g = i * 3 - 2
            self.Array.at[g,'RowForInput'] = self.reversed_df.loc[i,'weight']
            self.Array.at[g+1,'RowForInput'] = self.reversed_df.loc[i,'Size']
            self.Array.at[g+2,'RowForInput'] = self.reversed_df.loc[i,'Age']
        print(self.Array.shape)

        results = model.predict(self.Array)
        print('test loss, test acc:', results)

有人可以帮忙吗?

修改

根据评论,我更改了初始化数组的方式,但是现在出现以下错误:

 Error when checking input: expected dense_34_input to have shape (33,) but got array with shape (0,)

1 个答案:

答案 0 :(得分:0)

为什么用空列self.Array初始化Email?从您的代码看来,您似乎不需要它。如果是这样,您可以改为

self.Array = pd.DataFrame() 

如果您真的在其他地方需要它(尽管将Emaildtype='float32'一起使用是没有意义的),请执行

results = model.predict(self.Array.iloc[:,1:]