adriangb / scikeras

Scikit-Learn API wrapper for Keras.
https://www.adriangb.com/scikeras/
MIT License
239 stars 47 forks source link

AttributeError: 'Adam' object has no attribute 'build' #290

Closed ramtinmk closed 1 year ago

ramtinmk commented 1 year ago

I am attempting to convert a TensorFlow network to Keras and utilize the cross_val_predict function to evaluate my model. However, I am encountering an error and am unable to determine the cause.

def seq_model():
  model = tf.keras.Sequential([
      Embedding(embedding_matrix.shape[0], embedding_matrix.shape[1], weights=[embedding_matrix], trainable=False),
      Bidirectional(GRU(128,return_sequences=True)),
      Dropout(0.5),
      BatchNormalization(),
      Bidirectional(GRU(128,return_sequences=False)),
      Dropout(0.25),
      BatchNormalization(),
      Dense(64, activation='relu',kernel_regularizer='l2'),
      Dense(3,activation='softmax')
  ])

  model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(),
              optimizer="adam",
              metrics=['accuracy',tfa.metrics.F1Score(num_classes=3)])
  return model

model = seq_model()
model = KerasClassifier(model, epochs=10)
pred_probs = cross_val_predict(
    model,
    train_pad_sequence,
    y,
    cv=num_crossval_folds,
    method="predict_proba",
)
adriangb commented 1 year ago

What versions of SciKeras and TensorFlow are you using?

ramtinmk commented 1 year ago

Thank you for your help. I was running code on Colab and didn't notice that I was using TensorFlow (2.9.2). Once I upgraded to version 2.11.0, the issue was resolved.

adriangb commented 1 year ago

Great to hear!