2

如何从chainer中保存的快照恢复训练。我试图通过以下github链接使用chainer来实现DCGAN:

https://github.com/chainer/chainer/blob/master/examples/dcgan/train_dcgan.py

当我尝试给出--resume参数时,它在网络中显示形状不匹配错误。

在python代码中有一个选项可以提供我们需要从中恢复训练的快照。这些快照会自动保存到结果文件夹中。这也作为代码中的参数给出。所以我尝试从保存的快照中恢复训练给出以下命令。

$ python train.py --resume 'snapshot.npz'

其中 train.py 是带有 dcgan ciphar10 数据集标签的修改代码。

我通过给出上述命令得到的错误是:

chainer.utils.type_check.InvalidType: 
Invalid operation is performed in: LinearFunction (Forward)

Expect: x.shape[1] == W.shape[1]
Actual: 110 != 100

当我使用以下命令运行 python 文件时,没有错误:

$ python train.py

完整的错误跟踪:

Exception in main training loop: 
Invalid operation is performed in: LinearFunction (Forward)
Expect: x.shape[1] == W.shape[1]
Actual: 110 != 100
Traceback (most recent call last):
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/training/trainer.py, line 315, in run
    update()
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/training/updaters/standard_updater.py, line 165, in update
    self.update_core()
  File /home/964769/Lakshmi/DCGAN/updater_with_label.py, line 50, in update_core
    x_fake = gen(z,labels)
  File /home/964769/Lakshmi/DCGAN/net_with_label.py, line 61, in call
    h = F.reshape(F.relu(self.bn0(self.l0(F.concat((z,t),axis=1)))),
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/link.py, line 242, in call
    out = forward(args, *kwargs)
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/links/connection/linear.py, line 138, in forward
    return linear.linear(x, self.W, self.b, n_batch_axes=n_batch_axes)
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/functions/connection/linear.py, line 288, in linear
    y, = LinearFunction().apply(args)
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/function_node.py, line 245, in apply
    self.check_data_type_forward(in_data)
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/function_node.py, line 330, in check_data_type_forward
    self.check_type_forward(in_type)
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/functions/connection/linear.py, line 27, in check_type_forward
    x_type.shape[1] == w_type.shape[1],
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/utils/typecheck.py, line 546, in expect
    expr.expect()
  File/home/964769/anaconda3/lib/python3.6/site-packages/chainer/utils/typecheck.py, line 483, in expect
    '{0} {1} {2}'.format(left, self.inv, right))
Will finalize trainer extensions and updater before reraising the exception.
Traceback (most recent call last):
  Filetrain.py, line 140, in 
    main()
  Filetrain.py, line 135, in main
    trainer.run()
  File/home/964769/anaconda3/lib/python3.6/site-packages/chainer/training/trainer.py, line 329, in run
    six.reraise(sys.exc_info())
  File /home/964769/anaconda3/lib/python3.6/site-packages/six.py, line 686, in reraise
    raise value
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/training/trainer.py, line 315, in run
    update()
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/training/updaters/standard_updater.py, line 165, in update
    self.update_core()
  File /home/964769/Lakshmi/DCGAN/updater_with_label.py, line 50, in update_core
    x_fake = gen(z,labels)
  File /home/964769/Lakshmi/DCGAN/net_with_label.py, line 61, in call
    h = F.reshape(F.relu(self.bn0(self.l0(F.concat((z,t),axis=1)))),
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/link.py, line 242, in call
    out = forward(args, **kwargs)
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/links/connection/linear.py, line 138, in forward
    return linear.linear(x, self.W, self.b, n_batch_axes=n_batch_axes)
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/functions/connection/linear.py, line 288, in linear
    y, = LinearFunction().apply(args)
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/function_node.py, line 245, in apply
    self.check_data_type_forward(in_data)
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/function_node.py, line 330, in check_data_type_forward
    self.check_type_forward(in_type)
  File /home/964769/anaconda3/lib/python3.6/site-packages/chainer/functions/connection/linear.py, line 27, in checktype_forward
    x_type.shape[1] == w_type.shape[1],
  File "/home/964769/anaconda3/lib/python3.6/site-packages/chainer/utils/typecheck.py, line 546, in expect
    expr.expect()
  File/home/964769/anaconda3/lib/python3.6/site-packages/chainer/utils/type_check.py", line 483, in expect
    '{0} {1} {2}'.format(left, self.inv, right))
chainer.utils.type_check.InvalidType: 
Invalid operation is performed in: LinearFunction (Forward)
Expect: x.shape[1] == W.shape[1]
Actual: 110 != 100
4

0 回答 0