让我解释一下我的问题:
我假设有一些(不止一个)张量流层,如下所示:
import tensorflow as tf
x = tf.placeholder(tf.float32,[1,64,64,3])
conv_layer_1 = tf.layers.Conv2D(16,[3,3])
conv_layer_2 = tf.layers.Conv2D(16,[3,3])
是否有任何方法可以将这些图层组合到一个tf.Layer对象中?
# conv_layer is the combined result
# conv_layer(x) is equal to conv_layer2(conv_layer1(x))
conv_layer = some_function([conv_layer1,conv_layer2])
目前我使用的是丑陋的方法:
class MyLayer(tf.Layer)
......
def combine(layers_list):
self.layers_list += layers_list
def __call__(x):
for layer in self.layers:
y = layer(y)
return y
答案 0 :(得分:1)
在这种情况下,您可以使用tf.layers.concatenate 有关更多详细信息,请访问tensorflow网站https://www.tensorflow.org/api_docs/python/tf/keras/layers/concatenate