Useful or not, from you.
tensorflow AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'

<em>Please make sure that this is a build/installation issue. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:build_template</em>

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 18.04
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:not applicable
  • TensorFlow installed from (source or binary):binary (pip3 install tensorflow)
  • TensorFlow version: 2.2.0-dev20200409
  • Python version: 3.6.9
  • Installed using virtualenv? pip? conda?: pip
  • Bazel version (if compiling from source): na
  • GCC/Compiler version (if compiling from source):7.5.0
  • CUDA/cuDNN version: Cuda10.2/cuDNN 7.6.5
  • GPU model and memory:GeForce GTX 1060/6GB

Describe the problem Below is the issue with tensorflow when a specific model is executed.

Using TensorFlow backend. 2020-04-16 10:54:20.595255: I tensorflow/stream_executor/platform/default/] Successfully opened dynamic library Patch extracted Traceback (most recent call last): File "", line 38, in <module> model = M.BCDU_net_D3(input_size = (64,64,1)) File "/home/sandbox/vissu/image_segmentation/BCDU-Net/Retina Blood Vessel Segmentation/", line 17, in BCDU_net_D3 conv1 = Conv2D(64, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(inputs) File "/usr/local/lib/python3.6/dist-packages/keras/backend/", line 76, in symbolic_fn_wrapper return func(*args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/keras/engine/", line 446, in call self.assert_input_compatibility(inputs) File "/usr/local/lib/python3.6/dist-packages/keras/engine/", line 310, in assert_input_compatibility K.is_keras_tensor(x) File "/usr/local/lib/python3.6/dist-packages/keras/backend/", line 696, in is_keras_tensor if not is_tensor(x): File "/usr/local/lib/python3.6/dist-packages/keras/backend/", line 704, in is_tensor return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x) AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'

Also referred other open issues, but there is no solution out there.

Provide the exact sequence of commands / steps that you executed before running into the problem when running an example of BCDU-Net model.

Any other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

That's a useful answer
Without any help

@lilly-chen I think you modified the wrong file. You should check in lib/python3.7/site-packages/tensorflow/python/framework/ which is the correct name of the variable. I assume it should be core_tf_types.Tensor, according to your comment.

Then, you should modify the function 'is_tensor' in file /anaconda3/lib/python3.7/site-packages/keras/backend/ in

def is_tensor(x):
     return isinstance(x, core_tf_types.Tensor) or tf_ops.is_dense_tensor_like(x)

Note, you should import core as well. So, at the top of you should add import core as core_tf_types

Seems like some TF versions have the attribute defined in, while others import it from core.

Hi, Thanks for the step by step!

here is the is_dense_tensor_like in my lib/python3.7/site-packages/tensorflow/python/framework/ (i reinstalled my keras in a new environment)

def is_dense_tensor_like(t):
  return isinstance(t, core_tf_types._TENSOR_LIKE_TYPES)

then i go to my /anaconda3/lib/python3.7/site-packages/keras/backend/ here is the original version

 def is_tensor(x):
     return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x)

i tried to change to

import core as core_tf_types
def is_tensor(x):
    return isinstance(x, core_tf_types._TENSOR_LIKE_TYPES) or tf_ops.is_dense_tensor_like(x)

but i am getting a new error when i try to import keras

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-e787bea10ca0> in <module>
----> 1 from keras.datasets import mnist
      2 import numpy as np
      3 np.random.seed(10)

~/anaconda3/lib/python3.7/site-packages/keras/ in <module>
      1 from __future__ import absolute_import
----> 3 from . import utils
      4 from . import activations
      5 from . import applications

~/anaconda3/lib/python3.7/site-packages/keras/utils/ in <module>
      4 from . import data_utils
      5 from . import io_utils
----> 6 from . import conv_utils
      7 from . import losses_utils
      8 from . import metrics_utils

~/anaconda3/lib/python3.7/site-packages/keras/utils/ in <module>
      7 from six.moves import range
      8 import numpy as np
----> 9 from .. import backend as K

~/anaconda3/lib/python3.7/site-packages/keras/backend/ in <module>
----> 1 from .load_backend import epsilon
      2 from .load_backend import set_epsilon
      3 from .load_backend import floatx
      4 from .load_backend import set_floatx
      5 from .load_backend import cast_to_floatx

~/anaconda3/lib/python3.7/site-packages/keras/backend/ in <module>
     88 elif _BACKEND == 'tensorflow':
     89     sys.stderr.write('Using TensorFlow backend.\n')
---> 90     from .tensorflow_backend import *
     91 else:
     92     # Try and load external backend.

~/anaconda3/lib/python3.7/site-packages/keras/backend/ in <module>
    705 #     return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x)
    706 # change by lilly
--> 707 import core as core_tf_types
    708 def is_tensor(x):
    709     return isinstance(x, core_tf_types._TENSOR_LIKE_TYPES) or tf_ops.is_dense_tensor_like(x)

ModuleNotFoundError: No module named 'core'