如何解决错误:获取参数数组的类型<class'numpy.ndarray'>无效,必须为字符串或张量

时间:2019-07-25 08:32:20

标签: python tensorflow

我想输入1幅彩色图像作为输入,将1个浮点numpy数组作为地面真相,但是错误消息继续出现,我无法理解为什么。

我检查了n_map和dd中的图像是否已加载。我找不到解决方法。

for e in range(500):
    rate = (0.0002)/(e/15+1) # : Decay or Not
    for i in range(7):
        path = 'E:\\PSData\\PSData\\result_\\' + str(i + 1) + '.mat'
        data_mat = scio.loadmat(path)
        d_value = np.flip((data_mat.get('Z')), 0)
        dm = depth_maker(d_value)/rsz_rate
        d_map = cv2.resize(dm, None, fx=1 / rsz_rate, fy=1 / rsz_rate,interpolation=cv2.INTER_AREA)
        sh = int((d_map.shape[0] / 2 - h_ref / 2))
        sw = int((d_map.shape[1] / 2 - w_ref / 2))
        dd = d_map[sh:sh + h_ref, sw:sw + w_ref]            
        n_map = cv2.imread(route_r2d+'nn_'+str(i+1)+'_496.jpg')
        nn = np.expand_dims(n_map,0)
        dd = np.expand_dims(dd,0)
        c,d,t = se.run([cost_d,dd,train],feed_dict={x_n:nn,y_d:dd})

    if e%5 ==0:
        print ("D:",c)
        cv2.imwrite(route_r2d+'d_'+str(i+1)+'.jpg',d[0])

这是错误消息:

TypeError: Can not convert a ndarray into a Tensor or Operation.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/MooNChilD/PycharmProjects/tensorflow prj/venv/find_depth.py", line 198, in <module>
c,d,t = se.run([cost_d,dd,train],feed_dict={x_n:nn,y_d:dd})
File "C:\Users\MooNChilD\PycharmProjects\tensorflow prj\venv\lib\site-packages\tensorflow\python\client\session.py", line 900, in run
run_metadata_ptr)
File "C:\Users\MooNChilD\PycharmProjects\tensorflow prj\venv\lib\site-packages\tensorflow\python\client\session.py", line 1120, in _run
self._graph, fetches, feed_dict_tensor, feed_handles=feed_handles)
File "C:\Users\MooNChilD\PycharmProjects\tensorflow prj\venv\lib\site-packages\tensorflow\python\client\session.py", line 427, in __init__
self._fetch_mapper = _FetchMapper.for_fetch(fetches)
File "C:\Users\MooNChilD\PycharmProjects\tensorflow prj\venv\lib\site-packages\tensorflow\python\client\session.py", line 245, in for_fetch
return _ListFetchMapper(fetch)
File "C:\Users\MooNChilD\PycharmProjects\tensorflow prj\venv\lib\site-packages\tensorflow\python\client\session.py", line 352, in __init__
self._mappers = [_FetchMapper.for_fetch(fetch) for fetch in fetches]
File "C:\Users\MooNChilD\PycharmProjects\tensorflow prj\venv\lib\site-packages\tensorflow\python\client\session.py", line 352, in <listcomp>
self._mappers = [_FetchMapper.for_fetch(fetch) for fetch in fetches]
File "C:\Users\MooNChilD\PycharmProjects\tensorflow prj\venv\lib\site-packages\tensorflow\python\client\session.py", line 253, in for_fetch
return _ElementFetchMapper(fetches, contraction_fn)
File "C:\Users\MooNChilD\PycharmProjects\tensorflow prj\venv\lib\site-packages\tensorflow\python\client\session.py", line 286, in __init__
(fetch, type(fetch), str(e)))

TypeError: Fetch argument array([[[ 0.       ,  0.       ,  5.3772984, ...,  0.       ,          0.       ,  0.       ]]], dtype=float32) has invalid type <class 'numpy.ndarray'>, must be a string or Tensor. (Can not convert a ndarray into a Tensor or Operation.)

0 个答案:

没有答案