加载模型报错:Assign requires shapes of both tensors to match. lhs shape= [8000,100] rhs s

尝试用github上大佬的代码训练一个文本分类器,训练完毕进行预测的时候报错。

大佬代码链接: https://github.com/cjymz886/text-cnn

报错如下:

我进行了分段和标红,方便看

Traceback (most recent call last):
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1356, in _do_call
    return fn(*args)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1341, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1429, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [8000,100] rhs shape= [2865,100]
     [[{{node save/Assign_18}}]]

 

 

 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\training\saver.py", line 1286, in restore
    {self.saver_def.filename_tensor_name: save_path})
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 950, in run
    run_metadata_ptr)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1173, in _run
    feed_dict_tensor, options, run_metadata)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1350, in _do_run
    run_metadata)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\client\session.py", line 1370, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [8000,100] rhs shape= [2865,100]
     [[node save/Assign_18 (defined at D:/zzh/文本分类/text-cnn-master/text_predict.py:43) ]]

 

 

 

 

Errors may have originated from an input operation.
Input Source operations connected to node save/Assign_18:
 embeddings (defined at D:\zzh\文本分类\text-cnn-master\text_model.py:52)

Original stack trace for 'save/Assign_18':
  File "D:/zzh/文本分类/text-cnn-master/text_predict.py", line 136, in
    cat=predict(sentences)
  File "D:/zzh/文本分类/text-cnn-master/text_predict.py", line 43, in predict
    saver = tf.train.Saver()
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\training\saver.py", line 825, in __init__
    self.build()
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\training\saver.py", line 837, in build
    self._build(self._filename, build_save=True, build_restore=True)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\training\saver.py", line 875, in _build
    build_restore=build_restore)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\training\saver.py", line 508, in _build_internal
    restore_sequentially, reshape)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\training\saver.py", line 350, in _AddRestoreOps
    assign_ops.append(saveable.restore(saveable_tensors, shapes))
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\training\saving\saveable_object_util.py", line 72, in restore
    self.op.get_shape().is_fully_defined())
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\ops\state_ops.py", line 227, in assign
    validate_shape=validate_shape)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\ops\gen_state_ops.py", line 69, in assign
    use_locking=use_locking, name=name)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 788, in _apply_op_helper
    op_def=op_def)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\util\deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\ops.py", line 3616, in create_op
    op_def=op_def)
  File "C:\Users\YOUPU-Better\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\ops.py", line 2005, in __init__
    self._traceback = tf_stack.extract_stack()

 

 

百思不得其解,甚至去github上面提了问。。。呜呜呜好羞愧

最后仔细观察报错:

tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [8000,100] rhs shape= [2865,100]
     [[{{node save/Assign_18}}]]

他说有一个tensor的shape是8000,100,然后现在是2865,100

。。。咦

我好像少调了一个参数

。。。orz

加载模型报错:Assign requires shapes of both tensors to match. lhs shape= [8000,100] rhs s_第1张图片

在text_model里面把8000改成2865,再运行,完成。

 

嘤 我好菜啊呜呜呜

你可能感兴趣的:(error)