2017-12-16 23 views
2

안녕하세요 저는 일류 분류를위한 이미지 분류기를 구축하고 있습니다. (autoencoder_model.fit) (ValueError : 대상을 검사 할 때 오류가 발생했습니다 : shape_2 (없음, 252, 252, 1)을 가질 것으로 예상되는 model_2에 배열이 있습니다. 모양 (300, 128, 128, 3).)ValueError : target : expected model_2에 shape (None, 252, 252, 1)가 있지만 shape (300, 128, 128, 3) 배열이 있습니다.

num_of_samples = img_data.shape[0] 
labels = np.ones((num_of_samples,),dtype='int64') 



labels[0:376]=0 
names = ['cats'] 


input_shape=img_data[0].shape 



X_train, X_test = train_test_split(img_data, test_size=0.2, random_state=2) 


inputTensor = Input(input_shape) 
x = Conv2D(16, (3, 3), activation='relu', padding='same')(inputTensor) 
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x) 
x = MaxPooling2D((2, 2), padding='same')(x) 
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x) 
encoded_data = MaxPooling2D((2, 2), padding='same')(x) 

encoder_model = Model(inputTensor,encoded_data) 

# at this point the representation is (4, 4, 8) i.e. 128-dimensional 
encoded_input = Input((4,4,8)) 
x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded_input) 
x = UpSampling2D((2, 2))(x) 
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x) 
x = UpSampling2D((2, 2))(x) 
x = Conv2D(16, (3, 3), activation='relu',padding='same')(x) 
x = UpSampling2D((2, 2))(x) 
decoded_data = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x) 

decoder_model = Model(encoded_input,decoded_data) 

autoencoder_input = Input(input_shape) 
encoded = encoder_model(autoencoder_input) 
decoded = decoder_model(encoded) 
autoencoder_model = Model(autoencoder_input, decoded) 
autoencoder_model.compile(optimizer='adadelta', 
`enter code here`loss='binary_crossentropy') 


autoencoder_model.fit(X_train, X_train, 
      epochs=50, 
      batch_size=32, 
      validation_data=(X_test, X_test), 
      callbacks=[TensorBoard(log_dir='/tmp/autoencoder')]) 
+1

이미지의 크기는 어느 정도입니까? 'input_shape'와'img_data.shape'을 출력하고 당신이 기대하는 것을 검사 할 수 있습니까? 그것이'autoencoder_model.summary()와 일치하는지 확인하십시오. – ncfirth

+0

무엇을하고 있는지 알려주세요. –

+0

input_shape - (128, 128, 3), img_data.shape - (376, 128, 128, 3) –

답변

1

디코더의 출력 모양과 훈련 데이터의 모양이 서로 호환되지 않습니다. (목표는 출력을 의미 함).

2 개의 MaxPoolings (이미지 크기를 4로 나눈 값) 및 3 개의 업 샘플링 (디코더의 입력에 8을 곱한 값)이 있습니다.

자동 인코딩 장치의 최종 출력이 너무 커서 사용자 데이터와 일치하지 않습니다. 출력 모양을 교육 데이터와 일치 시키려면 모델에서 작업해야합니다.

+0

대니얼 :) –

0

당신이 사용하고있는 잘못된 API

autoencoder_model.fit(X_train, X_train, <--- This one is wrong 
     epochs=50, 
     batch_size=32, 
     validation_data=(X_test, X_test), 
     callbacks=[TensorBoard(log_dir='/tmp/autoencoder')]) 

것은 .fit에서보세요 https://github.com/keras-team/keras/blob/master/keras/models.py

def fit(self, 
     x=None, 
     y=None, 
     batch_size=None, 
     epochs=1, 
     verbose=1, 
     callbacks=None, 
     validation_split=0., 
     validation_data=None, 
     shuffle=True, 
     class_weight=None, 
     sample_weight=None, 
     initial_epoch=0, 
     steps_per_epoch=None, 
     validation_steps=None, 
     **kwargs): 
    """Trains the model for a fixed number of epochs (iterations on a dataset). 
    # Arguments 
     x: Numpy array of training data. 
      If the input layer in the model is named, you can also pass a 
      dictionary mapping the input name to a Numpy array. 
      `x` can be `None` (default) if feeding from 
      framework-native tensors (e.g. TensorFlow data tensors). 
     y: Numpy array of target (label) data. 
      If the output layer in the model is named, you can also pass a 
      dictionary mapping the output name to a Numpy array. 
      `y` can be `None` (default) if feeding from 
      framework-native tensors (e.g. TensorFlow data tensors). 

방법에서 소스 코드가 있도록 X 데이터되어야하고, Y는 상기 데이터의 라벨이 될 것이다. 도움이 되길 바랍니다

+0

아니요 자동 게시자 btw 게시 해 주셔서 감사합니다 –