Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
Keras model using GridSearchCV stuck in infinite loop

I have a keras model and I use sklearn.model_selection.GridSearchCV for tuning the hyperparameters, but it gets stuck in an infinite loop.

This is my model:

from keras import Sequential
from keras.layers import Dense, Activation

def make_model(optimizer='rmsprop'):
  model = Sequential()
  model.add(Dense(9, activation='relu', input_dim=28 * 28))
  model.add(Dense(27 , activation='relu'))
  model.add(Dense(27 , activation='relu'))
  model.add(Dense(81 , activation='relu'))
  model.add(Dense(10, activation='softmax'))
  model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics='acc')
  return model
from sklearn.model_selection import GridSearchCV
from keras.wrappers.scikit_learn import KerasClassifier

model = KerasClassifier(build_fn=make_model)

param_grid=dict(
    optimizer=['rmsprop'], 
    epochs=[25, 40], 
    batch_size=[45],
    validation_split=[.2])

grid_model = GridSearchCV(estimator=model, param_grid=param_grid)

And when I call fit on the model, instead of running with 25 and 40 epochs it will get stuck in an infinite loop.

I used keras.datasets.fashion_mnist as my dataset as below:

from keras.utils.np_utils import to_categorical


(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()

y_train = to_categorical(train_labels, num_classes=10)
y_test = to_categorical(test_labels, num_classes=10)

x_train = train_images / 255.0
x_test  = test_images / 255.0

x_train = x_train.reshape(60000, -1)
x_test = x_test.reshape(10000, -1)

I have used epochs=[2, 3] to representing the loop, and rest of the code as the same as before.

It's the result: enter image description here

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!