CharCnn_Keras icon indicating copy to clipboard operation
CharCnn_Keras copied to clipboard

Passing Learning rate

Open saravananpsg opened this issue 6 years ago • 3 comments

How to pass the learning rate for these model ?

I tried to update the config.json and 1st try - passed the learning rate before compile the model. 2nd try - set the value from Keras Backend for optimiser learning rate

Both the times, I am unable to pass the learning rates. Is there any way to pass the learning rates ?

saravananpsg avatar Aug 02 '18 05:08 saravananpsg

I have tried this one and it worked :
model.compile(optimizer=Adam(lr=self.learning_rate), loss=self.loss, metrics=['accuracy'])

saravananpsg avatar Aug 02 '18 07:08 saravananpsg

Yeah, that should work. Your problem was happening because of how Keras allows you to pass the optimizer as either a string or an object.

This codebase was configured to pass the optimizer's name as a string (so 'adam', 'sgd' etc.) which used the default parameters. However, if you actually instantiate a Keras optimizer object and pass that to the model when compiling it, you can configure optimizer parameters.

chaitjo avatar Aug 02 '18 08:08 chaitjo

There's also a manual way of setting the optimizer's parameters using the Keras backend. For example:

K.set_value(model.optimizer.lr, <your-learning-rate>)

chaitjo avatar Aug 02 '18 08:08 chaitjo