Open PhilippBrendel opened 1 year ago
...
self.model.compile("adam", lr=1e-3, decay=None,
loss_weights=[1, 1, 1, 1])
self.model.sess.run(tf.global_variables_initializer())
Sorry for posting this a little early (in hindsight), but maybe this solution is helpful for others as well....
Hello Philipp,@PhilippBrendel and @lululxvi
Can you provide implementation of adaptive loss weights class?
I am also trying to apply the same thing for 2d wave equation. Since a FNN and MsFFN seem to fail, i would like to try adaptive weights.
Thanks in advance
Hi, I'll use this issue to centralize information regarding adaptive loss weighting:
Other references of interest:
Note: "lambda slighly improves the accuracy" (Fig 13). According to Fig. 13 it does not seem to be so efficient.
As stated by @lululxvi in #215, "based on my experience, fixed and adaptive weights have similar effects. As you can see in the papers you mentioned, the adaptive weights quickly converge to a fixed number, and thus fixed weights are basically sufficient. Also, it is recommended to use hard constraints for BC/IC, see FAQ".
I would definitely define adaptive weighting as callbacks. I'll try to figure out a structure for implementing a simple weighting scheme. I think that adaptive weighting can be useful for more involved loss terms (with e.g. 4-5 terms).
Hi! I have been exploring this issue.
For all these adaptive weighting techniques, we want to be able to update loss_weights
during training with a callback, without having to compile the model again.
So loss_weights
shall be initialized at first epoch.
The callback would adapt the weights as a on_epoch_end
.
For example, in tensorflow.compat.v1
the multiplication is performed here:
So, to begin with, we would comment out these two lines, and put them somewhere else at the beginning of train function.
Then, with a few changes, we could define and use self.loss_weights
so that we can update the weights during training.
Do you agree @lululxvi ?
Also, do you prefer if I move this discussion to a new issue? Or could you please re-open this issue?
@pescap Yes, that sounds good.
As a first step, I am trying to facilitate the update of loss_weights
during training, see #1511.
Really looking forward to this implementation!
Really looking forward to this implementation!
Working on this in #1586
- I have experience with this type of work from my project, where I implemented my own PINN library in TensorFlow 2.0.
- If you're interested in implementing this feature in TensorFlow 2.0, I'm happy to lend a hand.
Hi! Thank you for proposing! We could start with the 'tensorflow'
backend. How do you suggest we proceed? We could discuss via the Deepxde Slack workspace.
- I have experience with this type of work from my project, where I implemented my own PINN library in TensorFlow 2.0.
- If you're interested in implementing this feature in TensorFlow 2.0, I'm happy to lend a hand.
Hi! Thank you for proposing! We could start with the
'tensorflow'
backend. How do you suggest we proceed? We could discuss via the Deepxde Slack workspace.
Yes, could you give me the Slack ID or URL?
- I have experience with this type of work from my project, where I implemented my own PINN library in TensorFlow 2.0.
- If you're interested in implementing this feature in TensorFlow 2.0, I'm happy to lend a hand.
Hi! Thank you for proposing! We could start with the
'tensorflow'
backend. How do you suggest we proceed? We could discuss via the Deepxde Slack workspace.Yes, could you give me the Slack ID or URL?
Can you please send an email to @lululxvi asking him to add you?
Hi everyone,
I've read in other Issues (e.g. #215 and #908) that adaptive Loss-Weights are not high-priority for DeepXDE, but I still want to test some approaches for that, as I see quite some potential for my current use-case. However, implementing this via a Callback like the following does not really work for me so far (cf. Error-message below).
Click for Error Message
```log Training model... Step Train loss Test loss Test metric 0 [9.15e+04, 2.41e+00, 1.07e-07, 2.08e-06] [3.41e+04, 9.30e-01, 0.00e+00, 0.00e+00] [] Compiling model... 'compile' took 9.111588 s Traceback (most recent call last): File "D:\Anaconda3\envs\deepxde_tf24\lib\site-packages\tensorflow\python\client\session.py", line 1375, in _do_call return fn(*args) File "D:\Anaconda3\envs\deepxde_tf24\lib\site-packages\tensorflow\python\client\session.py", line 1359, in _run_fn return self._call_tf_sessionrun(options, feed_dict, fetch_list, File "D:\Anaconda3\envs\deepxde_tf24\lib\site-packages\tensorflow\python\client\session.py", line 1451, in _call_tf_sessionrun return tf_session.TF_SessionRun_wrapper(self._session, options, feed_dict, tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value beta1_power_1 [[{{node beta1_power_1/read}}]] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "maxwell_quasistatic.py", line 1689, inI'm not an Expert on Core-Tensorflow (especially not TF1), so if anyone could give me an advice on what I'm doing wrong or how I can fix this, I'd really appreciate it!
Cheers, Philipp
Ps: In #331 are some more comments, but I don't think they apply to my problem, as I'm not interested in using gradients for the weights initially.