为了账号安全,请及时绑定邮箱和手机立即绑定

Tensorflow:不支持的操作数类型 -:'Sequential' 和 'Sequential'

Tensorflow:不支持的操作数类型 -:'Sequential' 和 'Sequential'

MMMHUHU 2023-06-20 10:25:34
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
]

它是一个函数,而不是一个数组。这是否解决了您的问题?


查看完整回答
反对 回复 2023-06-20
  • 1 回答
  • 0 关注
  • 92 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信