简体   繁体   English

检查目标时出错:预期 activation_6 有 3 个维度,但得到了形状为 (70612, 1) 的数组

[英]Error when checking target: expected activation_6 to have 3 dimensions, but got array with shape (70612, 1)

I Keep getting the error: Error when checking target: expected activation_6 to have 3 dimensions, but got array with shape (70612, 1).我不断收到错误:检查目标时出错:预期 activation_6 具有 3 个维度,但得到了形状为 (70612, 1) 的数组。 What could be the issue?可能是什么问题?

see below code:见下面的代码:

# CNN Model
model = Sequential()
model.add(Embedding(256, 8))

model.add(Conv1D(32, 3, activation="relu"))
model.add(MaxPooling1D(pool_size = (2)))
model.add(Conv1D(32, 3, activation="relu"))
model.add(MaxPooling1D(pool_size =(2)))


model.add(Dense(64)
model.add(Dropout(0.5))
model.add(Dense(2))
model.add(Activation("softmax"))

model.compile(loss="categorical_crossentropy", optimizer ="adam", metrics = ["accuracy"])

**Model Summary:**

Model: "sequential_37"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
embedding_37 (Embedding)     (None, None, 8)           2048      
_________________________________________________________________
conv1d_47 (Conv1D)           (None, None, 32)          800       
_________________________________________________________________
max_pooling1d_43 (MaxPooling (None, None, 32)          0         
_________________________________________________________________
conv1d_48 (Conv1D)           (None, None, 32)          3104      
_________________________________________________________________
max_pooling1d_44 (MaxPooling (None, None, 32)          0         
_________________________________________________________________
dense_34 (Dense)             (None, None, 64)          2112      
_________________________________________________________________
dropout_18 (Dropout)         (None, None, 64)          0         
_________________________________________________________________
dense_35 (Dense)             (None, None, 2)           130       
_________________________________________________________________
activation_12 (Activation)   (None, None, 2)           0         
=================================================================

Your last layer has 3 dimension, it should have been 2 (batch, n_class) .你的最后一层有 3 维,它应该是 2 (batch, n_class)

activation_12 (Activation) (None, None, 2) 0

You need to add a Flatten() layer before您需要先添加一个Flatten()

model.add(Dense(64)

Another issue is you have your labels with shape (batch, 1) .另一个问题是您的标签带有形状(batch, 1)

You need to use sigmoid instead of softmax (assuming binary classification).您需要使用sigmoid而不是softmax (假设二进制分类)。

Also, change the shape of x and y.此外,更改 x 和 y 的形状。

x = x.reshape((-1, 533, 1)) y = y.reshape(-1,1) x = x.reshape((-1, 533, 1)) y = y.reshape(-1,1)

model = Sequential()
model.add(Embedding(256, 8, input_length = 533))

model.add(Conv1D(32, 3, activation="relu"))
model.add(MaxPooling1D(pool_size = (2)))
model.add(Conv1D(32, 3, activation="relu"))
model.add(MaxPooling1D(pool_size =(2)))

model.add(Flatten())
model.add(Dense(64)
model.add(Dropout(0.5))
model.add(Dense(1)) # 1
model.add(Activation("sigmoid"))

model.compile(loss="binary_crossentropy", optimizer ="adam", metrics = ["accuracy"])

暂无
暂无

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

相关问题 ValuError:检查目标时出错:预期activation_6具有形状(70,)但得到形状为(71,)的数组 - ValuError: Error when checking target: expected activation_6 to have shape (70,) but got array with shape (71,) ValueError:检查目标时出错:预期 activation_6 具有形状(70,)但得到形状为(71,)的数组 - ValueError: Error when checking target: expected activation_6 to have shape (70,) but got array with shape (71,) ValueError:检查目标时出错:预期 activation_10 有 2 个维度,但得到了形状为 (118, 50, 1) 的数组 - ValueError: Error when checking target: expected activation_10 to have 2 dimensions, but got array with shape (118, 50, 1) 如何在检查目标时修复错误:预期 activation_5 有 2 个维度,但得到了形状为 (24943, 50, 50, 1) 的数组 - How to fix Error when checking target: expected activation_5 to have 2 dimensions, but got array with shape (24943, 50, 50, 1) Keras(FIT_GENERATOR)- 检查目标时出错:预期 activation_1 具有 3 个维度,但得到的数组形状为 (32, 416, 608, 3) - Keras(FIT_GENERATOR)- Error, when checking target: expected activation_1 to have 3 dimensions, but got array with shape (32, 416, 608, 3) Keras fit_generator:检查目标时出错:预期activation_32具有4个维,但数组的形状为(4,4) - Keras fit_generator : Error when checking target: expected activation_32 to have 4 dimensions, but got array with shape (4, 4) ValueError:检查目标时出错:预期激活具有形状 (1,) 但得到形状为 (2,) 的数组 - ValueError: Error when checking target: expected activation to have shape (1,) but got array with shape (2,) Keras-检查目标时出错:预期activation_5具有形状(2,),但数组的形状为(1,) - Keras - Error when checking target: expected activation_5 to have shape (2,) but got array with shape (1,) Keras - “ValueError:检查目标时出错:预期activation_1具有形状(无,9)但得到的数组具有形状(9,1) - Keras - "ValueError: Error when checking target: expected activation_1 to have shape (None, 9) but got array with shape (9,1) ValueError:检查目标时出错:预期 activation_9 具有形状 (74, 6) 但得到形状为 (75, 6) 的数组 - ValueError: Error when checking target: expected activation_9 to have shape (74, 6) but got array with shape (75, 6)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM