Ubuntu Yolov3 训练新的模型后,加载新模型参数出错InvalidArgumentError: Assign requires shapes of both tensors to match

在Ubuntu上尝试加载YOLOv3训练的新模型时遇到错误:InvalidArgumentError - Assign要求两个张量的形状匹配。问题出在模型权重的不兼容,原始模型有80个类别,而新训练的模型只有10个类别。解决方案是确保"class_name_path"和"restore_path"指向正确的自定义训练文件夹。
摘要由CSDN通过智能技术生成

--class_name_path : 类名文件

--restore_path :加载训练完成的模型

把这两个文件替换成自己训练的文件夹

tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [255] rhs shape= [45]
         [[Node: save/Assign_290 = Assign[T=DT_FLOAT, _class=["loc:@yolov3/yolov3_head/Conv_14/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](yolov3/yolov3_head/Conv_14/biases, save/RestoreV2/_581)]]
 

tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [255] rhs shape= [45]
         [[Node: save/Assign_290 = Assign[T=DT_FLOAT, _class=["loc:@yolov3/yolov3_head/Conv_14/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](yolov3/yolov3_head/Conv_14/biases, save/RestoreV2/_581)]]


InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [255] rhs shape= [45]
         [[Node: save/Assign_290 = Assign[T=DT_FLOAT, _class=["loc:@yolov3/yolov3_head/Conv_14/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](yolov3/yolov3_head/Conv_14/biases, save/RestoreV2/_581)]]


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_single_image.py", line 63, in <module>
    saver.restore(sess, args.restore_path)
  File "/gpfsssd/anacondas/ana1/anaconda/envs/env2/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1759, in restore
    err, "a mismatch between the current graph and the graph")
tensorflow.python.framework.errors_impl.InvalidArgumentError: Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:

Assign requires shapes of both tensors to match. lhs shape= [255] rhs shape= [45]
         [[Node: save/Assign_290 = Assign[T=DT_FLOAT, _class=["loc:@yolov3/yolov3_head/Conv_14/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](yolov3/yolov3_head/Conv_14/biases, save/RestoreV2/_581)]]
 

InvalidArgumentError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:

Assign requires shapes of both tensors to match. lhs shape= [255] rhs shape= [45]
         [[Node: save/Assign_290 = Assign[T=DT_FLOAT, _class=["loc:@yolov3/yolov3_head/Conv_14/biases"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](yolov3/yolov3_head/Conv_14/biases, save/RestoreV2/_581)]]

sh-4.2$ python test_single_image.py ./data/demo_data/messi.jpg
/gpfsssd/anacondas/ana1/anaconda/envs/env2/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
2019-08-05 12:20:00.624279: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2019-08-05 12:20:00.886501: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 0 with properties:
name: Tesla P40 major: 6 minor: 1 memoryClockRate(GHz): 1.531
pciBusID: 0000:2d:00.0
totalMemory: 22.38GiB freeMemory: 22.22GiB
2019-08-05 12:20:01.105373: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 1 with properties:
name: Tesla P40 major: 6 minor: 1 memoryClockRate(GHz): 1.531
pciBusID: 0000:31:00.0
totalMemory: 22.38GiB freeMemory: 22.22GiB
2019-08-05 12:20:01.329
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值