我在tf_1.2中运行以下代码:
inp = tf.contrib.keras.layers.Input(shape=(height, width, depth))
conv_1 = tf.contrib.keras.layers.Convolution2D(conv_depth,(kernel_size, kernel_size),
padding='same',
kernel_initializer='he_uniform',
kernel_regularizer=tf.contrib.keras.regularizers.l2(0.001),
activation='relu')(inp)
model = tf.contrib.keras.models.Model(inputs=inp, outputs=conv_1)
a = tf.contrib.keras.layers.Input(shape=(height, width, depth))
enc_a = model(a)
收到以下错误
tensorflow/contrib/keras/python/keras/engine/topology.pyc in run_internal_graph(self, inputs, masks)
1955 # Keep track of unconditional losses
1956 # (e.g. weight regularizers).
-> 1957 self.add_loss(layer.get_losses_for(None), None)
tensorflow/python/layers/base.pyc in add_loss(self, losses, inputs)
254 if not losses:
255 return
--> 256 self._losses += losses
AttributeError: 'Model' object has no attribute '_losses'
如果删除kernel_regularizer,相同的代码也可以工作,如果我导入的是keras而不是tf.contrib.keras