Esempio n. 1
0
def pack_loss(labels, logits, 
            #num_classes=81,
            num_classes=91,
            base_anchors=9,
            loss_weights=[0.2, 0.2, 1.0, 0.2, 1.0],
            **kwargs
        ):
    #'targets': ['height', 'width', 'num_objects', 'labels', 'segmentation_masks', 'bboxes'],
    #print(labels)
    ih = labels[0]
    iw = labels[1]
    num_instances = labels[2]
    gt_boxes = labels[5]
    #labels_s = labels[3]
    #gt_boxes = tf.concat([gt_boxes, tf.cast(labels_s, tf.float64)], 1)
    #gt_boxes = tf.Print(gt_boxes, [tf.shape(gt_boxes)], message = 'Box shape loss', summarize = 4)
    gt_masks = labels[4]
    #gt_masks = tf.Print(gt_masks, [tf.shape(gt_masks)], message = 'Mask shape loss', summarize = 4)

    loss, losses, batch_info = pyramid_network.build_losses(logits['pyramid'], logits['outputs'], 
                    gt_boxes, gt_masks,
                    num_classes=num_classes, base_anchors=base_anchors,
                    rpn_box_lw=loss_weights[0], rpn_cls_lw=loss_weights[1],
                    refined_box_lw=loss_weights[2], refined_cls_lw=loss_weights[3],
                    mask_lw=loss_weights[4])

    #outputs['losses'] = losses
    #outputs['total_loss'] = loss
    #outputs['batch_info'] = batch_info
    losses = tf.get_collection(tf.GraphKeys.LOSSES)
    regular_losses = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
    regular_loss = tf.add_n(regular_losses)
    out_loss = tf.add_n(losses)
    total_loss = tf.add_n(losses + regular_losses)

    return total_loss
Esempio n. 2
0
        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,
            refined_cls_lw=0.1,
            mask_lw=0.2)

        ## optimization
        learning_rate = _configure_learning_rate(82783, global_step)
        optimizer = _configure_optimizer(learning_rate)
        summaries.add(tf.summary.scalar('learning_rate', learning_rate))
        for loss in tf.get_collection(tf.GraphKeys.LOSSES):
            summaries.add(tf.summary.scalar('losses/%s' % loss.op.name, loss))

        loss = tf.get_collection(tf.GraphKeys.LOSSES)
        regular_loss = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
Esempio n. 3
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)
Esempio n. 4
0
                                          is_training=True)

    if DEBUG:
        gt_boxes = np.random.randint(0, 200, (32, 2))
        shape = np.random.randint(10, 30, (32, 2))
        classes = np.random.randint(0, 81, (32, ))
        gt_boxes = np.hstack((gt_boxes, gt_boxes + shape, classes[:,
                                                                  np.newaxis]))
        gt_boxes = gt_boxes.astype(np.float32)
        gt_masks = np.zeros((32, 224, 224), np.int32)
        gt_masks[:, 100:150, 100:150] = 1

    ## losses
    outputs = pyramid_network.build_losses(pyramid,
                                           outputs,
                                           gt_boxes,
                                           gt_masks,
                                           num_classes=81,
                                           base_anchors=15)

    ## optimization
    learning_rate = _configure_learning_rate(82783, global_step)
    optimizer = _configure_optimizer(learning_rate)
    summaries.add(tf.summary.scalar('learning_rate', learning_rate))
    for loss in tf.get_collection(tf.GraphKeys.LOSSES):
        summaries.add(tf.summary.scalar('losses/%s' % loss.op.name, loss))
    learning_rate = _configure_learning_rate(82783, global_step)
    optimizer = _configure_optimizer(learning_rate)

    loss = tf.get_collection(tf.GraphKeys.LOSSES)
    regular_loss = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
    total_loss = tf.add_n(loss + regular_loss)
Esempio n. 5
0
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, [1, 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)

gt_boxes = np.random.randint(0, 200, (32, 2))
shape = np.random.randint(10, 30, (32, 2))
classes = np.random.randint(0, 81, (32,))
gt_boxes = np.hstack((gt_boxes, gt_boxes + shape, classes[:, np.newaxis]))
gt_masks = np.zeros((32, 224, 224), np.int32)
gt_masks[:, 100:150, 100:150 ] = 1

outputs = pyramid_network.build_losses(pyramid, outputs,
                                       gt_boxes.astype(np.float32), gt_masks.astype(np.float32),
                                       num_classes=81, base_anchors=15)