Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotImplementedError: Cannot convert a symbolic Tensor (strided_slice:0) to a numpy array. #9706

Open
3 tasks done
aniketbote opened this issue Feb 5, 2021 · 67 comments
Open
3 tasks done
Assignees
Labels

Comments

@aniketbote
Copy link

aniketbote commented Feb 5, 2021

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am using the latest TensorFlow Model Garden release and TensorFlow 2.
  • I am reporting the issue to the correct repository. (Model Garden research directory)
  • I checked to make sure that this issue has not already been filed.

1. The entire URL of the file you are using

https://github.com/tensorflow/models/blob/master/research/object_detection/model_main_tf2.py

2. Describe the bug

I am trying to train object detection model for custom data using tutorial on link. I tested the for environment faults using https://github.com/tensorflow/models/blob/master/research/object_detection/builders/model_builder_tf2_test.py. All test passed. But when I put it for training the models gives out error.
Logs:

2021-02-05 14:26:00.620416: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-02-05 14:26:03.557625: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2021-02-05 14:26:03.790381: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0002:00:00.0 name: Tesla M60 computeCapability: 5.2
coreClock: 1.1775GHz coreCount: 16 deviceMemorySize: 7.92GiB deviceMemoryBandwidth: 149.31GiB/s
2021-02-05 14:26:03.796912: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-02-05 14:26:03.805410: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-02-05 14:26:03.813387: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-02-05 14:26:03.817933: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-02-05 14:26:03.827291: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2021-02-05 14:26:03.834728: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-02-05 14:26:03.850086: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2021-02-05 14:26:03.857292: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2021-02-05 14:26:03.860948: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-02-05 14:26:03.875535: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x80ec5ff940 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-02-05 14:26:03.880482: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2021-02-05 14:26:03.885168: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0002:00:00.0 name: Tesla M60 computeCapability: 5.2
coreClock: 1.1775GHz coreCount: 16 deviceMemorySize: 7.92GiB deviceMemoryBandwidth: 149.31GiB/s
2021-02-05 14:26:03.891972: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-02-05 14:26:03.895720: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-02-05 14:26:03.899501: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-02-05 14:26:03.904606: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-02-05 14:26:03.908422: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2021-02-05 14:26:03.912343: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-02-05 14:26:03.916413: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2021-02-05 14:26:03.924000: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2021-02-05 14:26:04.700603: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength
1 edge matrix:
2021-02-05 14:26:04.704509: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0
2021-02-05 14:26:04.706737: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N
2021-02-05 14:26:04.726496: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7048 MB memory) -> physical GPU (device: 0, name: Tesla M60, pci bus id: 0002:00:00.0, compute capability: 5.2)
2021-02-05 14:26:04.736932: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x810d9b6950 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2021-02-05 14:26:04.741982: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Tesla M60, Compute Capability 5.2
INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0',)
I0205 14:26:04.749317  8188 mirrored_strategy.py:500] Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0',)
INFO:tensorflow:Maybe overwriting train_steps: None
I0205 14:26:04.755326  8188 config_util.py:552] Maybe overwriting train_steps: None
INFO:tensorflow:Maybe overwriting use_bfloat16: False
I0205 14:26:04.755326  8188 config_util.py:552] Maybe overwriting use_bfloat16: False
INFO:tensorflow:Reading unweighted datasets: ['E:/DS_2020_Wildlife/Multi_Class_Classification/Tensorflow/workspace/annotations/train.record']
I0205 14:26:04.923312  8188 dataset_builder.py:163] Reading unweighted datasets: ['E:/DS_2020_Wildlife/Multi_Class_Classification/Tensorflow/workspace/annotations/train.record']
INFO:tensorflow:Reading record datasets for input file: ['E:/DS_2020_Wildlife/Multi_Class_Classification/Tensorflow/workspace/annotations/train.record']
I0205 14:26:04.926311  8188 dataset_builder.py:80] Reading record datasets for input file: ['E:/DS_2020_Wildlife/Multi_Class_Classification/Tensorflow/workspace/annotations/train.record']
INFO:tensorflow:Number of filenames to read: 1
I0205 14:26:04.926311  8188 dataset_builder.py:81] Number of filenames to read: 1
WARNING:tensorflow:num_readers has been reduced to 1 to match input file shards.
W0205 14:26:04.926311  8188 dataset_builder.py:87] num_readers has been reduced to 1 to match input file shards.
WARNING:tensorflow:From E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\object_detection\builders\dataset_builder.py:101: parallel_interleave (from tensorflow.python.data.experimental.ops.interleave_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.interleave(map_func, cycle_length, block_length, num_parallel_calls=tf.data.experimental.AUTOTUNE)` instead. If sloppy execution is desired, use `tf.data.Options.experimental_deterministic`.
W0205 14:26:04.928313  8188 deprecation.py:317] From E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\object_detection\builders\dataset_builder.py:101: parallel_interleave (from tensorflow.python.data.experimental.ops.interleave_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.interleave(map_func, cycle_length, block_length, num_parallel_calls=tf.data.experimental.AUTOTUNE)` instead. If sloppy execution is desired, use `tf.data.Options.experimental_deterministic`.
WARNING:tensorflow:From E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\object_detection\builders\dataset_builder.py:236: DatasetV1.map_with_legacy_function (from tensorflow.python.data.ops.dataset_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.map()
W0205 14:26:04.952313  8188 deprecation.py:317] From E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\object_detection\builders\dataset_builder.py:236: DatasetV1.map_with_legacy_function (from tensorflow.python.data.ops.dataset_ops) is
deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.data.Dataset.map()
Traceback (most recent call last):
  File "model_main_tf2.py", line 115, in <module>
    tf.compat.v1.app.run()
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\platform\app.py", line 40,
in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\absl\app.py", line 300, in run
    _run_main(main, args)
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\absl\app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "model_main_tf2.py", line 106, in main
    model_lib_v2.train_loop(
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\object_detection\model_lib_v2.py", line 569,
in train_loop
    load_fine_tune_checkpoint(detection_model,
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\object_detection\model_lib_v2.py", line 352,
in load_fine_tune_checkpoint
    features, labels = iter(input_dataset).next()
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\distribute\input_lib.py", line 858, in __iter__
    iterators, element_spec = _create_iterators_per_worker_with_input_context(
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\distribute\input_lib.py", line 1401, in _create_iterators_per_worker_with_input_context
    dataset = dataset_fn(ctx)
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\object_detection\model_lib_v2.py", line 521,
in train_dataset_fn
    train_input = inputs.train_input(
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\object_detection\inputs.py", line 893, in train_input
    dataset = INPUT_BUILDER_UTIL_MAP['dataset_build'](
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\object_detection\builders\dataset_builder.py", line 251, in build
    dataset = dataset_map_fn(dataset, decoder.decode, batch_size,
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\object_detection\builders\dataset_builder.py", line 236, in dataset_map_fn
    dataset = dataset.map_with_legacy_function(
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\util\deprecation.py", line
324, in new_func
    return func(*args, **kwargs)
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py", line 2402, in map_with_legacy_function
    ParallelMapDataset(
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py", line 4016, in __init__
    self._map_func = StructuredFunctionWrapper(
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py", line 3196, in __init__
    self._function.add_to_graph(ops.get_default_graph())
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\framework\function.py", line 544, in add_to_graph
    self._create_definition_if_needed()
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\framework\function.py", line 376, in _create_definition_if_needed
    self._create_definition_if_needed_impl()
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\framework\function.py", line 398, in _create_definition_if_needed_impl
    temp_graph = func_graph_from_py_func(
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\framework\function.py", line 969, in func_graph_from_py_func
    outputs = func(*func_graph.inputs)
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py", line 3188, in wrapper_fn
    ret = _wrapper_helper(*args)
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py", line 3156, in _wrapper_helper
    ret = autograph.tf_convert(func, ag_ctx)(*nested_args)
  File "E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\autograph\impl\api.py", line 265, in wrapper
    raise e.ag_error_metadata.to_exception(e)
NotImplementedError: in user code:

    E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\object_detection\data_decoders\tf_example_decoder.py:524 default_groundtruth_weights  *
        [tf.shape(tensor_dict[fields.InputDataFields.groundtruth_boxes])[0]],
    E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\ops\array_ops.py:2967 ones  **
        output = _constant_if_small(one, shape, dtype, name)
    E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\ops\array_ops.py:2662 _constant_if_small
        if np.prod(shape) < 1000:
    <__array_function__ internals>:5 prod

    E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\numpy\core\fromnumeric.py:3030 prod
        return _wrapreduction(a, np.multiply, 'prod', axis, dtype, out,
    E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\numpy\core\fromnumeric.py:87 _wrapreduction
        return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
    E:\DS_2020_Wildlife\Multi_Class_Classification\Tensorflow\venv\lib\site-packages\tensorflow\python\framework\ops.py:748 __array__
        raise NotImplementedError("Cannot convert a symbolic Tensor ({}) to a numpy"

    NotImplementedError: Cannot convert a symbolic Tensor (strided_slice:0) to a numpy array.

6. System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows Sever 2012
  • TensorFlow installed from (source or binary): PIP
  • TensorFlow version (use command below): 2.2
  • Python version: 3.8
  • CUDA/cuDNN version: 10.1
  • GPU model and memory: Tesla M60
@aniketbote aniketbote added models:research models that come under research directory type:bug Bug in the code labels Feb 5, 2021
@dademiller360
Copy link

dademiller360 commented Feb 5, 2021

System information
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Archlinux
TensorFlow installed from (source or binary): PIP
TensorFlow version (use command below): 2.4.1
Python version: 3.8
CUDA/cuDNN version: cudaToolkit 10.1 cuDnn 7.6.5
GPU model and memory: Quadro M2000

I have the same error if I use numpy 1.20.0
NotImplementedError: Cannot convert a symbolic Tensor (cond_2/strided_slice:0) to a numpy array.

if I use numpy 1.19.5 I get
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

Tried with TF 2.2.2 as well in both cases same errors

@dademiller360
Copy link

fixed using python 3.6

@aniketbote
Copy link
Author

fixed using python 3.6

Thank you @dademiller360 changing the Python version from 3.8 to 3.6 fixed the issue.
@saikumarchalla Can you clarify if this is intended behavior or a bug? If it's not a bug you can close the issue.

@CloneHub94
Copy link

CloneHub94 commented Feb 12, 2021

I have the same problem but when I modify from Python 3.8.5 to 3.6 I get the following error:

Traceback (most recent call last):
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "model_main_tf2.py", line 31, in
import tensorflow.compat.v2 as tf
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_init_.py", line 41, in
from tensorflow.python.tools import module_util as module_util
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python_init
.py", line 39, in
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed: The specified module could not be found.

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

Anybody know how to fix this issue?

@AKuperus7
Copy link

Same issue, but when I switch to Python 3.6 and try to install the Tensorflow Object Detection API using the research/object_detection/packages/tf2/setup.py file, I get this error:

Traceback (most recent call last):
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 152, in save_modules
    yield saved
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 193, in setup_context
    yield
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 254, in run_setup
    _execfile(setup_script, ns)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 43, in _execfile
    exec(code, globals, locals)
  File "C:\Users\tinyr\AppData\Local\Temp\easy_install-3subbki0\pandas-1.2.2\setup.py", line 761, in <module>
  File "C:\Users\tinyr\AppData\Local\Temp\easy_install-3subbki0\pandas-1.2.2\setup.py", line 731, in setup_package
  File "C:\Users\tinyr\AppData\Local\Temp\easy_install-3subbki0\pandas-1.2.2\setup.py", line 505, in maybe_cythonize
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\Cython\Build\Dependencies.py", line 1079, in cythonize
    nthreads, initializer=_init_multiprocessing_helper)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\context.py", line 119, in Pool
    context=self.get_context())
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\pool.py", line 174, in __init__
    self._repopulate_pool()
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\pool.py", line 239, in _repopulate_pool
    w.start()
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\popen_spawn_win32.py", line 43, in __init__
    with open(wfd, 'wb', closefd=True) as to_child:
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 421, in _open
    if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path):
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 432, in _ok
    realpath = os.path.normcase(os.path.realpath(path))
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\ntpath.py", line 548, in abspath
    return normpath(_getfullpathname(path))
TypeError: _getfullpathname: path should be string, bytes or os.PathLike, not int

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "object_detection/packages/tf2/setup.py", line 43, in <module>
    python_requires='>3.6',
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\command\install.py", line 67, in run
    self.do_egg_install()
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\command\install.py", line 117, in do_egg_install
    cmd.run(show_deprecation=False)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\command\easy_install.py", line 408, in run
    self.easy_install(spec, not self.no_deps)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\command\easy_install.py", line 650, in easy_install
    return self.install_item(None, spec, tmpdir, deps, True)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\command\easy_install.py", line 697, in install_item
    self.process_distribution(spec, dist, deps)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\command\easy_install.py", line 745, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\pkg_resources\__init__.py", line 768, in resolve
    replace_conflicting=replace_conflicting
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\pkg_resources\__init__.py", line 1051, in best_match
    return self.obtain(req, installer)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\pkg_resources\__init__.py", line 1063, in obtain
    return installer(requirement)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\command\easy_install.py", line 669, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\command\easy_install.py", line 695, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\command\easy_install.py", line 890, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\command\easy_install.py", line 1162, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\command\easy_install.py", line 1146, in run_setup
    run_setup(setup_script, args)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 257, in run_setup
    raise
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 193, in setup_context
    yield
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 164, in save_modules
    saved_exc.resume()
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 139, in resume
    raise exc.with_traceback(self._tb)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 152, in save_modules
    yield saved
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 193, in setup_context
    yield
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 254, in run_setup
    _execfile(setup_script, ns)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 43, in _execfile
    exec(code, globals, locals)
  File "C:\Users\tinyr\AppData\Local\Temp\easy_install-3subbki0\pandas-1.2.2\setup.py", line 761, in <module>
  File "C:\Users\tinyr\AppData\Local\Temp\easy_install-3subbki0\pandas-1.2.2\setup.py", line 731, in setup_package
  File "C:\Users\tinyr\AppData\Local\Temp\easy_install-3subbki0\pandas-1.2.2\setup.py", line 505, in maybe_cythonize
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\Cython\Build\Dependencies.py", line 1079, in cythonize
    nthreads, initializer=_init_multiprocessing_helper)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\context.py", line 119, in Pool
    context=self.get_context())
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\pool.py", line 174, in __init__
    self._repopulate_pool()
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\pool.py", line 239, in _repopulate_pool
    w.start()
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\multiprocessing\popen_spawn_win32.py", line 43, in __init__
    with open(wfd, 'wb', closefd=True) as to_child:
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 421, in _open
    if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path):
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\site-packages\setuptools\sandbox.py", line 432, in _ok
    realpath = os.path.normcase(os.path.realpath(path))
  File "C:\Users\tinyr\anaconda3\envs\squirrel\lib\ntpath.py", line 548, in abspath
    return normpath(_getfullpathname(path))
TypeError: _getfullpathname: path should be string, bytes or os.PathLike, not int

@CloneHub94
Copy link

In the meantime I solve it by using colab for my object detection. But I would like to be able to use my pc as well

@aniketbote
Copy link
Author

I have the same problem but when I modify from Python 3.8.5 to 3.6 I get the following error:

Traceback (most recent call last):
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "model_main_tf2.py", line 31, in
import tensorflow.compat.v2 as tf
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow__init__.py", line 41, in
from tensorflow.python.tools import module_util as module_util File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python__init_.py", line 39, in
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed: The specified module could not be found.

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

Anybody know how to fix this issue?

Have you installed tensorflow correctly? This may be due to C++ executables not present in your system.

@CloneHub94
Copy link

These are the results that I get when I lookup my tensorflow installation. Is there something that is missing?
image

@aniketbote
Copy link
Author

These are the results that I get when I lookup my tensorflow installation. Is there something that is missing?
image

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
Can you check if this works?
If this works tensorflow is correctly installed. Else there is something wrong with tensorflow installation rather than object detection API.

@CloneHub94
Copy link

This is the results I get:

image

@rav-en
Copy link

rav-en commented Feb 21, 2021

This is the results I get:

image

I have the same error as what you are getting. im using numpy 1.20.0 with Tensorflow 2.4.1

I'm convinced that numpy is the problem but im honestly too new at training models and using TF etc.
This is the tutorial ive been following https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html

Have you had any luck with solving this issue?

@CloneHub94
Copy link

No, unfortunatly. Just using colab for the moment and hopping that the inference part of tensorflow object detection does work on my computer

@dademiller360
Copy link

This is the results I get:
image

I have the same error as what you are getting. im using numpy 1.20.0 with Tensorflow 2.4.1

I'm convinced that numpy is the problem but im honestly too new at training models and using TF etc.
This is the tutorial ive been following https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html

Have you had any luck with solving this issue?

Try to downgrade numpy to
numpy 1.19.5 pypi_0 pypi

pip install numpy==1.19.5

after that, check with conda list which numpy version you have installed

@CloneHub94
Copy link

@dademiller360 The problem is if we do that we get the error mentioned earlier ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from. Some people are able to solve this by downgrading to Python 3.6. But if I do that I get the error from my first post:

Traceback (most recent call last):
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "model_main_tf2.py", line 31, in
import tensorflow.compat.v2 as tf
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow__init__.py", line 41, in
from tensorflow.python.tools import module_util as module_util File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python__init_.py", line 39, in
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "D:\Maurice_Doc\AI\anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed: The specified module could not be found.

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

@glemarivero
Copy link

glemarivero commented Mar 5, 2021

Hi @aniketbote I posted this answer in Stack Overflow: https://stackoverflow.com/questions/66373169/tensorflow-2-object-detection-api-numpy-version-errors/66486051#66486051

I had this same issue:

NotImplementedError: Cannot convert a symbolic Tensor (cond_2/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

The problem was fixed by changing np.prod for reduce_prod in this function https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/array_ops.py

def _constant_if_small(value, shape, dtype, name):
  try:
    if np.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

Note that you need to import reduce_prod at the top of the file:

from tensorflow.math import reduce_prod

@redradist
Copy link

redradist commented Mar 6, 2021

@glemarivero

Hi @aniketbote I posted this answer in Stack Overflow: https://stackoverflow.com/questions/66373169/tensorflow-2-object-detection-api-numpy-version-errors/66486051#66486051

I had this same issue:

NotImplementedError: Cannot convert a symbolic Tensor (cond_2/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

The problem was fixed by changing np.prod for reduce_prod in this function https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/array_ops.py

def _constant_if_small(value, shape, dtype, name):
  try:
    if np.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

Note that you need to import reduce_prod at the top of the file:

from tensorflow.math import reduce_prod

I was able to fix issue like you described but by importing reduc_prod as:

from tensorflow.python.ops.math_ops import reduce_prod
...

Seems like it is a bug in tensorflow

@Pipickin
Copy link

@glemarivero

Hi @aniketbote I posted this answer in Stack Overflow: https://stackoverflow.com/questions/66373169/tensorflow-2-object-detection-api-numpy-version-errors/66486051#66486051
I had this same issue:

NotImplementedError: Cannot convert a symbolic Tensor (cond_2/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

The problem was fixed by changing np.prod for reduce_prod in this function https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/array_ops.py

def _constant_if_small(value, shape, dtype, name):
  try:
    if np.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

Note that you need to import reduce_prod at the top of the file:

from tensorflow.math import reduce_prod

I was able to fix issue like you described but by importing reduc_prod as:

from tensorflow.python.ops.math_ops import reduce_prod
...

Seems like it is a bug in tensorflow

Hello, I'm new to tf object detection.
I had the same error but after I changed import this error was gone out. But I got new error:

Fatal Python error: Aborted

Thread 0x00007f505b7fe700 (most recent call first):
File "/usr/lib/python3.7/threading.py", line 296 in wait
File "/usr/lib/python3.7/queue.py", line 170 in get
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/summary/writer/event_file_writer.py", line 159 in run
File "/usr/lib/python3.7/threading.py", line 926 in _bootstrap_inner
File "/usr/lib/python3.7/threading.py", line 890 in _bootstrap

Current thread 0x00007f50f699f740 (most recent call first):
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 699 in init
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1585 in init
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/training/session_manager.py", line 194 in _restore_checkpoint
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/training/session_manager.py", line 290 in prepare_session
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/training/supervisor.py", line 734 in prepare_or_wait_for_session
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/training/supervisor.py", line 1003 in managed_session
File "/usr/lib/python3.7/contextlib.py", line 112 in enter
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tf_slim/learning.py", line 745 in train
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/object_detection-0.1-py3.7.egg/object_detection/legacy/trainer.py", line 415 in train
File "train.py", line 182 in main
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 324 in new_func
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/absl/app.py", line 251 in _run_main
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/absl/app.py", line 303 in run
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/platform/app.py", line 40 in run
File "train.py", line 186 in
Aborted (core dumped)

Did you face this probled before? Or do you have any idea about this error?

@Pipickin
Copy link

@glemarivero

Hi @aniketbote I posted this answer in Stack Overflow: https://stackoverflow.com/questions/66373169/tensorflow-2-object-detection-api-numpy-version-errors/66486051#66486051
I had this same issue:

NotImplementedError: Cannot convert a symbolic Tensor (cond_2/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

The problem was fixed by changing np.prod for reduce_prod in this function https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/array_ops.py

def _constant_if_small(value, shape, dtype, name):
  try:
    if np.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

Note that you need to import reduce_prod at the top of the file:

from tensorflow.math import reduce_prod

I was able to fix issue like you described but by importing reduc_prod as:

from tensorflow.python.ops.math_ops import reduce_prod
...

Seems like it is a bug in tensorflow

Hello, I'm new to tf object detection.
I had the same error but after I changed import this error was gone out. But I got new error:

Fatal Python error: Aborted

Thread 0x00007f505b7fe700 (most recent call first):
File "/usr/lib/python3.7/threading.py", line 296 in wait
File "/usr/lib/python3.7/queue.py", line 170 in get
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/summary/writer/event_file_writer.py", line 159 in run
File "/usr/lib/python3.7/threading.py", line 926 in _bootstrap_inner
File "/usr/lib/python3.7/threading.py", line 890 in _bootstrap

Current thread 0x00007f50f699f740 (most recent call first):
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 699 in init
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1585 in init
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/training/session_manager.py", line 194 in _restore_checkpoint
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/training/session_manager.py", line 290 in prepare_session
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/training/supervisor.py", line 734 in prepare_or_wait_for_session
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/training/supervisor.py", line 1003 in managed_session
File "/usr/lib/python3.7/contextlib.py", line 112 in enter
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tf_slim/learning.py", line 745 in train
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/object_detection-0.1-py3.7.egg/object_detection/legacy/trainer.py", line 415 in train
File "train.py", line 182 in main
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/util/deprecation.py", line 324 in new_func
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/absl/app.py", line 251 in _run_main
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/absl/app.py", line 303 in run
File "/home/vlad/.virtualenvs/tf1_obj_det_p37/lib/python3.7/site-packages/tensorflow_core/python/platform/app.py", line 40 in run
File "train.py", line 186 in
Aborted (core dumped)

Did you face this probled before? Or do you have any idea about this error?

I fixed this by adding CUDA_VISIBLE_DEVICES=""

@glemarivero
Copy link

@Pipickin
But then you are running the training on CPU and not GPU.
Were you able to train anything else? Just want to know if CUDA is setup correctly.

@hayk314
Copy link

hayk314 commented Mar 30, 2021

I had the same issue with newly installed tensorflow 2.2.0 and python 3.8.5.
Installing tensorflow with pip will install numpy version 1.20.2. You can then downgrade numpy to version 1.18.4 (just uninstall with pip and install that particular version). Then everything works perfectly fine.

@Pipickin
Copy link

@glemarivero
Hello. I trained my model via google colab, because I have not enough Capability on my GPU (I didn't even try do it). I was wondering why I got the error above

@Reflectioner
Copy link

i was able to fix issue
Go to C:\Users\khana\miniconda3\envs\tutorialenv\Lib\site-packages\tensorflow\python\ops\array_ops.py
Add - from tensorflow.python.ops.math_ops import reduce_prod
Change to this 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
tensorflow - 2.5.0
python - 3.7.0

This is the perfect solution without downgrading numpy or any things.

In case you are in base conda env then the Path will be like this :

C:\Users\USERNAME\anaconda3\Lib\site-packages\tensorflow\python\ops\array_ops.py

Just open the file in any editor
Add the following lines in starting to import

from tensorflow.python.ops.math_ops import reduce_prod

then search for def _constant_if_small and then replace the entire function to this :

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

P.S : My python version : 3.8.5, Numpy Version : 1.21.0 & tensorflow version : '2.4.0'

perfect, thanks a lot man, just a little touch I had to do:
instead of reduce_prod I had to add:
import tensorflow as tf
and:
instead of reduce_prod -> tf.math.reduce_prod
other then that everything is perfect didn't need to downgrade or install anything

@fudingyu
Copy link

i was able to fix issue
Go to C:\Users\khana\miniconda3\envs\tutorialenv\Lib\site-packages\tensorflow\python\ops\array_ops.py
Add - from tensorflow.python.ops.math_ops import reduce_prod
Change to this 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
tensorflow - 2.5.0
python - 3.7.0

This is the perfect solution without downgrading numpy or any things.

In case you are in base conda env then the Path will be like this :

C:\Users\USERNAME\anaconda3\Lib\site-packages\tensorflow\python\ops\array_ops.py

Just open the file in any editor
Add the following lines in starting to import

from tensorflow.python.ops.math_ops import reduce_prod

then search for def _constant_if_small and then replace the entire function to this :

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

P.S : My python version : 3.8.5, Numpy Version : 1.21.0 & tensorflow version : '2.4.0'

Thank you, this method has worked.

@Reflectioner your solution also worked.

@ljubantomic01
Copy link

i was able to fix issue
Go to C:\Users\khana\miniconda3\envs\tutorialenv\Lib\site-packages\tensorflow\python\ops\array_ops.py
Add - from tensorflow.python.ops.math_ops import reduce_prod
Change to this 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
tensorflow - 2.5.0
python - 3.7.0

This is the perfect solution without downgrading numpy or any things.
In case you are in base conda env then the Path will be like this :

C:\Users\USERNAME\anaconda3\Lib\site-packages\tensorflow\python\ops\array_ops.py

Just open the file in any editor
Add the following lines in starting to import

from tensorflow.python.ops.math_ops import reduce_prod

then search for def _constant_if_small and then replace the entire function to this :

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

P.S : My python version : 3.8.5, Numpy Version : 1.21.0 & tensorflow version : '2.4.0'

perfect, thanks a lot man, just a little touch I had to do:
instead of reduce_prod I had to add:
import tensorflow as tf
and:
instead of reduce_prod -> tf.math.reduce_prod
other then that everything is perfect didn't need to downgrade or install anything

It worked 👍 ! In my case array_ops.py was in .../site-packages/tensorflow-core/python/

@danielTobon43
Copy link

danielTobon43 commented Aug 31, 2021

Hi @aniketbote I posted this answer in Stack Overflow: https://stackoverflow.com/questions/66373169/tensorflow-2-object-detection-api-numpy-version-errors/66486051#66486051

I had this same issue:

NotImplementedError: Cannot convert a symbolic Tensor (cond_2/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

The problem was fixed by changing np.prod for reduce_prod in this function https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/array_ops.py

def _constant_if_small(value, shape, dtype, name):
  try:
    if np.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

Note that you need to import reduce_prod at the top of the file:

from tensorflow.math import reduce_prod

Wonderful.

In my case, it works for:

  • Tensorflow 2.5
  • Numpy 1.21.2
  • Python 3.8.10

I changed the import from tensorflow.math import reduce_prod to import tensorflow as tf
and in the def _constant_if_small function I used:
tf.math.reduce_prod according to the tf.math documentation for tf 2.5: https://www.tensorflow.org/api_docs/python/tf/math/reduce_prod?hl=ar

@MeghanshBansal
Copy link

I am having the same error, I am also using the latest version of anaconda with TensorFlow version 2.3.0.

The program was working with the general installation of TensorFlow with pip. It is not working with anaconda.

@danielTobon43
Copy link

@MeghanshBansal try to replace the lines on C:\Users\USERNAME\anaconda3\Lib\site-packages\tensorflow\python\ops\array_ops.py

@Matthew1309
Copy link

Matthew1309 commented Oct 15, 2021

Idk if this will help anyone, but I also got the NotImplementedError: Cannot convert a symbolic Tensor (strided_slice:0) to a numpy array. error. I don't know if all the previous error messages were the same, and I am kicking myself for not saving them, but I was very baffled by the problem.

I run my jupyter notebook in a conda envirnoment I have called tensorflow. Here is the .yml file I build it from:

name: tensorflow

channels:
    - conda-forge
    - anaconda
dependencies:
    - python=3.8
    - pip>=19.0
    - ipykernel
    - jupyter
    - jupyterlab
    - scikit-learn
    - scipy
    - pandas
    - pandas-datareader
    - matplotlib
    - pillow
    - tqdm
    - requests
    - h5py
    - pyyaml
    - flask
    - boto3
    - pip:
        - tensorflow==2.4
        - bayesian-optimization
        - gym
        - kaggle

It ran perfectly fine a few days ago, I took a break and tried to run the exact same code today, and I got that error above! I changed nothing, and it was very very confusing. I just restarted my computer and suddenly the issue is gone. Does anyone have an explaination? I'm not sure how to recreate it, but here is what I had

from tensorflow.keras.callbacks import LambdaCallback
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import LSTM
from tensorflow.keras.optimizers import RMSprop
from tensorflow.keras.utils import get_file
from tensorflow.python.ops.math_ops import reduce_prod
import numpy as np
import pandas as pd
import random
import sys
import io
import requests
import re
print('Build model')
model = Sequential()
model.add(LSTM(128, input_shape=(14, 1)))
model.add( Dense(9, activation='softmax') )

optimizer = RMSprop(lr=0.01)
model.compile(loss='categorical_crossentropy', optimizer=optimizer)

Edit: I was reading and tried the reduce_prod import which wasn't working and forgot it was in my list of imports. Commenting it out still runs without that error.

@yangleir
Copy link

yangleir commented Oct 22, 2021

After edit the array_ops.py as mentioned above, I still have errors:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
/tmp/ipykernel_6878/1920925617.py in <module>
     34     # fit model
     35     es = EarlyStopping(monitor='val_loss', mode='min', verbose=1,patience=pat)
---> 36     history=model.fit(X, y, batch_size=batch_size, epochs=n_epochs, verbose=1, shuffle=False, validation_split=val_split, callbacks=[es])
     37 
     38     model.save(model_name)

~/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
   1156                 _r=1):
   1157               callbacks.on_train_batch_begin(step)
-> 1158               tmp_logs = self.train_function(iterator)
   1159               if data_handler.should_sync:
   1160                 context.async_wait()

~/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds)
    887 
    888       with OptionalXlaContext(self._jit_compile):
--> 889         result = self._call(*args, **kwds)
    890 
    891       new_tracing_count = self.experimental_get_tracing_count()

~/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
    931       # This is the first call of __call__, so we have to initialize.
    932       initializers = []
--> 933       self._initialize(args, kwds, add_initializers_to=initializers)
    934     finally:
    935       # At this point we know that the initialization is complete (or less

~/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in _initialize(self, args, kwds, add_initializers_to)
    761     self._graph_deleter = FunctionDeleter(self._lifted_initializer_graph)
    762     self._concrete_stateful_fn = (
--> 763         self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
    764             *args, **kwds))
    765 

~/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/eager/function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
   3048       args, kwargs = None, None
   3049     with self._lock:
-> 3050       graph_function, _ = self._maybe_define_function(args, kwargs)
   3051     return graph_function
   3052 

~/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/eager/function.py in _maybe_define_function(self, args, kwargs)
   3442 
   3443           self._function_cache.missed.add(call_context_key)
-> 3444           graph_function = self._create_graph_function(args, kwargs)
   3445           self._function_cache.primary[cache_key] = graph_function
   3446 

~/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/eager/function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes)
   3277     arg_names = base_arg_names + missing_arg_names
   3278     graph_function = ConcreteFunction(
-> 3279         func_graph_module.func_graph_from_py_func(
   3280             self._name,
   3281             self._python_function,

~/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py in func_graph_from_py_func(name, python_func, args, kwargs, signature, func_graph, autograph, autograph_options, add_control_dependencies, arg_names, op_return_value, collections, capture_by_value, override_flat_arg_shapes)
    997         _, original_func = tf_decorator.unwrap(python_func)
    998 
--> 999       func_outputs = python_func(*func_args, **func_kwargs)
   1000 
   1001       # invariant: `func_outputs` contains only Tensors, CompositeTensors,

~/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in wrapped_fn(*args, **kwds)
    670         # the function a weak reference to itself to avoid a reference cycle.
    671         with OptionalXlaContext(compile_with_xla):
--> 672           out = weak_wrapped_fn().__wrapped__(*args, **kwds)
    673         return out
    674 

~/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs)
    984           except Exception as e:  # pylint:disable=broad-except
    985             if hasattr(e, "ag_error_metadata"):
--> 986               raise e.ag_error_metadata.to_exception(e)
    987             else:
    988               raise

NotImplementedError: in user code:

    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/engine/training.py:830 train_function  *
        return step_function(self, iterator)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/engine/training.py:813 run_step  *
        outputs = model.train_step(data)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/engine/training.py:770 train_step  *
        y_pred = self(x, training=True)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/engine/base_layer.py:1006 __call__  *
        outputs = call_fn(inputs, *args, **kwargs)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/engine/sequential.py:389 call  *
        outputs = layer(inputs, **kwargs)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/layers/recurrent.py:660 __call__  *
        return super(RNN, self).__call__(inputs, **kwargs)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/engine/base_layer.py:1006 __call__  *
        outputs = call_fn(inputs, *args, **kwargs)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/layers/recurrent_v2.py:1139 call  *
        inputs, initial_state, _ = self._process_inputs(inputs, initial_state, None)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/layers/recurrent.py:860 _process_inputs  *
        initial_state = self.get_initial_state(inputs)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/layers/recurrent.py:642 get_initial_state  *
        init_state = get_initial_state_fn(
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/layers/recurrent.py:2509 get_initial_state  *
        self, inputs, batch_size, dtype))
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/layers/recurrent.py:2990 _generate_zero_filled_state_for_cell  *
        return _generate_zero_filled_state(batch_size, cell.state_size, dtype)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/keras/layers/recurrent.py:3003 create_zeros  *
        return tf.zeros(init_state_size, dtype=dtype)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py:206 wrapper  **
        return target(*args, **kwargs)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py:2911 wrapped
        def wrapped(*args, **kwargs):
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py:2960 zeros
        # op to prevent serialized GraphDefs from becoming too large.
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py:2896 _constant_if_small
        try:
    <__array_function__ internals>:5 prod
        
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/numpy/core/fromnumeric.py:3051 prod
        return _wrapreduction(a, np.multiply, 'prod', axis, dtype, out,
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/numpy/core/fromnumeric.py:86 _wrapreduction
        return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
    /home/yl/miniconda3/envs/tf0/lib/python3.8/site-packages/tensorflow/python/framework/ops.py:867 __array__
        raise NotImplementedError(

    NotImplementedError: Cannot convert a symbolic Tensor (sequential_5/lstm_10/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

I use :

Tensorflow 2.5.0
numpy 1.19.5
python 3.8.12

@danielTobon43
Copy link

danielTobon43 commented Oct 22, 2021

@yangleir Update your numpy version to the last one.

@Kimxbzheng
Copy link

Kimxbzheng commented Dec 15, 2021

@glemarivero

Hi @aniketbote I posted this answer in Stack Overflow: https://stackoverflow.com/questions/66373169/tensorflow-2-object-detection-api-numpy-version-errors/66486051#66486051
I had this same issue:

NotImplementedError: Cannot convert a symbolic Tensor (cond_2/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

The problem was fixed by changing np.prod for reduce_prod in this function https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/array_ops.py

def _constant_if_small(value, shape, dtype, name):
  try:
    if np.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

Note that you need to import reduce_prod at the top of the file:

from tensorflow.math import reduce_prod

I was able to fix issue like you described but by importing reduc_prod as:

from tensorflow.python.ops.math_ops import reduce_prod
...

Seems like it is a bug in tensorflow

For cpu version, I found from tensorflow.math import reduce_prod works.
For gpu version, I found from tensorflow.python.ops.math_ops import reduce_prod works.

tallamjr added a commit to tallamjr/astronet that referenced this issue Dec 19, 2021
Jax reports errors, type mismatch

Numpy issue may be able to be resolve here: tensorflow/models#9706

	modified:   astronet/metrics.py
@MarcelRobitaille
Copy link

Is this change proposed by @athenasaurav expected to be released anytime soon? Modifying a file from the package after installing does not seem like a good solution to me. Neither does downgrading numpy, especially if the rest of my code uses features only available in numpy 1.20.

@john-maidbot
Copy link

john-maidbot commented Feb 16, 2022

Suddenly experiencing this problem in google colab with object detection API and TF1 with code that worked perfectly fine last week 🤔
I tried the suggested solution of downgrading to an older version of numpy, but it seems that something in the object detection api is built using numpy >= 1.20 because I get this error:
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

@mukammilbasha
Copy link

NotImplementedError: Cannot convert a symbolic Tensor (cond_2/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

from tensorflow.python.ops.math_ops import reduce_prod

the above import package working fine.

Locations : -\Lib\site-packages\tensorflow_core\python\ops\array_ops.py

image

@JafirDon
Copy link

[Solved]

I have the same error when training the data, even also try to downgrade the NumPy version, but it not be fixed.
Finally, I solved that issue. Try the below command:

!pip install numpy==1.17.4
!pip install pycocotools==2.0.0

@ahmedbr
Copy link

ahmedbr commented Mar 9, 2022

This is the results I get:
image

I have the same error as what you are getting. im using numpy 1.20.0 with Tensorflow 2.4.1
I'm convinced that numpy is the problem but im honestly too new at training models and using TF etc.
This is the tutorial ive been following https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html
Have you had any luck with solving this issue?

Try to downgrade numpy to numpy 1.19.5 pypi_0 pypi

pip install numpy==1.19.5

after that, check with conda list which numpy version you have installed

this worked for me too.

@mofagoulaopi
Copy link

I had the same problem when using colab, fixed it by reinstalling numpy==1.19.0
First I tried to switch to python3.6 as dademiller360 said, but somehow I failed cuz Idk how to change the python environment of tf.
Then I simply used the following order at colab:
!python -m pip install -U numpy==1.19.0
and it worked!

@firststepdev
Copy link

This worked for me:

OS: Windows 10
Python: 3.7.4
Virtualization: virtualenv

call python -m pip install tensorflow==2.4.1 --force-reinstall
call python -m pip install numpy==1.19.5 --force-reinstall
call python -m pip install h5py==2.10.0 --force-reinstall

@lghasemzadeh
Copy link

simply change the tensorflow or tensorflow-gpu to older versions:
$ pip install tensorflow-gpu==2.5.0

@mattyred
Copy link

mattyred commented Mar 15, 2023

This works fine for me:

OS: MacOS Monterey
Python: 3.8.16 (with Anaconda)

tensorflow: 2.11.0
numpy: 1.22.4

This was the the versions the packages on Google Colab where things are working
(In particular i found the bug when working with the GPFlow library)

@JayKumarr
Copy link

downgrade the numpy worked for me
pip install numpy==1.19.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests