sanghyun-son / EDSR-PyTorch

PyTorch version of the paper 'Enhanced Deep Residual Networks for Single Image Super-Resolution' (CVPRW 2017)
MIT License
2.43k stars 669 forks source link

ValueError: x and y must have same first dimension, but have shapes (0,) and (1,) #228

Closed wanna-fly closed 4 years ago

wanna-fly commented 4 years ago

When I tried to train the EDSR model using default settings in this code, an error about function plt.plot occurred.

Traceback (most recent call last):
  File "main.py", line 33, in <module>
    main()
  File "main.py", line 28, in main
    t.test()
  File "/home/ybx/studio/EDSR-PyTorch/src/trainer.py", line 123, in test
    self.ckp.save(self, epoch, is_best=(best[1][0, 0] + 1 == epoch))
  File "/home/ybx/studio/EDSR-PyTorch/src/utility.py", line 88, in save
    trainer.loss.plot_loss(self.dir, epoch)
  File "/home/ybx/studio/EDSR-PyTorch/src/loss/__init__.py", line 111, in plot_loss
    plt.plot(axis, self.log[:, i].numpy(), label=label)
ValueError: x and y must have same first dimension, but have shapes (0,) and (1,)

I think code of line 106 in /src/loss/initpy axis = np.linspace(1, epoch, epoch)should be modified into axis = np.linspace(0, epoch+1, epoch+1) as well as the 108th line of code in /src/utility. And it does work for me.

yanmenglu commented 4 years ago

you need install matplotlib

wulongjian commented 4 years ago

I have also meet this problem, as I follow your guidance ,I solve this problem, thanks a lot.

Levishery commented 4 years ago

Seems that this problem is related to pytorch version. They changed 'epoch = self.optimizer.get_last_epoch() + 1' to 'epoch = self.optimizer.get_last_epoch()' from test() in their commits on Aug 21, 2019 to support PyTorch 1.2.0. This is why this error occur.

Lifedecoder commented 2 years ago

Fabulous! Thanks!