katerakelly / pytorch-maml

PyTorch implementation of MAML: https://arxiv.org/abs/1703.03400
MIT License
552 stars 128 forks source link

How to solve "IndexError: too many indices for array"? #10

Closed fuzihaofzh closed 5 years ago

fuzihaofzh commented 6 years ago

I have encountered the problem "IndexError: too many indices for array". Is it related to the dataset I use? I just download this file (https://github.com/brendenlake/omniglot/blob/master/python/images_evaluation.zip) and put it under data. The log is as follows:

./train-omniglot-5way-1shot.sh
tee: ../logs/maml-omniglot-5way-1shot-TEST: No such file or directory
exp maml-omniglot-5way-1shot-TEST
dataset omniglot
num_cls 5
num_inst 1
batch 1
m_batch 32
num_updates 15000
num_inner_updates 5
lr 1e-1
meta_lr 1e-3
gpu 0
Setting GPU to 0
init weights
init weights
init weights
Traceback (most recent call last):
  File "maml.py", line 230, in <module>
    main()
  File "/home/maple/programs/miniconda2/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/maple/programs/miniconda2/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/maple/programs/miniconda2/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/maple/programs/miniconda2/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "maml.py", line 227, in main
    learner.train(exp)
  File "maml.py", line 151, in train
    mt_loss, mt_acc, mv_loss, mv_acc = self.test()
  File "maml.py", line 113, in test
    tloss, tacc = evaluate(test_net, train_loader)
  File "/home/maple/pytorch-maml/src/score.py", line 30, in evaluate
    loss += l.data.cpu().numpy()[0]
IndexError: too many indices for array
szitha commented 6 years ago

Hello there,

I have experienced the same error before. To get rid of it, change the line loss += l.data.cpu().numpy()[0] to loss += l.data.cpu().numpy().

I hope this helps,

Best Regards, Simphiwe.

On Mon, Sep 17, 2018 at 10:59 AM Zihao Fu notifications@github.com wrote:

I have encountered the problem "IndexError: too many indices for array". Is it related to the dataset I use? I just download this file ( https://github.com/brendenlake/omniglot/blob/master/python/images_evaluation.zip) and put it under data. The log is as follows:

./train-omniglot-5way-1shot.sh tee: ../logs/maml-omniglot-5way-1shot-TEST: No such file or directory exp maml-omniglot-5way-1shot-TEST dataset omniglot num_cls 5 num_inst 1 batch 1 m_batch 32 num_updates 15000 num_inner_updates 5 lr 1e-1 meta_lr 1e-3 gpu 0 Setting GPU to 0 init weights init weights init weights Traceback (most recent call last): File "maml.py", line 230, in main() File "/home/maple/programs/miniconda2/lib/python2.7/site-packages/click/core.py", line 722, in call return self.main(args, kwargs) File "/home/maple/programs/miniconda2/lib/python2.7/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/home/maple/programs/miniconda2/lib/python2.7/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/maple/programs/miniconda2/lib/python2.7/site-packages/click/core.py", line 535, in invoke return callback(args, **kwargs) File "maml.py", line 227, in main learner.train(exp) File "maml.py", line 151, in train mt_loss, mt_acc, mv_loss, mv_acc = self.test() File "maml.py", line 113, in test tloss, tacc = evaluate(test_net, train_loader) File "/home/maple/pytorch-maml/src/score.py", line 30, in evaluate loss += l.data.cpu().numpy()[0] IndexError: too many indices for array

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/katerakelly/pytorch-maml/issues/10, or mute the thread https://github.com/notifications/unsubscribe-auth/AQHc2sBZjyVx3ekEs99oxNqITqsbjMA-ks5ub2RfgaJpZM4WrgKq .

--

Simphiwe Zitha szitha@ska.ac.za ahotele@ska.ac.za Tel:+27 21 506 7300 www.ska.ac.za

fuzihaofzh commented 6 years ago

@szitha It works! Thanks for your help.

szitha commented 6 years ago

Perfect!!