【发布时间】:2020-12-27 08:10:52
【问题描述】:
我的代码中有类似的问题,我写了一个简化版本:
我的模型有两个输入,但是无论我如何将数据发送到fit,它都不起作用。
这是问题的一个简短示例:
input1 = Input(shape=(1,), dtype='int64')
input2 = Input(shape=(1,), dtype='int64')
embeding1 = Embedding(1, 5, input_length=1, embeddings_regularizer=l2(1e-4) )(input1)
embeding2 = Embedding(1, 5, input_length=1, embeddings_regularizer=l2(1e-4) )(input2)
x = concatenate([embeding1, embeding2])
x = Flatten()(x)
x = Dense(1, activation='relu')(x)
model = Model([input1, input2],x)
model.compile(loss='mse', metrics=['accuracy'], optimizer='adam')
但我不知道如何跑步,我试过了:
history = model.fit(
[[1,1], [1,1], [1,1]],
[1,1,1]
)
认为样本中的每个项目都需要有一个包含其两个属性的列表, 但后来我收到了错误
ValueError: Layer model_3 expects 2 input(s), but it received 1 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, 2) dtype=int64>]
我也试过
history = model.fit(
[[1,1,1], [1,1,1]],
[1,1,1]
)
想也许我需要为每个功能提供两个列表。 错误:
ValueError: Data cardinality is ambiguous:
x sizes: 2
y sizes: 3
Make sure all arrays contain the same number of samples.
我还尝试了将[] 与() 切换的变体,使用np.array、np.stack
但我试过的都没有用...
【问题讨论】:
标签: tensorflow keras training-data