【问题标题】:Need help resolving the issue ''AttributeError: 'function' object has no attribute 'summary' ''需要帮助解决问题 ''AttributeError: 'function' object has no attribute 'summary'''
【发布时间】:2021-10-05 05:19:56
【问题描述】:

需要帮助解决问题'AttributeError: 'function' object has no attribute 'summary'

def model(inputs):

    batch_size,height,width=config.BATCH_SIZE,config.IMAGE_SHAPE[0],config.IMAGE_SHAPE[1]
    
    with slim.arg_scope(resnet_v2.resnet_arg_scope()):
          #net, end_points = resnet_v2.resnet_v2_101(inputs, 1001, is_training=False)
          net, end_points = resnet_v2.resnet_v2_152(inputs,
                                                    2048,
                                                    is_training=True,
                                                    global_pool=False,
                                                    reuse=tf.AUTO_REUSE,
                                                    output_stride=config.OUTPUT_STRIDE)
    #print(net)
    kp_maps = tf.contrib.layers.conv2d(net,num_outputs = config.NUM_KP,
                                             kernel_size=(1,1),activation_fn=tf.nn.sigmoid,stride=1,scope='kp_maps',reuse=tf.AUTO_REUSE)

    short_offsets = tf.contrib.layers.conv2d(net,num_outputs = 2*config.NUM_KP,
                                             kernel_size=(1,1),activation_fn=None,stride=1,scope='short_offsets',reuse=tf.AUTO_REUSE)
                          
    mid_offsets = tf.contrib.layers.conv2d(net,num_outputs = 4*config.NUM_EDGES,
                                             kernel_size=(1,1),activation_fn=None,stride=1,scope='mid_offsets',reuse=tf.AUTO_REUSE)
    
    long_offsets = tf.contrib.layers.conv2d(net,num_outputs = 2*config.NUM_KP,
                                             kernel_size=(1,1),activation_fn=None,stride=1,scope='long_offsets',reuse=tf.AUTO_REUSE)
    
    seg_mask = tf.contrib.layers.conv2d(net,num_outputs = 1,
                                             kernel_size=(1,1),activation_fn=tf.nn.sigmoid,stride=1,scope='seg_mask',reuse=tf.AUTO_REUSE)


    model.summary()

我正在尝试打印模型的摘要

【问题讨论】:

  • 你能告诉我们错误吗?
  • model 既是函数名又是变量名?你有model.summary,但我不知道model 是在哪里定义的。
  • 您似乎没有使用 Keras,您无法真正使用 model.summary(),因为您没有在此代码中构建 Keras 模型。

标签: python tensorflow keras


【解决方案1】:

model.summary() 模型中似乎是对当前函数的引用。

您正在尝试使用递归函数引用。

尝试将模型引用与输入一起传递给此函数并使用它来获取摘要。

def model(model_obj, inputs):

    ...
    model_obj.summary()

【讨论】:

    猜你喜欢
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-06
    • 2022-12-04
    • 2022-11-11
    • 2022-12-01
    • 1970-01-01
    相关资源
    最近更新 更多