Skip to content Skip to sidebar Skip to footer

How To Change Keras Optimizer Code

I am really new to Keras so forgive me if my query is a bit silly. I installed Keras in my system using the default methods and it works fine. I want to add a new optimizer to Kera

Solution 1:

I think your approach is complicated and it doesn't have to be. Let's say you implement your own optimizer by subclassing keras.optimizers.Optimizer:

class MyOptimizer(Optimizer):
    optimizer functions here.

Then to instantiate it in your model you can do this:

myOpt = MyOptimizer()
model.compile(loss='binary_crossentropy', optimizer=myOpt, metrics= ['accuracy'])

Just pass an instance of your optimizer as the optimizer parameter of model.compile and that's it, Keras will now use your optimizer.


Solution 2:

Are you sure that it is a new optimizer that you want? Not a custom objective function? Objectives can be custom it's easy to define, optimizers are trickier.

There is already a huge number of optimizers with a lot of parameters. However if you really want to go down that road I would advise you to go to tensorflow! Then you will be able to use this in Keras

It's all I can do for you, but maybe there is another way that I don't know of.


Post a Comment for "How To Change Keras Optimizer Code"