首页 > 解决方案 > 如何将张量转换为numpy数组matmul的结果

问题描述

我想将 fc1 张量转换为 numpy 数组。如何得到它?

fc1 = tf.reshape(conv1, [-1, weights['wd1'].get_shape().as_list()[0]])
fc1 = tf.matmul(fc1, weights['wd1'])

标签: python

解决方案


它会导致此错误

    fc1 = tf.reshape(conv1, [-1, weights['wd1'].get_shape().as_list()[0]])
    fc1 = tf.matmul(fc1, weights['wd1'])
    sess = tf.Session()
    fc1.eval(session=sess)

    Traceback (most recent call last):
  File "C:/Users/ybrot/OneDrive/바탕 화면/QCNN/QCNN.py", line 150, in <module>
    logits = conv_net(X, weights, keep_prob)
  File "C:/Users/ybrot/OneDrive/바탕 화면/QCNN/QCNN.py", line 114, in conv_net
    fc1.eval(session=sess)
  File "C:\Users\ybrot\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 731, in eval
    return _eval_using_default_session(self, feed_dict, self.graph, session)
  File "C:\Users\ybrot\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 5579, in _eval_using_default_session
    return session.run(tensors, feed_dict)
  File "C:\Users\ybrot\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 950, in run
    run_metadata_ptr)
  File "C:\Users\ybrot\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1173, in _run
    feed_dict_tensor, options, run_metadata)
  File "C:\Users\ybrot\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1350, in _do_run
    run_metadata)
  File "C:\Users\ybrot\Anaconda3\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: 2 root error(s) found.
  (0) Invalid argument: You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [?,256]
     [[node Placeholder (defined at /Users/ybrot/OneDrive/바탕 화면/QCNN/QCNN.py:54) ]]
     [[MatMul/_1]]
  (1) Invalid argument: You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [?,256]
     [[node Placeholder (defined at /Users/ybrot/OneDrive/바탕 화면/QCNN/QCNN.py:54) ]]
0 successful operations.
0 derived errors ignored.

推荐阅读