Comments (6)
activating cuda
Epoch 0
Traceback (most recent call last):
File "train.py", line 96, in
loss = model.loss(out_labels, labels, m)
File "train.py", line 43, in loss
a_t = torch.cat([x[i][target[i]] for i in range(b)]) #b
RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated
from matrix-capsules-pytorch.
I met this bug too.
from matrix-capsules-pytorch.
Have you solved it?
from matrix-capsules-pytorch.
Change the loss function in train.py to below.
def loss(self, x, target, m): #x:b,10 target:b
target = target*x
zero_tensor = torch.tensor(0.0).cuda()
loss = torch.max(zero_tensor,m-(target-x))**2
loss = torch.mean(loss)
return loss
And rather than passing labels as the 2nd argument to model.loss() pass torch.eye(10).index_select(dim=0,index=labels) this. That is on line 96 the code is
loss = model.loss(out_labels, labels, m)
change that to
loss = model.loss(out_labels, torch.eye(10).index_select(dim=0,index=labels), m)
This will work if your use_cuda flag is False. If it is set to True, do the following:
After line 92 define a new variable
labels_zero = torch.eye(10).index_select(dim=0,index=labels).cuda()
and then on line 96
loss = model.loss(out_labels, labels, m)
change this to
loss = model.loss(out_labels, labels_zero, m)
from matrix-capsules-pytorch.
Also considering you got an issue at line 43, you may additionally get an error at line 102 acc = pred.eq(labels).cpu().sum().data[0]
in that case change it to acc = pred.eq(labels).cpu().sum().item()
from matrix-capsules-pytorch.
Pytorch version problem
a_t = torch.cat([x[i][target[i]].unsqueeze(0) for i in range(b)])
from matrix-capsules-pytorch.
Related Issues (10)
- Do you succeed in reproducing the author's result on smallNORB? HOT 4
- Isn't here a bug? HOT 1
- Overfitting with r>1 HOT 9
- some code question HOT 3
- RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated HOT 2
- r.cuda() ? HOT 1
- there may be some mistakes in your code HOT 1
- Couldn't use full power of CUDA cores HOT 1
- loss nan when r>1 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matrix-capsules-pytorch.