Categories
Misc

Incompatible Shapes due to Batch Size

Hi all. I am trying to train a neural net to perform handwritten character recognition, and have attached the relevant code below. I’m training 28×28 size characters with the EMNIST dataset. No matter how what I change the batch size to, when I try to train the model, I always get a similar error at the bottom. Does anyone know how to fix this? Thank you for the help!

def load_dataset(): X_train = X_train.reshape((X_train.shape[0], 28, 28, 1)) X_test = X_test.reshape((X_test.shape[0], 28, 28, 1)) y_train = to_categorical(y_train) y_test = to_categorical(y_test) return X_train, y_train, X_test, y_test def prep_pixels(train, test): train_norm = train.astype('float32') test_norm = test.astype('float32') train_norm = train_norm/255.0 test_norm = test_norm/255.0 return train_norm, test_norm def define_model(): model = Sequential() model.add(Conv2D(32, (3,3), activation = 'relu', kernel_initializer = 'he_uniform', input_shape = (28, 28, 1))) model.add(MaxPooling2D((2,2))) model.add(Flatten()) model.add(Dense(100, activation = 'relu', kernel_initializer = 'he_uniform')) model.add(Dense(46, activation = 'softmax')) opt = SGD(learning_rate = 0.01, momentum = 0.9) model.compile(optimizer = opt, loss = 'categorical_crossentropy', metrics = ['accuracy']) return model def evaluate_model(dataX, dataY, xtest, ytest, n_folds = 5): model = define_model() history = model.fit(dataX, dataY, epochs = 4, batch_size = 64, validation_data = (xtest, ytest)) _, acc = model.evaluate(dataX, dataY, verbose=0) scores.append(acc) histories.append(history) 

‚Äč

 ValueError: Shapes (64, 1) and (64, 46) are incompatible 

EDIT: Fixed some bugs, but still have the same error

submitted by /u/landshark223344
[visit reddit] [comments]

Leave a Reply

Your email address will not be published.