TensorFlow Errors - image_processing.py

EDIT: Nevermind I think I found something related… Missing tensorflow wheel for Alpine 3.13 · Issue #48569 · home-assistant/core · GitHub
EDIT AGAIN: Actually I have no idea… maybe it’s not related…

Since upgrading to 2021.4.1 (I believe that’s when it started). I am getting this error and my Tensorflow image processing doesn’t work.
I’m running 2021.4.5 on Debian 10 Supervised.
I coming from a longtime VENV install so I haven’t had to do much troubleshooting in a supervised environment, so I’m not really sure the best way to troubleshoot/reinstall packages in supervised… anyone have any suggestions?


2021-04-18 12:44:09 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/tensorflow/image_processing.py", line 176, in tensorflow_hass_start
    model(input_tensor)
  File "/usr/local/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 780, in __call__
    result = self._call(*args, **kwds)
  File "/usr/local/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 823, in _call
    self._initialize(args, kwds, add_initializers_to=initializers)
  File "/usr/local/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 696, in _initialize
    self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
  File "/usr/local/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 2855, in _get_concrete_function_internal_garbage_collected
    graph_function, _, _ = self._maybe_define_function(args, kwargs)
  File "/usr/local/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 3213, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "/usr/local/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 3065, in _create_graph_function
    func_graph_module.func_graph_from_py_func(
  File "/usr/local/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py", line 986, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/usr/local/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 600, in wrapped_fn
    return weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "/usr/local/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py", line 973, in wrapper
    raise e.ag_error_metadata.to_exception(e)
NotImplementedError: in user code:

    /usr/src/homeassistant/homeassistant/components/tensorflow/image_processing.py:91 detect_fn  *
        prediction_dict = model.predict(image, shapes)
    /config/tensorflow/object_detection/meta_architectures/faster_rcnn_meta_arch.py:827 predict  *
        prediction_dict.update(
    /config/tensorflow/object_detection/meta_architectures/faster_rcnn_meta_arch.py:1003 _predict_second_stage  *
        prediction_dict = self._box_prediction(rpn_features_to_crop,
    /config/tensorflow/object_detection/meta_architectures/faster_rcnn_meta_arch.py:1065 _box_prediction  *
        flattened_proposal_feature_maps = (
    /config/tensorflow/object_detection/meta_architectures/faster_rcnn_meta_arch.py:1958 _compute_second_stage_input_feature_maps  *
        cropped_regions = self._flatten_first_two_dimensions(
    /config/tensorflow/object_detection/utils/spatial_transform_ops.py:520 multilevel_matmul_crop_and_resize  *
        return multilevel_roi_align(images,
    /config/tensorflow/object_detection/utils/spatial_transform_ops.py:349 multilevel_roi_align  *
        feature_coordinates = ravel_indices(feature_grid_y, feature_grid_x,
    /config/tensorflow/object_detection/utils/spatial_transform_ops.py:187 ravel_indices  *
        batch_dim_indices = (
    /usr/local/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py:201 wrapper  **
        return target(*args, **kwargs)
    /usr/local/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py:3041 ones
        output = _constant_if_small(one, shape, dtype, name)
    /usr/local/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py:2732 _constant_if_small
        if np.prod(shape) < 1000:
    <__array_function__ internals>:5 prod
        
    /usr/local/lib/python3.8/site-packages/numpy/core/fromnumeric.py:3030 prod
        return _wrapreduction(a, np.multiply, 'prod', axis, dtype, out,
    /usr/local/lib/python3.8/site-packages/numpy/core/fromnumeric.py:87 _wrapreduction
        return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
    /usr/local/lib/python3.8/site-packages/tensorflow/python/framework/ops.py:845 __array__
        raise NotImplementedError(

    NotImplementedError: Cannot convert a symbolic Tensor (MultiLevelMatMulCropAndResize/MultiLevelRoIAlign/strided_slice_5: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 tried uninstalling and reinstalling numpy but I get this on reinstall:


  Downloading numpy-1.20.2.zip (7.8 MB)
     |████████████████████████████████| 7.8 MB 2.2 MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmp3xrt62cm
         cwd: /tmp/pip-install-pgas2zyk/numpy
    Complete output (226 lines):
    Processing numpy/random/_bounded_integers.pxd.in
    Processing numpy/random/mtrand.pyx
    Processing numpy/random/_pcg64.pyx
    Processing numpy/random/bit_generator.pyx
    Processing numpy/random/_sfc64.pyx
    Processing numpy/random/_common.pyx
    Processing numpy/random/_bounded_integers.pyx.in
    Processing numpy/random/_philox.pyx
    Processing numpy/random/_generator.pyx
    Processing numpy/random/_mt19937.pyx
    Cythonizing sources
    blas_opt_info:
    blas_mkl_info:
    customize UnixCCompiler
      libraries mkl_rt not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    blis_info:
      libraries blis not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    openblas_info:
      libraries openblas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    atlas_3_10_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries tatlas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    atlas_3_10_blas_info:
      libraries satlas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    atlas_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries ptf77blas,ptcblas,atlas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    atlas_blas_info:
      libraries f77blas,cblas,atlas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    blas_info:
      libraries blas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    blas_src_info:
      NOT AVAILABLE
    
      NOT AVAILABLE
    
    non-existing path in 'numpy/distutils': 'site.cfg'
    lapack_opt_info:
    lapack_mkl_info:
      libraries mkl_rt not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    openblas_lapack_info:
      libraries openblas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    openblas_clapack_info:
      libraries openblas,lapack not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    flame_info:
      libraries flame not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    atlas_3_10_threads_info:
    Setting PTATLAS=ATLAS
      libraries lapack_atlas not found in /usr/local/lib
      libraries tatlas,tatlas not found in /usr/local/lib
      libraries lapack_atlas not found in /usr/lib
      libraries tatlas,tatlas not found in /usr/lib
    <class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
      NOT AVAILABLE
    
    atlas_3_10_info:
      libraries lapack_atlas not found in /usr/local/lib
      libraries satlas,satlas not found in /usr/local/lib
      libraries lapack_atlas not found in /usr/lib
      libraries satlas,satlas not found in /usr/lib
    <class 'numpy.distutils.system_info.atlas_3_10_info'>
      NOT AVAILABLE
    
    atlas_threads_info:
    Setting PTATLAS=ATLAS
      libraries lapack_atlas not found in /usr/local/lib
      libraries ptf77blas,ptcblas,atlas not found in /usr/local/lib
      libraries lapack_atlas not found in /usr/lib
      libraries ptf77blas,ptcblas,atlas not found in /usr/lib
    <class 'numpy.distutils.system_info.atlas_threads_info'>
      NOT AVAILABLE
    
    atlas_info:
      libraries lapack_atlas not found in /usr/local/lib
      libraries f77blas,cblas,atlas not found in /usr/local/lib
      libraries lapack_atlas not found in /usr/lib
      libraries f77blas,cblas,atlas not found in /usr/lib
    <class 'numpy.distutils.system_info.atlas_info'>
      NOT AVAILABLE
    
    lapack_info:
      libraries lapack not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    lapack_src_info:
      NOT AVAILABLE
    
      NOT AVAILABLE
    
    numpy_linalg_lapack_lite:
      FOUND:
        language = c
        define_macros = [('HAVE_BLAS_ILP64', None), ('BLAS_SYMBOL_SUFFIX', '64_')]
    
    running dist_info
    running build_src
    build_src
    building py_modules sources
    creating build
    creating build/src.linux-x86_64-3.8
    creating build/src.linux-x86_64-3.8/numpy
    creating build/src.linux-x86_64-3.8/numpy/distutils
    building library "npymath" sources
    Could not locate executable gfortran
    Could not locate executable f95
    Could not locate executable ifort
    Could not locate executable ifc
    Could not locate executable lf95
    Could not locate executable pgfortran
    Could not locate executable nvfortran
    Could not locate executable f90
    Could not locate executable f77
    Could not locate executable fort
    Could not locate executable efort
    Could not locate executable efc
    Could not locate executable g77
    Could not locate executable g95
    Could not locate executable pathf95
    Could not locate executable nagfor
    Could not locate executable frt
    don't know how to compile Fortran code on platform 'posix'
    Running from numpy source directory.
    setup.py:485: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
      run_build = parse_setuppy_commands()
    /tmp/pip-install-pgas2zyk/numpy/numpy/distutils/system_info.py:1989: UserWarning:
        Optimized (vendor) Blas libraries are not found.
        Falls back to netlib Blas library which has worse performance.
        A better performance should be easily gained by switching
        Blas library.
      if self._calc_info(blas):
    /tmp/pip-install-pgas2zyk/numpy/numpy/distutils/system_info.py:1989: UserWarning:
        Blas (http://www.netlib.org/blas/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [blas]) or by setting
        the BLAS environment variable.
      if self._calc_info(blas):
    /tmp/pip-install-pgas2zyk/numpy/numpy/distutils/system_info.py:1989: UserWarning:
        Blas (http://www.netlib.org/blas/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [blas_src]) or by setting
        the BLAS_SRC environment variable.
      if self._calc_info(blas):
    /tmp/pip-install-pgas2zyk/numpy/numpy/distutils/system_info.py:1849: UserWarning:
        Lapack (http://www.netlib.org/lapack/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [lapack]) or by setting
        the LAPACK environment variable.
      return getattr(self, '_calc_info_{}'.format(name))()
    /tmp/pip-install-pgas2zyk/numpy/numpy/distutils/system_info.py:1849: UserWarning:
        Lapack (http://www.netlib.org/lapack/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [lapack_src]) or by setting
        the LAPACK_SRC environment variable.
      return getattr(self, '_calc_info_{}'.format(name))()
    /usr/local/lib/python3.8/distutils/dist.py:274: UserWarning: Unknown distribution option: 'define_macros'
      warnings.warn(msg)
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
        main()
      File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "/usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 133, in prepare_metadata_for_build_wheel
        return hook(metadata_directory, config_settings)
      File "/tmp/pip-build-env-us8uxf2i/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 157, in prepare_metadata_for_build_wheel
        self.run_setup()
      File "/tmp/pip-build-env-us8uxf2i/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 248, in run_setup
        super(_BuildMetaLegacyBackend,
      File "/tmp/pip-build-env-us8uxf2i/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 142, in run_setup
        exec(compile(code, __file__, 'exec'), locals())
      File "setup.py", line 513, in <module>
        setup_package()
      File "setup.py", line 505, in setup_package
        setup(**metadata)
      File "/tmp/pip-install-pgas2zyk/numpy/numpy/distutils/core.py", line 169, in setup
        return old_setup(**new_attr)
      File "/tmp/pip-build-env-us8uxf2i/overlay/lib/python3.8/site-packages/setuptools/__init__.py", line 165, in setup
        return distutils.core.setup(**attrs)
      File "/usr/local/lib/python3.8/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/local/lib/python3.8/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/pip-build-env-us8uxf2i/overlay/lib/python3.8/site-packages/setuptools/command/dist_info.py", line 31, in run
        egg_info.run()
      File "/tmp/pip-install-pgas2zyk/numpy/numpy/distutils/command/egg_info.py", line 24, in run
        self.run_command("build_src")
      File "/usr/local/lib/python3.8/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/local/lib/python3.8/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/pip-install-pgas2zyk/numpy/numpy/distutils/command/build_src.py", line 144, in run
        self.build_sources()
      File "/tmp/pip-install-pgas2zyk/numpy/numpy/distutils/command/build_src.py", line 155, in build_sources
        self.build_library_sources(*libname_info)
      File "/tmp/pip-install-pgas2zyk/numpy/numpy/distutils/command/build_src.py", line 288, in build_library_sources
        sources = self.generate_sources(sources, (lib_name, build_info))
      File "/tmp/pip-install-pgas2zyk/numpy/numpy/distutils/command/build_src.py", line 378, in generate_sources
        source = func(extension, build_dir)
      File "numpy/core/setup.py", line 676, in get_mathlib_info
        raise RuntimeError("Broken toolchain: cannot link a simple C program")
    RuntimeError: Broken toolchain: cannot link a simple C program
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmp3xrt62cm Check the logs for full command output.

I’ll jump onboard with this one as well. I am, however, running in a venv and have been seeing these errors for quite a long time (months if not years).

I use Tensorflow very heavily (dozens of times a minute) with a GPU on the backend (GTX 1080) and see these stream pretty frequently.

2021-04-19 09:47:49 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/venv/lib/python3.8/site-packages/homeassistant/components/tensorflow/image_processing.py", line 176, in tensorflow_hass_start
    model(input_tensor)
  File "/srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 780, in __call__
    result = self._call(*args, **kwds)
  File "/srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 823, in _call
    self._initialize(args, kwds, add_initializers_to=initializers)
  File "/srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 696, in _initialize
    self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
  File "/srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 2855, in _get_concrete_function_internal_garbage_collected
    graph_function, _, _ = self._maybe_define_function(args, kwargs)
  File "/srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 3213, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "/srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 3065, in _create_graph_function
    func_graph_module.func_graph_from_py_func(
  File "/srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py", line 986, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 600, in wrapped_fn
    return weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "/srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py", line 973, in wrapper
    raise e.ag_error_metadata.to_exception(e)
NotImplementedError: in user code:

    /srv/homeassistant/venv/lib/python3.8/site-packages/homeassistant/components/tensorflow/image_processing.py:91 detect_fn  *
        prediction_dict = model.predict(image, shapes)
    /srv/homeassistant/.homeassistant/tensorflow/object_detection/meta_architectures/faster_rcnn_meta_arch.py:818 predict  *
        prediction_dict.update(
    /srv/homeassistant/.homeassistant/tensorflow/object_detection/meta_architectures/faster_rcnn_meta_arch.py:994 _predict_second_stage  *
        prediction_dict = self._box_prediction(rpn_features_to_crop,
    /srv/homeassistant/.homeassistant/tensorflow/object_detection/meta_architectures/faster_rcnn_meta_arch.py:1056 _box_prediction  *
        flattened_proposal_feature_maps = (
    /srv/homeassistant/.homeassistant/tensorflow/object_detection/meta_architectures/faster_rcnn_meta_arch.py:1969 _compute_second_stage_input_feature_maps  *
        cropped_regions = self._flatten_first_two_dimensions(
    /srv/homeassistant/.homeassistant/tensorflow/object_detection/utils/spatial_transform_ops.py:520 multilevel_matmul_crop_and_resize  *
        return multilevel_roi_align(images,
    /srv/homeassistant/.homeassistant/tensorflow/object_detection/utils/spatial_transform_ops.py:349 multilevel_roi_align  *
        feature_coordinates = ravel_indices(feature_grid_y, feature_grid_x,
    /srv/homeassistant/.homeassistant/tensorflow/object_detection/utils/spatial_transform_ops.py:187 ravel_indices  *
        batch_dim_indices = (
    /srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py:201 wrapper  **
        return target(*args, **kwargs)
    /srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py:3041 ones
        output = _constant_if_small(one, shape, dtype, name)
    /srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py:2732 _constant_if_small
        if np.prod(shape) < 1000:
    <__array_function__ internals>:5 prod

    /srv/homeassistant/venv/lib/python3.8/site-packages/numpy/core/fromnumeric.py:3030 prod
        return _wrapreduction(a, np.multiply, 'prod', axis, dtype, out,
    /srv/homeassistant/venv/lib/python3.8/site-packages/numpy/core/fromnumeric.py:87 _wrapreduction
        return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
    /srv/homeassistant/venv/lib/python3.8/site-packages/tensorflow/python/framework/ops.py:845 __array__
        raise NotImplementedError(

    NotImplementedError: Cannot convert a symbolic Tensor (MultiLevelMatMulCropAndResize/MultiLevelRoIAlign/strided_slice_5: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 believe this is the same issue as reported on the github page.