在TensorFlow中使用keras的功能API遇到错误。在我尝试启动Model对象(tf.keras.Model)之前,这些层可以很好地编译,此时我将收到以下错误和回溯。
最后一个包装器在下面:
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']]
我已经审查了其他有关类似错误的问题,here,here和here。所有这些问题都可以通过更正输入或将输出包装在keras.Lambda层包装程序中来解决,这两种方法似乎都不适合我。
我的输入如下:
self.input_proxy = tf.keras.layers.Input(shape=self.batch_input_shape[1:],dtype=tf.float32)
我还没有尝试过的答案是here,其中我将手动分配缺少的必需meta_data。这可能有效,但是似乎很hacky,我希望有一个更直接的解决方案,如果可能的话,可以与API一起使用。
为什么会这样,我该如何解决?
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",