lululxvi / deepxde

A library for scientific machine learning and physics-informed learning
https://deepxde.readthedocs.io
GNU Lesser General Public License v2.1
2.64k stars 741 forks source link

question about model.py #1259

Open wooodswu opened 1 year ago

wooodswu commented 1 year ago
image

Need your help! I have a question about this “losses_fn", except in the definition of “outputs_losses”, i cannot find this function. When I want to change the loss function, and using the following:

/*code

net = dde.maps.DeepONetCartesianProd( [101,30,30,101], [1,30,30,101], "relu", "Glorot normal")

model2 =dde.Model(data, net) model2.compile("adam", lr=3e-4, loss=“mse", metrics=["l2 relative error"], )

*/ loss in dde.Model.compile()

by my understanding, is just the “loss_fn”(here is just mse) in the “losses_fn", and I cannot find the “losses_fn” in the whole package.

My question: could I change this losses_fn? is this the loss function I need to define? Or in the somewhere of the model, where can I change the loss?

kyouma commented 1 year ago

You can pass a callable to the Model class: for example, _loss=torch.nn.functional.l1loss instead of loss='mse'. And as far as I understand from the source code, a list of mixed identifiers/callables for the equations and the conditions also can be used.

wooodswu commented 1 year ago

You can pass a callable to the Model class: for example, _loss=torch.nn.functional.l1loss instead of loss='mse'. And as far as I understand from the source code, a list of mixed identifiers/callables for the equations and the conditions also can be used.

Could you tell me where the mixed identifiers/callables for the equation is and in which module? i have not found this in this package. Thanks a lot.

kyouma commented 1 year ago

Check this get() function, which returns the loss function itself to the model during the initialization process. The check for callable is on the line 70. You can use this feature like this: model.compile('adam', lr=1e-3, loss=torch.nn.functional.l1_loss).

chuluya commented 1 year ago

Hello, could you help solve the problems "Error: The network has multiple inputs, and saving such result han't been implemented." when I choose the DeepONet as my net. Thank you so much if you could help me! image

kyouma commented 1 year ago

Hello, could you help solve the problems "Error: The network has multiple inputs, and saving such result han't been implemented." when I choose the DeepONet as my net. Thank you so much if you could help me! image

As far as I understand, your network uses multiple input "streams", and DeepXDE has not implemented saving and plotting input-output states for such models yet. In my opinion, you have several options: 1) not use the deepxde.saveplot function at all