NotImplementedError: Cannot convert a symbolic Tensor (strided_slice:0) to a numpy array (lower version not required)

This problem is generally caused by three reasons: lowering/increasing the numpy version, lowering/increasing the tensorflow version. This is easy to find. Here is a method that does not require version updating.

Note: There are multiple solutions in github at the bottom.

Solve the bug by modifying array_ops.py

1. Find the location where tensorflow is installed through pip. If you don’t know, just pip install tensorflow directly. The system will prompt that tensorflow has been installed. Find this path.

# 找到 array_ops.py 的路径
cd C:\Users\USERNAME\anaconda3\Lib\site-packages\tensorflow\python\ops\

2. Modify the array_ops.py file (remember to back up the source file)

cp array_ops.py  array_ops_copy.py
vi array_ops.py 

3. In the import section at the beginning, add the following content to import this package

from tensorflow.python.ops.math_ops import reduce_prod

Then search for the following method def _constant_if_small, and replace the original method with the following content. Search in vim to press ESC, then press /, and then enter the search content 

def _constant_if_small(value, shape, dtype, name):
  try:
    if reduce_prod(shape) < 1000:
      return constant(value, shape=shape, dtype=dtype, name=name)
  except TypeError:
    # Happens when shape is a Tensor, list with Tensor elements, etc.
    pass
  return None

reference:

NotImplementedError: Cannot convert a symbolic Tensor (strided_slice:0) to a numpy array. · Issue #9706 · tensorflow/models · GitHub

Guess you like

Origin blog.csdn.net/qq_37424778/article/details/123536772