简体   繁体   English

ValueError:检查模型目标时出错:预期activation_2具有形状(无,761,1)但是具有形状的数组(1,779,1)

[英]ValueError: Error when checking model target: expected activation_2 to have shape (None, 761, 1) but got array with shape (1, 779, 1)

I have the following error statement... 我有以下错误声明......

ValueError: Error when checking model target: expected activation_2 to have shape (None, 761, 1) but got array with shape (1, 779, 1)

In errors, I don't know what the number 761 means, my data1 's shape is 779 * 80 , my data3 's shape is 779 * 1 . 在错误中,我不知道761的数字意味着什么,我的data1的形状是779 * 80 ,我的data3的形状是779 * 1 Thank you for your help! 谢谢您的帮助!

from __future__ import print_function
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential

from keras.layers import Dense, \
                         Dropout, \
                         Activation, \
                         Flatten

from keras.layers import Convolution1D, \
                         MaxPooling2D, \
                         Convolution2D

from keras.utils import np_utils

import scipy.io as sio
import numpy as np

matfn = 'LIVE_data.mat'

data = sio.loadmat(matfn) 
data0 = data['data']
data1 = np.ones((1, 779, 80))
data1[0, :, :] = data0
data00 = data['label']
data2 = np.ones((1,779,1))
data2[0, :, :] = data00
data000 = data['ref_ind_live']
data3 = np.ones((1, 779, 1))
data3[0, :, :] = data000
batch_size = 64
nb_classes = 30
nb_epoch = 50

X_train = data1
y_train = data3
X_test = data1[0, :]
y_test = data3[0, :]

X_train = X_train.astype('double')
X_test = X_test.astype('double')
X_train /= 255
X_test /= 255

# Convert class vectors to binary class matrices.
Y_train = np_utils.to_categorical(y_train, nb_classes)
Y_test = np_utils.to_categorical(y_test, nb_classes)

model = Sequential()

model.add(Convolution1D(32, \
                        10, \
                        border_mode = 'same', \
                        input_shape = (779, \
                                       80)))
model.add(Activation('relu'))
model.add(Convolution1D(64, \
                        10, \
                        activation='relu'))
model.add(Dropout(0.25))
model.add(Convolution1D(128, \
                        10, \
                        activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('softmax'))

# Let's train the model using RMSprop
model.compile(loss = 'categorical_crossentropy', \
              optimizer = 'rmsprop', \
              metrics=['accuracy'])

print("start train")

model.fit(X_train, \
          Y_train, \
          batch_size = batch_size, \
          nb_epoch = nb_epoch, \
          shuffle = True)

print("end")

score = model.evaluate(X_test, \
                       Y_test, \
                       batch_size = 32)

print('Test score:', \
      score[0])
print('Test accuracy:', \
      score[1])

Your model output shape is (779, 1) and same shape is expected in final layer but due to 2 convolution operation that reduced to 761. So by adding border_mode = 'same' in other 2 convolution layer would solve the problem. 您的模型输出形状为(779, 1)并且在最终层中预期相同的形状,但由于2卷积运算减少到761.因此,通过在其他2个卷积层中添加border_mode = 'same'将解决问题。

You can check in Model summary: 您可以登记模型摘要:


Layer (type) Output Shape Param # 图层(类型)输出形状参数#

conv1d_1 (Conv1D) (None, 779, 32) 25632 conv1d_1(Conv1D)(无,779,32)25632


activation_1 (Activation) (None, 779, 32) 0 activation_1(激活)(无,779,32)0


conv1d_2 (Conv1D) (None, 770, 64) 20544 conv1d_2(Conv1D)(无,770,64)20544


dropout_1 (Dropout) (None, 770, 64) 0 dropout_1(Dropout)(无,770,64)0


conv1d_3 (Conv1D) (None, 761, 128) 82048 conv1d_3(Conv1D)(无,761,128)82048


dropout_2 (Dropout) (None, 761, 128) 0 dropout_2(Dropout)(无,761,128)0


dense_13 (Dense) (None, 761, 1) 129 dense_13(密集)(无,761,1)129


activation_2 (Activation) (None, 761, 1) 0 activation_2(激活)(无,761,1)0

暂无
暂无

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

相关问题 检查目标时出错:预期的activation_2的形状为(512,),但数组的形状为(1,) - Error when checking target: expected activation_2 to have shape (512,) 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) 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:检查目标时出错:预期 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:检查目标时出错:预期激活具有形状 (1,) 但得到形状为 (2,) 的数组 - ValueError: Error when checking target: expected activation to have shape (1,) but got array with shape (2,) ValueError:检查目标时出错:预期activation_5 的形状为(1,),但数组的形状为(100,) - ValueError: Error when checking target: expected activation_5 to have shape (1,) but got array with shape (100,) ValueError:检查目标时出错:预期density_13具有形状(None,6),但数组形状为(6,1) - ValueError: Error when checking target: expected dense_13 to have shape (None, 6) but got array with shape (6, 1) ValueError:检查目标时出错:期望的model_2具有形状(无,252,252,1)但是具有形状的数组(300,128,128,3) - ValueError: Error when checking target: expected model_2 to have shape (None, 252, 252, 1) but got array with shape (300, 128, 128, 3)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM