Keras模型曲解了输入数据的形状

时间:2019-03-07 23:01:24

标签: python tensorflow keras

我有一个生成器,它yield {'ingredients': ingredients, 'documents': documents}, labels包含以下内容:

ingredients.shape (10, 46) documents.shape (10, 46) labels.shape (10,)

yield'd迭代器具有以下形状:

ValueError: Error when checking input: expected ingredients to have shape (1,) but got array with shape (46,)

在完成该迭代器的建模后,我将得到以下信息:

# Both inputs are 1-dimensional ingredients = Input( name='ingredients', shape=[1] ) # ingredients.shape (?, 1) documents = Input( name='documents', shape=[1] ) # documents.shape (?, 1) logger.info('ingredients %s documents shape %s', ingredients.shape, documents.shape) ingredients_embedding = Embedding(name='ingredients_embedding', input_dim=training_size, output_dim=embedded_document_size)(ingredients) # Embedding the document (shape will be (None, 1, embedding_size)) document_embedding = Embedding(name='documents_embedding', input_dim=training_size, output_dim=embedded_document_size)(documents)

下面是产生上述错误的模型代码:

const arr = ['A',true,'B',true,'C',true,'D',true,'E','A',true,'B',true,'C',false,'E','A',true,'B',false,'E'];

const result = arr.reduce((acc, x) => {
  acc[acc.length-1].push(x)
  if (x === 'E') acc.push([]);
  return acc;
}, [[]]).filter(x => x.length);

console.log(result);

1 个答案:

答案 0 :(得分:1)

input_shapeingredients输入层中提到的documents是(1)。但是,成分的形状是(10,46),文档的形状是(10,46)。这里是10个样本。

您正在初始化模型以使其具有形状输入(None,1)。应该是(None,46)。因此,您可以进行这些更改。

ingredients = Input( name='ingredients', shape=( 46 , ) ) 
documents = Input( name='documents', shape=( 46 , )

这应该可以修复错误。实际上,输入具有46个尺寸或46个特征。