Why can't I build a VGG19 model in keras?

I have no idea how to fix it. Here is my code and error:
from keras import backend as K

    target_image = K.constant(preprocess_image(target_image_path))
    style_reference_image = K.constant(preprocess_image(style_reference_image_path))

    combination_image = K.placeholder((1, img_height, img_width, 3))
    input_tensor = K.concatenate([target_image, style_reference_image, combination_image], axis=0)
    model = vgg19.VGG19(input_tensor=input_tensor, weights='imagenet', include_top=False)
    print('model loaded')


AttributeError Traceback (most recent call last)
<ipython-input-17-709cfab4486a> in <module>
      6 combination_image = K.placeholder((1, img_height, img_width, 3))
      7 input_tensor = K.concatenate([target_image, style_reference_image, combination_image], axis=0)
----> 8 model = vgg19.VGG19(input_tensor=input_tensor, weights='imagenet', include_top=False)
      9 print('model loaded')

~/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/keras/applications/__init__.py in wrapper(*args, **kwargs)
     18         kwargs['models'] = models
 19         kwargs['utils'] = utils
---> 20         return base_fun(*args, **kwargs)
 21 
 22     return wrapper

~/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/keras/applications/vgg19.py in VGG19(*args, **kwargs)
  9 @keras_modules_injection
 10 def VGG19(*args, **kwargs):
---> 11     return vgg19.VGG19(*args, **kwargs)
 12 
 13 

~/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/keras_applications/vgg19.py in VGG19(include_top, weights, input_tensor, input_shape, pooling, classes, **kwargs)
102         img_input = layers.Input(shape=input_shape)
103     else:
--> 104         if not backend.is_keras_tensor(input_tensor):
105             img_input = layers.Input(tensor=input_tensor, shape=input_shape)
106         else:

~/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py in is_keras_tensor(x)
693     ```
694     """
--> 695     if not is_tensor(x):
696         raise ValueError('Unexpectedly found an instance of type `' +
697                          str(type(x)) + '`. '

~/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py in is_tensor(x)
701 
702 def is_tensor(x):
--> 703     return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x)
704 
705 

AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'
1 Like

Are you using Keras or tf.keras?

What Is your TersorFlow version?

2 Likes

Can you share more of your code and the TensorFlow version/environment you’re using?

Also, try using the latest TensorFlow version (e.g. with PiPI or conda) and then call/use tf.keras.applications.vgg19().

Example/walkthrough with VGG19:

API docs:

https://www.tensorflow.org/api_docs/python/tf/keras/applications/VGG19

More examples with VGG19:

This may also help - implementations of VGG-11/13/19 with TF 2.0 (last updated June 2020, not tested):

3 Likes

Thanks, it is because of version in tensorflow that when I change from 2.0 to 1.11 it works for me.

2 Likes

TF 1.x is end of life.
Please use tf.keras with modern TF 2.x versions.

1 Like