Code Monkey home page Code Monkey logo

Comments (6)

keacifer avatar keacifer commented on September 17, 2024

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.

bobchenlut avatar bobchenlut commented on September 17, 2024

I met this bug too.

from matrix-capsules-pytorch.

ChunningDu avatar ChunningDu commented on September 17, 2024

Have you solved it?

from matrix-capsules-pytorch.

RahulSChand avatar RahulSChand commented on September 17, 2024

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.

RahulSChand avatar RahulSChand commented on September 17, 2024

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.

FreshFood avatar FreshFood commented on September 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.