title: set_model() missing 1 required positional argument: 'model'
body: <p>I'm have created a Keras Sequential Model and am using Adam optimizer. I wished to get the learning rate after every epoch. This <a href="https://stackoverflow.com/questions/47490834/how-can-i-print-the-learning-rate-at-each-epoch-with-adam-optimizer-in-keras">stackoverflow question</a> seem to answer my question. However, when I followed the solution mentioned, I get the following error</p>
  
  <pre><code>set_model() missing 1 required positional argument: 'model'
  </code></pre>
  
  <p>Here's my code to create a model:</p>
  
  <pre><code>model = Sequential()
  
  model.add(Conv2D(64, (5, 5), input_shape=(IMG_HEIGHT, IMG_WIDTH, 3), activation='relu'))
  
  model.add(Conv2D(64, (5, 5), activation='relu'))
  model.add(MaxPooling2D((2, 2)))
  model.add(Dropout(0.2))
  
  model.add(Conv2D(128, (5, 5), activation='relu'))
  model.add(Conv2D(128, (5, 5), activation='relu'))
  model.add(MaxPooling2D((2, 2)))
  model.add(Dropout(0.2))
  
  model.add(Conv2D(256, (5, 5), activation='relu'))
  model.add(Conv2D(256, (5, 5), activation='relu'))
  model.add(MaxPooling2D((2, 2)))
  model.add(BatchNormalization(axis=3))
  model.add(Dropout(0.2))
  
  model.add(Flatten())
  model.add(Dense(256, activation='relu'))
  
  model.add(Dropout(0.5))
  
  model.add(Dense(256, activation='relu'))
  
  model.add(Dropout(0.5))
  model.add(Dense(10, activation='softmax'))
  
  model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
  
  learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc', 
                                              patience=3, 
                                              verbose=1, 
                                              factor=0.4, 
                                              min_lr=0.0001)
  csvlogger = CSVLogger("solution.csv", separator='\t')
  checkpoint = ModelCheckpoint("models/best_model5.h5", monitor="val_acc", save_best_only=True, mode='max')
  learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc', 
                                              patience=3, 
                                              verbose=1, 
                                              factor=0.4, 
                                              min_lr=0.00001)
  
  class MyCallback(keras.callbacks.Callback):
      def on_epoch_end(self, epoch, logs=None):
          lr = self.model.optimizer.lr
          decay = self.model.optimizer.decay
          iterations = self.model.optimizer.iterations
          lr_with_decay = lr / (1. + decay * K.cast(iterations, K.dtype(decay)))
          print(K.eval(lr_with_decay))
  
  model.fit_generator(datagen.flow(x_train, y_train, batch_size=75), 
                             epochs=10, validation_data=(x_validation, y_test),verbose=1, 
                             steps_per_epoch=x_train.shape[0], callbacks=[csvlogger, checkpoint, MyCallback])
  </code></pre>
  
  <p>How do I get past this error "set_model() missing 1 required positional argument: 'model'
  "
  Below is the stack trace </p>
  
  <pre><code>TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-12-1826a19039cd&gt; in &lt;module&gt;()
      128 model.fit_generator(datagen.flow(x_train, y_train, batch_size=75), 
      129                            epochs=10, validation_data=(x_validation, y_test),verbose=1,
  --&gt; 130                            steps_per_epoch=x_train.shape[0], callbacks=[csvlogger, checkpoint, MyCallback])
      131 model.save('trained_model5.h5')
      132 
  
  /usr/local/lib/python3.6/dist-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
       89                 warnings.warn('Update your `' + object_name +
       90                               '` call to the Keras 2 API: ' + signature, stacklevel=2)
  ---&gt; 91             return func(*args, **kwargs)
       92         wrapper._original_function = func
       93         return wrapper
  
  /usr/local/lib/python3.6/dist-packages/keras/models.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
     1274                                         use_multiprocessing=use_multiprocessing,
     1275                                         shuffle=shuffle,
  -&gt; 1276                                         initial_epoch=initial_epoch)
     1277 
     1278     @interfaces.legacy_generator_methods_support
  
  /usr/local/lib/python3.6/dist-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
       89                 warnings.warn('Update your `' + object_name +
       90                               '` call to the Keras 2 API: ' + signature, stacklevel=2)
  ---&gt; 91             return func(*args, **kwargs)
       92         wrapper._original_function = func
       93         return wrapper
  
  /usr/local/lib/python3.6/dist-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
     2131         else:
     2132             callback_model = self
  -&gt; 2133         callbacks.set_model(callback_model)
     2134         callbacks.set_params({
     2135             'epochs': epochs,
  
  /usr/local/lib/python3.6/dist-packages/keras/callbacks.py in set_model(self, model)
       50     def set_model(self, model):
       51         for callback in self.callbacks:
  ---&gt; 52             callback.set_model(model)
       53 
       54     def on_epoch_begin(self, epoch, logs=None):
  
  TypeError: set_model() missing 1 required positional argument: 'model'
  </code></pre>
  
  <p>Also, another question that I have is, whether the above solution is correct.<a href="https://www.tensorflow.org/api_docs/python/tf/train/AdamOptimizer#methods" rel="noreferrer">This tensorflow link about Adam Optimizer</a> suggests learning rate to be calculated as:</p>
  
  <blockquote>
    <p>lr_t &lt;- learning_rate * sqrt(1 - beta2^t) / (1 - beta1^t)</p>
  </blockquote>
  
  <p>This seems quite different from the solution that is mentioned in the other link. Did I miss something?</p>