张量层无法正确加载预训练的重量

时间:2020-01-14 10:03:21

标签: tensorflow tensorlayer

我在将预训练的参数加载到张量层中时遇到问题。 我尝试使用srgan(https://github.com/tensorlayer/srgan)及其预训练的参数(https://github.com/tensorlayer/srgan/releases/tag/1.2.0

适用代码如下

G = get_G([1, None, None, 3])
load_params = tl.files.load_npz(path='', name='g_srgan.npz')
tl.files.assign_weights(load_params, 
#G.load_weights(os.path.join("g_srgan.npz"))
G.eval()

我遇到错误:

Traceback (most recent call last):
  File "train.py", line 194, in <module>
    evaluate(session)
  File "train.py", line 156, in evaluate
    tl.files.assign_weights(load_params, G)
  File "/usr/local/lib/python3.6/dist-packages/tensorlayer/files/utils.py", line 2023, in assign_weights
    ops.append(network.all_weights[idx].assign(param))
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py", line 819, in assign
    self._shape.assert_is_compatible_with(value_tensor.shape)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/tensor_shape.py", line 1110, in assert_is_compatible_with
    raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (1, 1, 1, 64) and (64,) are incompatible

请告诉我解决方案。 谢谢!!

0 个答案:

没有答案