2017-02-07 5 views
2

Keras (테아 노 백엔드)의 일부 연습을 통해 CNN을 이해하려고합니다. 아래 모델을 적용 할 수 없습니다 (오류 : AttributeError : 'Convolution2D'객체에 'get_shape'속성이 없습니다). 이 데이터 세트는 최대 5 개의 이미지에 대해 함께 연결된 MNIST 데이터의 이미지 (28 * 28)입니다. 따라서 입력 모양은 1, 28, 140이어야합니다 (회색 명암 = 1, 높이 = 28, 너비 = 28 * 5)여러 자릿수 인식을위한 Keras

목표는 숫자의 순서를 예측하는 것입니다. 고맙습니다!!

batch_size = 128 
nb_classes = 10 
nb_epoch = 2 

img_rows =28 
img_cols=140 
img_channels = 1 

model_input=(img_channels, img_rows, img_cols) 

x = Convolution2D(32, 3, 3, border_mode='same')(model_input) 
x = Activation('relu')(x) 
x = Convolution2D(32, 3, 3)(x) 
x = Activation('relu')(x) 
x = MaxPooling2D(pool_size=(2, 2))(x) 
x = Dropout(0.25)(x) 
conv_out = Flatten()(x) 

x1 = Dense(nb_classes, activation='softmax')(conv_out) 
x2 = Dense(nb_classes, activation='softmax')(conv_out) 
x3 = Dense(nb_classes, activation='softmax')(conv_out) 
x4 = Dense(nb_classes, activation='softmax')(conv_out) 
x5 = Dense(nb_classes, activation='softmax')(conv_out) 

lst = [x1, x2, x3, x4, x5] 

model = Sequential(input=model_input, output=lst) 

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

model.fit(dataset, data_labels, batch_size=batch_size, nb_epoch=nb_epoch, verbose=1) 

답변

4

문제는 입력 레이어에 있습니다. 다음과 같이 변경을 수행

model_input=Input(shape=(img_channels, img_rows, img_cols)) 

image_dim_orderingth 제공된다. Input 레이어를 keras.layers에서 가져옵니다.

출력이 여러 개인 경우도 있습니다. 따라서 Sequential 대신 Function 모델을 사용해야합니다. keras.models에서

model = Model(input=model_input, output=lst) 

가져 오기 Model : 그냥으로 변경합니다.

+0

답변 해 주셔서 감사합니다. 나는 여전히 텐서 객체가 반복 가능하지 않다는 것을 알고있다. –

+0

'model.fit()'에서 오류가 발생했습니다. 그렇다면 내 생각에'data_labels'는 길이가 5 인 numpy 배열의리스트 여야합니다. numpy 배열은 각각 차원 'dataset.shape [0] x nb_classes'이어야합니다. – indraforyou

+0

오류가 활성화 레이어에 있습니다. 다음은 전체 코드 링크입니다. https://gist.github.com/jdills26/ca69e59ef19d4993636f6b50a7cbe514 도움 주셔서 감사합니다! 데이터 소스는 다음과 같습니다. http://yann.lecun.com/exdb/mnist/index.html –