python.InvalidArgumentError: Assign requires shapes of both tensors to match.

2019-05-25 13:13:54 浏览数 (2)

问题

代码语言:javascript复制
INFO:tensorflow:Restoring parameters from /tmp/mnist_convnet_modelmodel.ckpt-1619
2018-04-10 16:02:17.996575: W c:ltensorflow_1501918863922worktensorflow-1.2.1tensorflowcoreframeworkop_kernel.cc:1158] Not found: Key conv___1/bias not found in checkpoint
2018-04-10 16:02:17.999870: W c:ltensorflow_1501918863922worktensorflow-1.2.1tensorflowcoreframeworkop_kernel.cc:1158] Not found: Key conv___1/kernel not found in checkpoint
Traceback (most recent call last):
  File "E:anacondaenvspy36libsite-packagestensorflowpythonclientsession.py", line 1139, in _do_call
    return fn(*args)
  File "E:anacondaenvspy36libsite-packagestensorflowpythonclientsession.py", line 1121, in _run_fn
    status, run_metadata)
  File "E:anacondaenvspy36libcontextlib.py", line 88, in __exit__
    next(self.gen)
  File "E:anacondaenvspy36libsite-packagestensorflowpythonframeworkerrors_impl.py", line 466, in raise_exception_on_not_ok_status
    pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [64] rhs shape= [32]
         [[Node: save/Assign = Assign[T=DT_FLOAT, _class=["loc:@conv2d/bias"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/cpu:0"](conv2d/bias, save/RestoreV2)]]

解决过程

  1. 查看到INVALIDARGUMENTERROR (SEE ABOVE FOR TRACEBACK): ASSIGN REQUIRES SHAPES OF BOTH TENSORS TO MATCH. LHS SHAPE= [2048,38] RHS SHAPE= [2048,2] 中提到 做tensorflow object detection 中,清空下checkpoint就可以啦
  2. 于是我看到自己的报错信息中有一句Restoring parameters from /tmp/mnist_convnet_modelmodel.ckpt-1619,说明程序是在读取参数时出错的。尝试删除这些.ckpt-1619后缀的文件,并且不要设置model_dir之类的变量即可。

0 人点赞