【发布时间】:2019-10-29 03:00:28
【问题描述】:
这是我第一次使用 keras,我正在尝试按照我在网上找到的教程并将我自己的数据适合它。我有一个矩阵和二进制标签。
> str(d_train)
num [1:1062, 1:180] -0.04748 0.04607 -0.05429 -0.0126 -0.00219 ...
> str(trainlabels)
num [1:1062, 1:2] 0 0 0 0 0 0 1 0 0 0 ...
我的代码:
model = keras_model_sequential()
model %>%
layer_dense(units = 8, activation = 'relu', input_shape = c(180)) %>%
layer_dense(units = 3, activation = "softmax")
summary(model)
## Compile
model %>%
compile(loss = "binary_crossentropy",
optimizer = "adam",
metrics = "accuracy")
## Fit model
history = model %>%
fit(d_train,
trainlabels,
epoch=200,
batch_size=32,
validation_split=0.2)
我似乎无法适应模型,我收到以下错误消息:
Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: A target array with shape (1062, 2) was passed for an output of shape (None, 3) while using as loss `binary_crossentropy`. This loss expects targets to have the same shape as the output.
根据错误消息,要求输入数组的不同形状,我尝试更改尺寸但没有运气。
【问题讨论】:
标签: r tensorflow keras neural-network