首页 > 解决方案 > 需要帮助解决问题 ''AttributeError: 'function' object has no attribute 'summary'''

问题描述

需要帮助解决问题'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()

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

标签: pythontensorflowkeras

解决方案


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

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

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

def model(model_obj, inputs):

    ...
    model_obj.summary()

推荐阅读