简体   繁体   English

在keras中设置模型的输入形状

[英]Set input shape of model in keras

I had saw other similar question on tensor flow but didn't match my problem. 我在张量流中看到了其他类似的问题,但与我的问题不符。

Model: 模型:

# picture size
img_row = 128
img_col = 647
shape = (img_row, img_col)

img = Input(input_shape)
...

with result 结果 模型

Data: 数据:

There has 1000 datas and each with shape (128, 647), and its a column of Dataframe df. 有1000个数据,每个数据的形状为(128,647),其数据框为df列。 Therefore, size result and data preview are as follow: 因此,大小结果和数据预览如下: 在此处输入图片说明 在此处输入图片说明

Problem 问题

The problem is: when I pass the Data to Model, some size error occured. 问题是:当我将数据传递给模型时,发生了一些大小错误。

train_history = model.fit(  x = df["data"],
                            y = df["genre_idx"],
                            validation_split = 0.1,
                            epochs = 30,
                            batch_size = 200,
                            verbose = 2
                         )

And error message are as follow: 错误信息如下:

Error when checking input: expected input_79 to have 3 dimensions, but got array with shape (1000, 1)

It might be a low question, but I didn't figure out what is the main problem of this situation and how to solve it. 这可能是一个很低的问题,但是我没有弄清楚这种情况的主要问题是什么以及如何解决。

You need to give it as a single ndarray which you can extract using the .values property of the data frame. 您需要将其作为单个ndarray给出 ,您可以使用数据框的.values属性对其进行提取。 The expected shape for the input is (1000, 128, 647) . 输入的预期形状为(1000, 128, 647)

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

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