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

Using softTreeLoss error #11

Open
Muzijiajian opened this issue Nov 14, 2020 · 1 comment
Open

Using softTreeLoss error #11

Muzijiajian opened this issue Nov 14, 2020 · 1 comment

Comments

@Muzijiajian
Copy link

Muzijiajian commented Nov 14, 2020

Hello, I am trying to use softTreeLoss by using following codes:
from nbdt.loss import SoftTreeSupLoss
train_loss_fn = nn.CrossEntropyLoss().cuda()
criterion = SoftTreeSupLoss(criterion=train_loss_fn, dataset='Imagenet1000', tree_supervision_weight=1.0,
hierarchy='induced-efficientnet_b7b')
...
for i, (input, targets) in enumerate(train_loader):
targets = targets.cuda(async=True)
input_var = torch.autograd.Variable(input).cuda()
targets_var = torch.autograd.Variable(targets).cuda()
scores = model(input_var)
loss = criterion(scores, targets_var)

Then it comes the following errors:
File "/gruntdata/semantic-hierarchy-master/neural-backed-decision-trees/nbdt/model.py", line 240, in forward
wnid_to_outputs = self.forward_nodes(outputs)
File "/gruntdata/semantic-hierarchy-master/neural-backed-decision-trees/nbdt/model.py", line 101, in forward_nodes
return self.get_all_node_outputs(outputs, self.nodes)
File "/gruntdata/semantic-hierarchy-master/neural-backed-decision-trees/nbdt/model.py", line 90, in get_all_node_outputs
node_logits = cls.get_node_logits(outputs, node)
File "/gruntdata/semantic-hierarchy-master/neural-backed-decision-trees/nbdt/model.py", line 79, in get_node_logits
for new_label in range(node.num_classes)
File "/gruntdata/semantic-hierarchy-master/neural-backed-decision-trees/nbdt/model.py", line 79, in
for new_label in range(node.num_classes)
AttributeError: 'Tensor' object has no attribute 'T'

@alvinwan
Copy link
Owner

@Muzijiajian Hm, are you on PyTorch 1.4? https://github.com/alvinwan/neural-backed-decision-trees/blob/master/requirements.txt#L2. Your code looks right, and tensors should definitely support .T for transpose.

alvinwan added a commit that referenced this issue Jan 23, 2021
* cifar wrapper

* move load_state_dict to nbdt.models.utils

* train loss oops

* cleaner dataset kwarg attempt

* aesthetic changes

* decorator for analyzer

* imports and docstring

* moar aesthetics

* more aesthetic
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

2 participants