lmoroney / dlaicourse

Notebooks for learning deep learning
5.66k stars 5.36k forks source link

Update for Adam optimizer compatibility on TF 2.0 #46

Open laurauzcategui opened 4 years ago

laurauzcategui commented 4 years ago

When running into Course 1 - Part 4 - Lesson 2 - Notebook with Tensorflow 2.0, ran into an issue with compile method when setting up the optimizer.

I think fix would be appropriate by setting the string instead of the tf.train.Adam

Error I ran into:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-17-3863a6d90e8a> in <module>
----> 1 model.compile(optimizer = tf.train.Adam(),
      2               loss = 'sparse_categorical_crossentropy',
      3               metrics=['accuracy'])
      4 
      5 model.fit(training_images, training_labels, epochs=5)

AttributeError: module 'tensorflow_core._api.v2.train' has no attribute 'Adam'

@lmoroney , I'll open a PR for this :)

lcarcamo1526 commented 4 years ago

You should use optimizer='adam', instead tf.train.Adam()