Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edits for PINN/custom loss functions #15

Open
rmojgani opened this issue Mar 28, 2022 · 0 comments
Open

edits for PINN/custom loss functions #15

rmojgani opened this issue Mar 28, 2022 · 0 comments

Comments

@rmojgani
Copy link

rmojgani commented Mar 28, 2022

How can I use the code for the case where I have a custom loss function, and not a torch.nn."LOSS"?
I'm specifically trying to reproduce the results in https://arxiv.org/abs/2109.01050 , and cannot get the PyHessian class to work.

Also, in the PINN case, network does not have a data=(inputs, targets), can I use the same code/class or I need further edits?

I'm thinking of changing the loss in line 92

loss = self.criterion(outputs, targets.to(device))

with my custom loss (from the network)

wondering if that's all the changes I need


PS:
Also since I'm only interested in the eigenvectors, tried to exctract parameters and gradients, i.e.,

def get_params_grad(model):

and pass it to
def eigenvalues(self, maxIter=100, tol=1e-3, top_n=1):

Though it's throwing some error at me, would appreciate any insights,

`Traceback (most recent call last):

File "/tmp/ipykernel_709492/339026100.py", line 1, in
hv = torch.autograd.grad(gradsH,

File "/home/xxx/.local/lib/python3.8/site-packages/torch/autograd/init.py", line 229, in grad
grad_outputs_ = make_grads(outputs, grad_outputs)

File "/home/xxx/.local/lib/python3.8/site-packages/torch/autograd/init.py", line 33, in _make_grads
if not out.shape == grad.shape:

AttributeError: 'float' object has no attribute 'shape'`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant