Categories
Misc

Error when returning tf.keras.Model

I want to create a python program for neural style transfer based on this tutorial: https://medium.com/tensorflow/neural-style-transfer-creating-art-with-deep-learning-using-tf-keras-and-eager-execution-7d541ac31398. They used tensorflow 1.* for this but I use tensorflow 2.* (gpu), so I had to change a few things. Both my version and the original version of the program raised a ValueError when I tried to return a vgg19 model. Can someone explain this error or tell me how to fix it?

“`def get_model(): vgg = tf.keras.applications.vgg19.VGG19(include_top = False, weights = ‘imagenet’) vgg.trainable = False style_outputs = [vgg.get_layer(name) for name in style_layers] content_outputs = [vgg.get_layer(name) for name in content_layers] model_outputs = style_outputs + content_outputs return tf.keras.Model(vgg.input, model_outputs)

Traceback (most recent call last): File “NSTV2.py”, line 155, in <module> main() File “NST_V2.py”, line 152, in main best, best_loss = run_style_transfer(args[‘content’], args[‘style’]) File “NST_V2.py”, line 101, in run_style_transfer model = get_model() File “NST_V2.py”, line 48, in get_model return tf.keras.Model(vgg.input, model_outputs) File “C:UsersfreddAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythontrainingtrackingbase.py”, line 517, in _method_wrapper result = method(self, args, *kwargs) File “C:UsersfreddAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythonkerasenginefunctional.py”, line 120, in __init_ self._init_graph_network(inputs, outputs) File “C:UsersfreddAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythontrainingtrackingbase.py”, line 517, in _method_wrapper result = method(self, args, *kwargs) File “C:UsersfreddAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythonkerasenginefunctional.py”, line 157, in _init_graph_network self._validate_graph_inputs_and_outputs() File “C:UsersfreddAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythonkerasenginefunctional.py”, line 727, in _validate_graph_inputs_and_outputs raise ValueError(‘Output tensors of a ‘ + cls_name + ‘ model must be ‘ ValueError: Output tensors of a Functional model must be the output of a TensorFlow Layer (thus holding past layer metadata). Found: <tensorflow.python.keras.layers.convolutional.Conv2D object at 0x000002A05C2F9D60>“`

submitted by /u/Jirne_VR
[visit reddit] [comments]

Leave a Reply

Your email address will not be published.