2017-04-30 2 views
0

다른 클래스가있는 데이터 세트의 VGG16 모델을 미세 조정하려고합니다. this example에 따라,이처럼하려고 노력 :오류 "모델 객체에 'get_shape'속성이 없습니다. - Keras 모델 미세 조정

from keras.applications.vgg16 import VGG16 
from keras.models import Model 
from keras.layers import Dense, GlobalAveragePooling2D 
from keras import backend as K 

pretrained = VGG16(include_top=False, weights='imagenet') 
model = pretrained.output 

# Add new layers here 

model = Model(inputs=pretrained.input, outputs=model) 

을 그러나, 나는 모델에 새로운 레이어를 추가하는 데 문제가 있습니다. 라인 model = pretrained.output에 따라, 나는 (한 번에 하나의) 다음 줄의 각을 시도했다 : 나는 시도 처음 두 행에 대한

model = Flatten()(pretrained) 

model = MaxPooling2D((2,2), strides=(2,2))(pretrained) 

model = Dense(1024, activation='relu')(model) 

model = Convolution2D(32, 3, 3)(model) 

model = GlobalAveragePooling2D()(x) 

, 나는 각을 시도했을 때 나는 오류

AttributeError: 'Model' object has no attribute 'get_shape'  

있어 마지막 세 줄 중, 레이어의 크기와 관련된 오류가 발생할 때마다 (예 : 라인 model = Convolution2D(32, 3, 3)(model) 줬어 :

Error when checking target: expected conv2d_1 to have 4 dimensions, but got array with shape (38, 100) 

나는이 오류를 어떻게 수정합니까? 더 일반적으로 컨볼 루션 모델에 추가 할 수있는 레이어 유형을 어떻게 알 수 있습니까? - X 이전 계층 pretrained.output에 포함되어있는 신경 세포의 총 수는

model = Flatten()(pretrained) 

모델이 "평면"가되었으며 차원 [None, X]를 인수했다 :이 레이어를 추가 한 후

답변

0

.

그 이유는 명백히 모델의 모양이 "사각형"이 아니기 때문에 (예 : (None,3,28,20)과 같이) 컨볼 루션 및 풀링 레이어를 적용 할 수없는 이유입니다. 모든 것이 제대로 작동하려면 pretrained.output의 출력 크기를 결정한 다음 Flatten() 레이어가 없으면 필요한 크기의 커널을 사용하여 컨볼 루션 또는 풀링 작업을 적용해야합니다.