I am makinga Neural Network for a stomach tissue dataset. The idea is that I want to optimize parameters for my model, so I run KerasClassifier to change parameters for model. So I was trying to run my code, but I am stuck with an error:
“‘KerasClassifier’ object has no attribute ‘call‘ “
(Also, I am sorry if there are any grammar mistakes. English is not my first language. Also, this is my first time using StackOverflow for questions as well)
Code is below:
params={
'batch_size':[50, 100],
'epochs':[50,70],
'model_neurons_1':[500,300],
'model_neurons_2':[100,40],
'model_dropout':[0.1,0.2],
'model_learning_rate' : [0.01, 0.001, 0.0001]
}
def get_mlp_model(neurons_1,neurons_2 ,dropout, learning_rate):
# initialize a sequential model and add layer to flatten the
# input data
model6 = Sequential()
model6.add(Dense(neurons_1, activation="relu",
input_shape=(56200,)))
model6.add(Dropout(dropout))
model6.add(Dense(neurons_2, activation="relu"))
model6.add(Dropout(dropout))
# add a softmax layer on top
model6.add(Dense(6, activation="softmax"))
# compile the model
model6.compile(optimizer=Adam(learning_rate = learning_rate), loss="sparse_categorical_crossentropy", metrics=["accuracy"])
return model6
print("[INFO] initializing model...")
model = KerasClassifier(model = get_mlp_model, verbose=0)
print("[INFO] performing random search...")
searcher = GridSearchCV(estimator=model,param_grid=params,scoring='accuracy',cv=3, n_jobs= 1 ,return_train_score=True,verbose=0)
searchResults = searcher.fit(X_train, y_train, validation_data=(X_test, y_test), epochs = 100, batch_size = 20, callbacks = [es])
bestScore = searchResults.best_score_
bestParams = searchResults.best_params_
print("[INFO] best score is {:.2f} using {}".format(bestScore,
bestParams))
print("[INFO] evaluating the best model...")
bestModel = searchResults.best_estimator_
accuracy = bestModel.score(X_train, y_train)
print("accuracy: {:.2f}%".format(accuracy * 100))
`
Currently, I have tried changing versions, changing a couple lines of my code, but nothing is really working. Any suggestions would be greatly appreciated.
Kaeki Cookie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.