1

Encountering an error using the functional API of keras from within TensorFlow. The layers compile fine until I attempt to initiate the Model object (tf.keras.Model) at which point I receive the below error and traceback.

The last layer wrapper is below:

def dense(self,kwargs):
    print('simple old Dense layer')
    self.layer_outputs[kwargs['LayerID']] = tf.keras.layers.Lambda(tf.layers.Dense(name=self._namer(kwargs['LayerID']), **kwargs['LayerKwargs']))(self.layer_outputs[kwargs['LayerInput']])
    if kwargs['args'].setdefault('norm',True):
        self.layer_outputs[kwargs['LayerID']] = self.batchnorm_relu(self.layer_outputs[kwargs['LayerID']],kwargs['LayerID'])
    return self.layer_outputs[kwargs['LayerID']]

I've reviewed other questions regarding similar errors, here, here and here. All of these issues were resolved either by correcting the input or wrapping the output in a keras.Lambda layer wrapper, neither of which seem to be working for me.

My input is below:

self.input_proxy = tf.keras.layers.Input(shape=self.batch_input_shape[1:],dtype=tf.float32)

One answer which I haven't yet tried is here, wherein I would assign the missing requisite meta_data manually. This may work, but seems awfully hacky and I'd like a more straightforward solution that works with the API if possible.

Why is this happening and how can I resolve it?

   C:\Users\asus\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\training.py in __init__(self, *args, **kwargs)
        115
        116   def __init__(self, *args, **kwargs):
    --> 117     super(Model, self).__init__(*args, **kwargs)
        118     # Create a cache for iterator get_next op.
        119     self._iterator_get_next = weakref.WeakKeyDictionary()

    C:\Users\asus\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\network.py in __init__(self, *args, **kwargs)
         78         'inputs' in kwargs and 'outputs' in kwargs):
         79       # Graph network
    ---> 80       self._init_graph_network(*args, **kwargs)
         81     else:
         82       # Subclassed network

    C:\Users\asus\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\training\checkpointable\base.py in _method_wrapper(self, *args, **kwargs)
        424     self._setattr_tracking = False  # pylint: disable=protected-access
        425     try:
    --> 426       method(self, *args, **kwargs)
        427     finally:
        428       self._setattr_tracking = previous_value  # pylint: disable=protected-access

    C:\Users\asus\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\network.py in _init_graph_network(self, inputs, outputs, name)
        222         raise ValueError('Output tensors to a ' + cls_name + ' must be '
        223                          'the output of a TensorFlow `Layer` '
    --> 224                          '(thus holding past layer metadata). Found: ' + str(x))
        225
        226     self._base_init(name=name)

    ValueError: Output tensors to a Model must be the output of a TensorFlow `Layer` (thus holding past layer metadata). Found: Tensor("lambda/Last__0/BiasAdd:0",

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.