ReduceLROnPlateau gives error with ADAM optimizer

2024/9/30 13:33:09

Is it because adam optimizer changes the learning rate by itself. I get an error saying 'Attempting to use uninitialized value Adam_1/lr' I guess there is no point in using ReduceLRonPlateau as Adam will automatically change learning rate.Anyways i have updated the codee Update: Code:

from keras.optimizers import Adam
model.compile(optimizer='adam',loss='mse')callback_reduce_lr=ReduceLROnPlateau(monitor='val_loss',factor=0.1, min_lr=1e-4,patience=0,verbose=1)
model.fit(xTrain,yTrain,epochs=100,batch_size=10,validation_data=(xTest,yTest),verbose=2,callbacks=[callback_reduce_lr])

Error://Attempting to use uninitialized value Adam_1/lr

I read somewhere that initializing adam doesnt work while working with ReduceLROnPlateau,,i have tried to initialize the weights too but i got the same error

Answer

As discussed in the question's comments, keras' ReduceLROnPleteau, does appear to work for its default parameters:

# keras' ReduceLROnPlateau callback default parameters:
from keras.callbacks import ReduceLROnPlateau
reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=10,verbose=0, mode='auto', min_delta=0.0001,cooldown=0, min_lr=0)

I tried to recreate the error to try and identify which parameter causes it, but I couldn't. Due to this, I believe that the error doesn't appear for all input shapes or models.

However, I can say for sure that, with the correct parameters, ReduceLROnPlateau does work with Adam.

https://en.xdnf.cn/q/71081.html

Related Q&A

How to make add replies to comments in Django?

Im making my own blog with Django and I already made a Comments system.. I want to add the replies for each comment (like a normal comments box) and I dont know what to do this is my current models.py …

Which Regular Expression flavour is used in Python?

I want to know which RegEx-flavour is used for Python? Is it PCRE, Perl compatible or is it ICU or something else?

Python regex: Including whitespace inside character range

I have a regular expression that matches alphabets, numbers, _ and - (with a minimum and maximum length).^[a-zA-Z0-9_-]{3,100}$I want to include whitespace in that set of characters.According to the Py…

Python - how can I override the functionality of a class before its imported by a different module?

I have a class thats being imported in module_x for instantiation, but first I want to override one of the classs methods to include a specific feature dynamically (inside some middleware that runs bef…

Calling a stateful LSTM as a functional model?

I have a stateful LSTM defined as a Sequential model:model = Sequential() model.add(LSTM(..., stateful=True)) ...Later, I use it as a Functional model:input_1, input_2 = Input(...), Input(...) output_1…

How to cluster Gantt bars without overlap?

Using create_gantt I have overlapping start and end dates: import plotly.plotly as py import plotly.figure_factory as ff import plotlydf = [dict(Task="Milestone A", Start=2017-01-01, Finish=2…

Fail to install lxml using pip

This is the command I used to install lxml:sudo pip install lxmlAnd I got the following message in the Cleaning Up stage:Cleaning up... Command /usr/bin/python -c "import setuptools, tokenize;…

Python 3.x list comprehension VS tuple generator

Is there any reason for memory, speed or whatever, that I would want to use:tuple(i for i in range(5000))instead of:[i for i in range(5000)]If I didnt mind the immutability of tuples

Using Sphinx with a distutils-built C extension

I have written a Python module including a submodule written in C: the module itself is called foo and the C part is foo._bar. The structure looks like:src/ foo/__init__.py <- contains the public …

PyYAML error: Could not determine a constructor for the tag !vault

I am trying to read a YAML file that has the tag !vault in it. I get the error:could not determine a constructor for the tag !vaultUpon reading a couple of blogs, I understood that I need to specify so…