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

'NoneType' object has no attribute 't' #8

Open
schonkopf opened this issue Feb 25, 2021 · 2 comments
Open

'NoneType' object has no attribute 't' #8

schonkopf opened this issue Feb 25, 2021 · 2 comments
Labels
enhancement New feature or request
Projects

Comments

@schonkopf
Copy link

schonkopf commented Feb 25, 2021

While running the following codes:
net = NMF(data.shape, rank=self.basis_num, W=torch.Tensor(self.W), trainable_W=False).cuda()
net.fit(data.cuda(), verbose=True, max_iter=200, tol=1e-18, beta=1)

I received the error message, any idea?
/content/pytorchNMF/torchnmf/nmf.py in fit(self, V, beta, tol, max_iter, verbose, alpha, l1_ratio)
281
282 with torch.no_grad():
--> 283 WH = self.reconstruct(H, W)
284 loss_init = previous_loss = beta_div(WH, V, beta).mul(2).sqrt().item()
285

/content/pytorchNMF/torchnmf/nmf.py in reconstruct(H, W)
486 @staticmethod
487 def reconstruct(H, W):
--> 488 return F.linear(H, W)
489
490

/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py in linear(input, weight, bias)
1690 ret = torch.addmm(bias, input, weight.t())
1691 else:
-> 1692 output = input.matmul(weight.t())
1693 if bias is not None:
1694 output += bias

AttributeError: 'NoneType' object has no attribute 't'

@yoyololicon
Copy link
Owner

yoyololicon commented Feb 25, 2021

@schonkopf
If the Vshape argumet (the first argument) is specified, it will overrided other arguments like W and H.
To use custom template tensor, in your case, you have to manually set W and H.

Example:

net = NMF(W=torch.Tensor(self.W), trainable_W=False, H=(data.shape[0], self.basis_num)).cuda()

Seems I didn't write the document clearly, I will add some assertions in the module to let user know what happened.

@yoyololicon yoyololicon added the enhancement New feature or request label Feb 25, 2021
@yoyololicon
Copy link
Owner

Hi @schonkopf,

In the newest commit e4563b2 I add an warning note in class docstring. Also, I changed the behavior of trainable_* arguments to only take effect when template tensor is given, it's also written in docstring.

While running the following codes:
net = NMF(data.shape, rank=self.basis_num, W=torch.Tensor(self.W), trainable_W=False).cuda()
net.fit(data.cuda(), verbose=True, max_iter=200, tol=1e-18, beta=1)

This way will work without error now, though W would be replaced by random weights.

@yoyololicon yoyololicon added this to In progress in Develope Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In progress
Develope
In progress
Development

No branches or pull requests

2 participants