简体   繁体   English

ValueError:检查目标时出错:预期activation_5 的形状为(1,),但数组的形状为(100,)

[英]ValueError: Error when checking target: expected activation_5 to have shape (1,) but got array with shape (100,)

I'm currently trying to train a LSTM network with sequential video data.我目前正在尝试使用顺序视频数据训练 LSTM 网络。 The problem that keeps occurring now though is an error with the output shape of the data itself.不过,现在不断发生的问题是数据本身的 output 形状存在错误。 From the video, I have generated 686 sample clips of 100 time steps (frames).从视频中,我生成了 100 个时间步长(帧)的 686 个样本片段。 Then with another CNN, I've created an embedding of shape 2048 of each image.然后使用另一个 CNN,我创建了每个图像的形状 2048 的嵌入。 In other words, the shape of X_train in my case is (686,100,2048) and the shape of Y_train is (686,100).换句话说,在我的例子中,X_train 的形状是 (686,100,2048),而 Y_train 的形状是 (686,100)。 Now when I pass my dataset through my network, I get this shape error.现在,当我通过我的网络传递我的数据集时,我得到了这个形状错误。

My model:我的 model:

from keras.layers import Activation, Input, Dense, Lambda, LSTM, Flatten
from keras.models import Model



def model_builder(input_shape):
    base_input = Input(shape = input_shape)
    x = LSTM(units=50, name='LSTM1', return_sequences=True)(base_input)
    x = Flatten()(x)
    x = Dense(units = 3)(x)
    x = Activation('softmax')(x)
    classification_model = Model(base_input, x,name='classifier')
    classification_model.compile(loss='sparse_categorical_crossentropy',optimizer='adam',metrics=['accuracy'])

    return classification_model

And I run it like this:我像这样运行它:

batch_size = 64
epochs = 20
timesteps = 100
embedding_shape=2048

classification_model = model_builder((timesteps,embedding_shape))

try:
    Y_train=Y_train.reshape((686,timesteps))
    X_train = np.reshape(X_train,(686, timesteps,embedding_shape))

    outcome = classification_model.fit(x=X_train, y=Y_train, batch_size=batch_size, epochs=epochs, verbose=1, callbacks=None, validation_split=(6200/68600), validation_data=None, shuffle=False, class_weight=None, sample_weight=None, initial_epoch=0, steps_per_epoch=None, validation_steps=None, validation_freq=1)

except KeyboardInterrupt:
    pass

Resulting in this error message:导致此错误消息: 在此处输入图像描述

Any ideas as to what I might be doing wrong?关于我可能做错了什么的任何想法?

Model Summary: Model 总结: 在此处输入图像描述

Without checking your code in depth, 99% of this Errors occur if you have the false loss function.如果没有深入检查您的代码,如果您有错误丢失 function,则会发生 99% 的此类错误。

Please modify your model compilation with the loss='categorical_crossentropy' instead of loss='sparse_categorical_crossentropy':请使用 loss='categorical_crossentropy' 而不是 loss='sparse_categorical_crossentropy' 修改您的 model 编译:

classification_model.compile(loss='categorical_crossentropy',........)

The difference is the encodings of you targets.不同之处在于您的目标的编码。 If your targets are one-hot encoded, use categorical_crossentropy.如果您的目标是一次性编码的,请使用 categorical_crossentropy。

暂无
暂无

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

相关问题 Keras-检查目标时出错:预期activation_5具有形状(2,),但数组的形状为(1,) - Keras - Error when checking target: expected activation_5 to have shape (2,) but got array with shape (1,) 检查目标时出错:预期 activation_5 的形状为 (1,) 但得到的数组的形状为 (2,) - Error when checking target: expected activation_5 to have shape (1,) but got array with shape (2,) 如何在检查目标时修复错误:预期 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:ValueError:检查模型目标时出错:预期activation_1具有形状(无,60),但数组的形状为(10,100) - keras: ValueError: Error when checking model target: expected activation_1 to have shape (None, 60) but got array with shape (10, 100) ValueError:检查目标时出错:预期激活具有形状 (1,) 但得到形状为 (2,) 的数组 - ValueError: Error when checking target: expected activation to have shape (1,) but got array with shape (2,) 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) ValueError:检查目标时出错:预期activation_1的形状为(158,),但数组的形状为(121,) - ValueError: Error when checking target: expected activation_1 to have shape (158,) but got array with shape (121,) 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)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM