0
votes
 
What's wrong with this code?      
 faces = datasets.fetch_olivetti_faces()
    X_train, X_test, y_train, y_test = train_test_split(faces.data,faces.target, test_size=0.2)
    X_train = X_train.reshape(-1,32 ,32 ,1)
    X_test = X_test.reshape(-1,32 , 32 ,1)
    # Normalize the data
    X_train = X_train.astype('float32')
    X_test = X_test.astype('float32')
    X_train /= 255.0
    X_test /= 255.0
    # One hot 
    classes=40
    y_train = keras.utils.to_categorical(y_train, classes)
    y_test = keras.utils.to_categorical(y_test, classes)
    #Build LetNet model with Keras
    def LetNet(width, height, depth, classes):
      # initialize the model
      model = Sequential()
      # first layer, convolution and pooling
      model.add(Conv2D(input_shape=(width, height, depth), kernel_size=(5, 5), filters=6, strides=(1,1), activation='tanh'))
      model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))

      # second layer, convolution and pooling
      model.add(Conv2D(input_shape=(width, height, depth), kernel_size=(5, 5), filters=16, strides=(1,1), activation='tanh'))
      model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
      # Fully connection layer
      model.add(Flatten())
      model.add(Dense(120,activation = 'tanh'))
      model.add(Dense(84,activation = 'tanh'))
      # softmax classifier
      model.add(Dense(classes))
      model.add(Activation("softmax"))
      return model
    LetNet_model = LetNet(32,32,1,40)
    LetNet_model.summary() 
    #Strat training
    LetNet_model.compile(optimizer=Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08),loss = 'categorical_crossentropy',metrics=['accuracy'])
    History = LetNet_model.fit(X_train, y_train, epochs=5, batch_size=32,validation_data=(X_test, y_test))

1
Can you print X_train.shape, y_train.shape?Zabir Al Nazi

1 Answers

1
votes

My calculations say, your input images have shape 64 by 64 with 1 channel instead of 32 by 32.

You can change the following lines.

    X_train = X_train.reshape(-1, 64 ,64 ,1)
    X_test = X_test.reshape(-1, 64 , 64 ,1)

Also, change your model inputs.

LetNet_model = LetNet(64,64,1,40)