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}
## data image, ih, iw, gt_boxes, gt_masks, num_instances, img_id = \ coco.read('./data/coco/records/coco_train2014_00000-of-00040.tfrecord') with tf.control_dependencies([image, gt_boxes, gt_masks]): image, gt_boxes, gt_masks = coco_preprocess.preprocess_image( image, gt_boxes, gt_masks, is_training=True) ## network with slim.arg_scope(resnet_v1.resnet_arg_scope(weight_decay=0.0001)): logits, end_points = resnet50(image, 1000, is_training=False) end_points['inputs'] = image for x in sorted(end_points.keys()): print(x, end_points[x].name, end_points[x].shape) 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,