cvlab-stonybrook / Scanpath_Prediction

Predicting Goal-directed Human Attention Using Inverse Reinforcement Learning (CVPR2020)
MIT License
103 stars 22 forks source link

nary_operator() missing 1 required positional argument: 'fun' #10

Closed ManooshSamiei closed 4 years ago

ManooshSamiei commented 4 years ago

Hello,

Its been a while I am trying to solve the error I get while calculating gradient in the GAIL class. The error is:

nary_operator() missing 1 required positional argument: 'fun'

This is the part of the code that generates this error:

    grad = autograd.grad(outputs=disc,
                         inputs=mixup_states,
                         grad_outputs=ones,
                         create_graph=True,
                         retain_graph=True,
                         only_inputs=True)[0]

Which is part of compute_grad_pen function in GAIL class.

I would really appreciate it if you could help me realize how to fix this error. Thank you so much in advance.

ouyangzhibo commented 4 years ago

Hello,

Its been a while I am trying to solve the error I get while calculating gradient in the GAIL class. The error is:

nary_operator() missing 1 required positional argument: 'fun'

This is the part of the code that generates this error:

    grad = autograd.grad(outputs=disc,
                         inputs=mixup_states,
                         grad_outputs=ones,
                         create_graph=True,
                         retain_graph=True,
                         only_inputs=True)[0]

Which is part of compute_grad_pen function in GAIL class.

I would really appreciate it if you could help me realize how to fix this error. Thank you so much in advance.

Hi @manooshsamiei76, can you show the full log?

ManooshSamiei commented 4 years ago

Hello, Its been a while I am trying to solve the error I get while calculating gradient in the GAIL class. The error is: nary_operator() missing 1 required positional argument: 'fun' This is the part of the code that generates this error:

    grad = autograd.grad(outputs=disc,
                         inputs=mixup_states,
                         grad_outputs=ones,
                         create_graph=True,
                         retain_graph=True,
                         only_inputs=True)[0]

Which is part of compute_grad_pen function in GAIL class. I would really appreciate it if you could help me realize how to fix this error. Thank you so much in advance.

Hi @manooshsamiei76, can you show the full log?

I am running the code in google colab. Here is the complete output of my execution:

target fixation prob (valid).: [0. 0.00019841 0.00019841 0.00019841 0.00019841 0.00039683 0.00039683] generating state-action pairs to train discriminator... [0 0] Collected 2695 state-action pairs updating discriminator (step=0)...

TypeError Traceback (most recent call last)

in () 54 built = build(hparams, True, device, dataset['catIds']) 55 trainer = Trainer(**built, dataset=dataset, device=device, hparams=hparams) ---> 56 trainer.train() 2 frames in train(self) 96 fake_data = FakeDataRollout(trajs_all, self.batch_size) 97 D_loss, D_real, D_fake = self.gail.update( ---> 98 self.train_HG_loader, fake_data) 99 100 self.writer.add_scalar("discriminator/fake_loss", D_fake, in update(self, true_data_loader, fake_data, iter_num, noisy_label_ratio) 125 126 gail_loss = expert_loss + policy_loss --> 127 grad_pen = self.compute_grad_pen(*x_real, *x_fake) 128 129 self.optimizer.zero_grad() in compute_grad_pen(self, expert_states, expert_act, expert_task, policy_states, policy_act, policy_task, type, lambda_) 65 create_graph=True, 66 retain_graph=True, ---> 67 only_inputs=True)[0] 68 69 grad_pen = lambda_ * (grad.norm(2, dim=1) - 1).pow(2).mean() TypeError: nary_operator() missing 1 required positional argument: 'fun'
ManooshSamiei commented 4 years ago

Hello, Its been a while I am trying to solve the error I get while calculating gradient in the GAIL class. The error is: nary_operator() missing 1 required positional argument: 'fun' This is the part of the code that generates this error:

    grad = autograd.grad(outputs=disc,
                         inputs=mixup_states,
                         grad_outputs=ones,
                         create_graph=True,
                         retain_graph=True,
                         only_inputs=True)[0]

Which is part of compute_grad_pen function in GAIL class. I would really appreciate it if you could help me realize how to fix this error. Thank you so much in advance.

Hi @manooshsamiei76, can you show the full log?

I am running the code in google colab. Here is the complete output of my execution:

target fixation prob (valid).: [0. 0.00019841 0.00019841 0.00019841 0.00019841 0.00039683

0.00039683] generating state-action pairs to train discriminator... [0 0] Collected 2695 state-action pairs updating discriminator (step=0)... TypeError Traceback (most recent call last) in () 54 built = build(hparams, True, device, dataset['catIds']) 55 trainer = Trainer(**built, dataset=dataset, device=device, hparams=hparams) ---> 56 trainer.train()

2 frames in train(self) 96 fake_data = FakeDataRollout(trajs_all, self.batch_size) 97 D_loss, D_real, D_fake = self.gail.update( ---> 98 self.train_HG_loader, fake_data) 99 100 self.writer.add_scalar("discriminator/fake_loss", D_fake,

in update(self, true_data_loader, fake_data, iter_num, noisy_label_ratio) 125 126 gail_loss = expert_loss + policy_loss --> 127 grad_pen = self.compute_grad_pen(x_real, x_fake) 128 129 self.optimizer.zero_grad()

in compute_grad_pen(self, expert_states, expert_act, expert_task, policy_states, policy_act, policytask, type, lambda) 65 create_graph=True, 66 retain_graph=True, ---> 67 only_inputs=True)[0] 68 69 gradpen = lambda * (grad.norm(2, dim=1) - 1).pow(2).mean()

TypeError: nary_operator() missing 1 required positional argument: 'fun'

I had wrongly imported another library of autograd! Instead of importing it from torch! instead of :

from torch import autograd

I had just typed : import autograd Which is another library!

Thank you very much for your help Zhibo.