Comments (7)
The implementation I provided is made to use LM algorithm on keras models. It is not possible to do it by creating a custom keras optimizer because during the training loop keras provide to the optimizer the gradient vector, while LM needs the jacobian matrix.
Creating a ModelWrapper that overrides the fit function is the easiest way I found to provide that behaviour.
from tf-levenberg-marquardt.
Hi,
I am not sure I have understood the question. I'll try to answer.
import levenberg_marquardt as lm
model = code to create the model ...
model_wrapper = lm.ModelWrapper(model)
model_wrapper.compile(
optimizer=tf.keras.optimizers.SGD(learning_rate=0.1),
loss=lm.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
model_wrapper.fit(train_dataset, epochs=5)
After the training you can just use the model
object you have created as a normal keras model and do all the tests you need. ModelWrapper it is used only to perform the training.
Let me know if I answered your question.
from tf-levenberg-marquardt.
Thank you for your reply.!
But after I trained the model using model_wrapper
, I want to evaluate the performance of the model and when I use model.evaluate() to evaluate the model, it reports an error: "RuntimeError: You must compile your model before training/testing. use
model.compile(optimizer, loss)``." How do I solve this problem?
from tf-levenberg-marquardt.
Just compile the model with a random optimizer (ex. tf.keras.optimizers.Adam
) and the loss you want to evaluate your model on (ex. tf.keras.losses.MeanSquaredError
).
Or I think you can just call model_wrapper.evaluate()
, do not remeber if it works you can try it.
from tf-levenberg-marquardt.
I tried calling model_wrapper.evaluate()
and it works fine, but the evaluation results are not very good. I guess that model_wrapper.evaluate() does not evaluate accurately, after all levenberg_marquardt.py
does not provide a function interface similar to evaluate()
. If it is convenient, I suggest you can add an evaluate
function to levenberg_marquardt.py.
from tf-levenberg-marquardt.
Actually ModelWrapper
inherits from tf.keras.Sequential
:
class ModelWrapper(tf.keras.Sequential):
So model_wrapper.evaluate()
must be correct. It you get bad results evaluating on test data il probably means you are overfitting train data. Try using a smaller model or use regularization techniques.
from tf-levenberg-marquardt.
Thank you for your patience and answers. I see what you mean. Also, have you tried using the LM algorithm
as a custom optimizer for a kreas
, it would be much easier to do that!
from tf-levenberg-marquardt.
Related Issues (20)
- Getting error when trying to wrap a model with a tf keras Normalization layer HOT 4
- Issue with a model that returns the gradient of a sequence HOT 4
- damping method and matrix solver HOT 3
- Random results HOT 1
- How to save this model and load weights? HOT 12
- How to use LM algorithm in a custom train loop with custom loss function? HOT 11
- Retracing warning on latest tensorflow version HOT 1
- Loss function returns 0 after first epoch for training set only when using validation data in training HOT 4
- Error when running the code test_curve_fitting.py HOT 4
- Applying the LM optimizer for PINNs HOT 13
- Error when using the "fit" function on the wrapped model "unexpected keyword argument 'count_mode'"
- Error when running the model.fit on the wrapped model "Exception encountered when calling ModelWrapper.call()" HOT 3
- Hyperparameter tuning to avoid overfitting HOT 1
- Input matrix is not invertible HOT 2
- Combine fireTS library for NARX network with Levenberg Marquardt HOT 6
- Return value for ModelWrapper fit() HOT 1
- Need help HOT 4
- Applying Levenberg-Marquardt to physically informed neural networks (PINNs) HOT 9
- Error in resuduals when labels given as int instead of float64 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tf-levenberg-marquardt.