def build_net(img_shape): """ :type img_shape: tuple. Shape of input image. Here is(1,height, width). 1 because pgm file only has one channel. :rtype:tensorflow Sequential """ model = tf.keras.Sequential() # convolution layer 1 model.add(tf.keras.layers.Conv2D(filters = 16, kernel_size = 3, strides = 1, activation = "relu", input_shape = img_shape, data_format = "channels_first")) model.add(tf.keras.layers.MaxPool2D(pool_size = 2)) model.add(tf.keras.layers.Dropout(0.1)) # convolution layer 2 model.add(tf.keras.layers.Conv2D(filters = 32, kernel_size = 3, strides = 1)) model.add(tf.keras.layers.MaxPool2D(pool_size = 2)) model.add(tf.keras.layers.Dropout(0.1)) model.add(tf.keras.layers.Flatten()) model.add(tf.keras.layers.Dense(1024)) model.add(tf.keras.layers.Dropout(0.25)) model.add(tf.keras.layers.Dense(512, activation='relu')) # deep face mentioned that there are 67 points to detect on a human face, so use 70 features. model.add(tf.keras.layers.Dense(70, activation='relu')) print(model.summary()) return model并定义 adist来计算两个输出向量之间的距离。im1_features = build_net(input_dim)im2_features = build_net(input_dim)dist = tf.keras.layers.Lambda(lambda tensors: tf.keras.backend.abs[tensors[0] - tensors[1]])([im1_features, im2_features])错误发生在dist File "e:\School\AIAS\proj\build_model.py", line 102, in <lambda> dist = tf.keras.layers.Lambda(lambda tensors: tf.keras.backend.abs[tensors[0] - tensors[1]])([im1_features, im2_features])TypeError: unsupported operand type(s) for -: 'Sequential' and 'Sequential'如何使函数build_net返回向量而不是 Sequential 对象?
1 回答
交互式爱情
TA贡献1712条经验 获得超3个赞
尝试tf.keras.abs
这样调用:
tf.keras.backend.abs( x )
不是
tf.keras.backend.abs[ x ]
它是一个函数,而不是一个数组。这是否解决了您的问题?
添加回答
举报
0/150
提交
取消