def pack_model(inputs, train = True, back_network = 'resnet50', #num_classes=81, num_classes=91, base_anchors=9, weight_decay=0.00005, **kwargs ): # Reshape the input image, batch size 1 supported image = inputs['images'] ih = inputs['height'] iw = inputs['width'] im_shape = tf.shape(image) #image = tf.Print(image, [im_shape], message = 'shape', summarize = 4) image = tf.reshape(image, (im_shape[0], im_shape[1], im_shape[2], 3)) image = tf.cast(image, tf.float32) image_height = ih image_width = iw num_instances = inputs['num_objects'] gt_boxes = inputs['bboxes'] #gt_boxes = tf.reshape(gt_boxes, [num_instances, 4]) #labels = inputs['labels'] #labels = tf.reshape(labels, [num_instances, 1]) #gt_boxes = tf.concat([gt_boxes, tf.cast(labels, tf.float64)], 1) #gt_boxes = tf.Print(gt_boxes, [tf.shape(gt_boxes)], message = 'Box shape', summarize = 4) # Build the basic network logits, end_points, pyramid_map = network.get_network(back_network, image, weight_decay=weight_decay) # Build the pyramid pyramid = pyramid_network.build_pyramid(pyramid_map, end_points) # Build the heads outputs = \ pyramid_network.build_heads(pyramid, image_height, image_width, num_classes, base_anchors, is_training=train, gt_boxes=gt_boxes) return {'outputs': outputs, 'pyramid': pyramid}, {'network': back_network}
pyramid = pyramid_network.build_pyramid('resnet50', end_points) # for p in pyramid: # print (p, pyramid[p]) summaries = set(tf.get_collection(tf.GraphKeys.SUMMARIES)) for p in pyramid: summaries.add(tf.summary.histogram('pyramid/hist/' + p, pyramid[p])) summaries.add( tf.summary.scalar('pyramid/means/' + p, tf.reduce_mean(tf.abs(pyramid[p])))) outputs = pyramid_network.build_heads(pyramid, ih, iw, num_classes=81, base_anchors=9, is_training=True, gt_boxes=gt_boxes) ## losses loss, losses, batch_info = pyramid_network.build_losses( pyramid, outputs, gt_boxes, gt_masks, num_classes=81, base_anchors=9, rpn_box_lw=0.1, rpn_cls_lw=0.2, refined_box_lw=2.0,
#!/usr/bin/env python from __future__ import absolute_import from __future__ import division from __future__ import print_function import functools import tensorflow as tf import tensorflow.contrib.slim as slim from libs.logs.log import LOG import libs.nets.resnet_v1 as resnet_v1 resnet50 = resnet_v1.resnet_v1_50 images = tf.placeholder(tf.float32, [16, 224, 224, 3], name='image') logits, end_points = resnet50(images, 1000, is_training=False) end_points['inputs'] = images for x in sorted(end_points.keys()): print (x, end_points[x].name, end_points[x].shape) import libs.nets.pyramid_network as pyramid_network pyramid = pyramid_network.build_pyramid('resnet50', end_points) for p in pyramid: print (p, pyramid[p]) outputs = pyramid_network.build_heads(pyramid, num_classes=81, base_anchors=15, is_training=True) outputs = pyramid_network.build_losses(pyramid, outputs)