Exemplo n.º 1
0
def get_dataset(dataset_name,
                split_name,
                dataset_dir,
                im_batch=1,
                is_training=False,
                file_pattern=None,
                reader=None):
    """"""
    if file_pattern is None:
        file_pattern = dataset_name + '_' + split_name + '*.tfrecord'

    tfrecords = glob.glob(dataset_dir + '/records/' + file_pattern)

    assert len(
        tfrecords
    ) > 0, "haven't found any tfrecord(did you run train.py from code root?). we were looking at %s." % dataset_dir + '/records/' + file_pattern

    image, ih, iw, gt_boxes, gt_masks, num_instances, img_id = coco.read(
        tfrecords, is_training=is_training)

    image, new_ih, new_iw, gt_boxes, gt_masks = coco_preprocess.preprocess_image(
        image, gt_boxes, gt_masks, is_training)
    #visualize_input(gt_boxes, image, tf.expand_dims(gt_masks, axis=3))

    return image, ih, iw, new_ih, new_iw, gt_boxes, gt_masks, num_instances, img_id
Exemplo n.º 2
0
def get_dataset(dataset_name, split_name, dataset_dir, 
        im_batch=1, is_training=False, file_pattern=None, reader=None):
    """"""
    if file_pattern is None:
        file_pattern = dataset_name + '_' + split_name + '*.tfrecord' 

    tfrecords = glob.glob(dataset_dir + '/records/' + file_pattern)
    image, ih, iw, gt_boxes, gt_masks, num_instances, img_id = coco.read(tfrecords)

    image, gt_boxes, gt_masks = coco_preprocess.preprocess_image(image, gt_boxes, gt_masks, is_training)

    return image, ih, iw, gt_boxes, gt_masks, num_instances, img_id
Exemplo n.º 3
0
    def prep_data(self, data):
        for i in range(len(data)):
            inputs = data[i]

            image = inputs['images']
            image = tf.decode_raw(image, tf.uint8)
            ih = inputs['height']
            iw = inputs['width']
            ih = tf.cast(ih, tf.int32)
            iw = tf.cast(iw, tf.int32)
            inputs['height'] = ih
            inputs['width'] = iw

            imsize = tf.size(image)

            #image = tf.Print(image, [imsize, ih, iw], message = 'Imsize')

            image = tf.cond(tf.equal(imsize, ih * iw), \
                  lambda: tf.image.grayscale_to_rgb(tf.reshape(image, (ih, iw, 1))), \
                  lambda: tf.reshape(image, (ih, iw, 3)))

            image_height = ih
            image_width = iw
            num_instances = inputs['num_objects']
            num_instances = tf.cast(num_instances, tf.int32)
            inputs['num_objects'] = num_instances
            gt_boxes = tf.decode_raw(inputs['bboxes'], tf.float64)
            gt_boxes = tf.reshape(gt_boxes, [num_instances, 4])

            labels = tf.decode_raw(inputs['labels'], tf.int32)
            labels = tf.reshape(labels, [num_instances, 1])
            inputs['labels'] = labels

            gt_boxes = tf.concat([gt_boxes, tf.cast(labels, tf.float64)], 1)
            gt_boxes = tf.cast(gt_boxes, tf.float32)

            gt_masks = tf.decode_raw(inputs['segmentation_masks'], tf.uint8)
            gt_masks = tf.cast(gt_masks, tf.int32)
            gt_masks = tf.reshape(gt_masks, [num_instances, ih, iw])
            #gt_masks = tf.Print(gt_masks, [tf.shape(gt_masks)], message = 'Mask shape before', summarize = 4)

            image, gt_boxes, gt_masks = coco_preprocess.preprocess_image(image, gt_boxes, gt_masks, True)
            #image = tf.Print(image, [tf.shape(image)], message = 'Imsize', summarize = 4)
            #gt_masks = tf.Print(gt_masks, [tf.shape(gt_masks)], message = 'Mask shape', summarize = 4)

            inputs['segmentation_masks'] = gt_masks
            inputs['bboxes'] = gt_boxes
            inputs['images'] = image

        return data
def get_dataset(dataset_name,
                split_name,
                dataset_dir,
                im_batch=1,
                is_training=False,
                file_pattern=None,
                reader=None):
    """"""
    if file_pattern is None:
        file_pattern = dataset_name + '_' + split_name + '*.tfrecord'

    pattern = '../' + dataset_dir + 'records/' + file_pattern

    tfrecords = glob.glob(pattern)
    image, ih, iw, gt_boxes, gt_masks, num_instances, img_id = coco.read(
        tfrecords)

    image, gt_boxes, gt_masks = coco_preprocess.preprocess_image(
        image, gt_boxes, gt_masks, is_training)
    #visualize_input(gt_boxes, image, tf.expand_dims(gt_masks, axis=3))

    return image, ih, iw, gt_boxes, gt_masks, num_instances, img_id
Exemplo n.º 5
0
DEBUG = False

with tf.Graph().as_default():
    gpu_options = tf.GPUOptions(
        per_process_gpu_memory_fraction=0.8,
        allow_growth=True,
    )
    with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options,
                                          allow_soft_placement=True)) as sess:
        global_step = slim.create_global_step()

        ## 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:
Exemplo n.º 6
0
import libs.nets.resnet_v1 as resnet_v1
import libs.datasets.dataset_factory as dataset_factory
import libs.datasets.coco as coco
import libs.preprocessings.coco_v1 as preprocess_coco
from libs.layers import ROIAlign

resnet50 = resnet_v1.resnet_v1_50
FLAGS = tf.app.flags.FLAGS

with tf.Graph().as_default():

  image, ih, iw, gt_boxes, gt_masks, num_instances, img_id = \
    coco.read('./data/coco/records/coco_trainval2014_00000-of-00048.tfrecord')
  
  image, gt_boxes, gt_masks = \
    preprocess_coco.preprocess_image(image, gt_boxes, gt_masks)

  

  sess = tf.Session()
  init_op = tf.group(tf.global_variables_initializer(),
                     tf.local_variables_initializer())
  # init_op = tf.initialize_all_variables()

  boxes = [[100, 100, 200, 200],
           [50, 50, 100, 100],
           [100, 100, 750, 750],
           [50, 50, 60, 60]]
  # boxes = np.zeros((0, 4))
  boxes = tf.constant(boxes, tf.float32)
  feat = ROIAlign(image, boxes, False, 16, 7, 7)
Exemplo n.º 7
0
    return tfrecords


with tf.Graph().as_default():

    records = get_records(FLAGS.dataset_name,
                          FLAGS.dataset_split_name,
                          FLAGS.dataset_dir,
                          FLAGS.im_batch,
                          is_training=False)

    image, ih, iw, gt_boxes, gt_masks, num_instances, img_id = \
        coco.read(records)

    image, gt_boxes, gt_masks = \
        preprocess_coco.preprocess_image(image, gt_boxes, gt_masks)

    # using queue to input
    queue = tf.RandomShuffleQueue(capacity=12,
                                  min_after_dequeue=6,
                                  dtypes=(image.dtype, ih.dtype, iw.dtype,
                                          gt_boxes.dtype, gt_masks.dtype,
                                          num_instances.dtype, img_id.dtype))
    enqueue_op = queue.enqueue(
        (image, ih, iw, gt_boxes, gt_masks, num_instances, img_id))
    (image_, ih_, iw_, gt_boxes_, gt_masks_, num_instances_,
     img_id_) = queue.dequeue()
    qr = tf.train.QueueRunner(queue, [enqueue_op] * 4)

    sess = tf.Session()
    init_op = tf.group(tf.global_variables_initializer(),
Exemplo n.º 8
0
cls = np.random.randint(1, 6, (N, 1)).astype(np.float32)
gt_boxes = np.hstack((xy, xy + wh, cls)).astype(np.float32)
gt_boxes_np = gt_boxes 
image_np = image 
gt_masks_np = gt_masks 

for i in range(N):
    box = gt_boxes[i, 0:4]
    gt_masks[i, int(box[1]):int(box[3]),
                int(box[0]):int(box[2])] = 1
image = tf.constant(image)
gt_boxes = tf.constant(gt_boxes)
gt_masks = tf.constant(gt_masks)

image, gt_boxes, gt_masks = \
        coco_preprocess.preprocess_image(image, gt_boxes, gt_masks, is_training=True)

with tf.Session() as sess:
    # print(image.eval())
    image_tf, gt_boxes_tf, gt_masks_tf = \
            sess.run([image, gt_boxes, gt_masks])
    print ('#######################')
    print ('DATA PREPROCESSING TEST')
    print ('#######################')
    print ('gt_boxes shape:', gt_boxes_tf.shape)
    print('mask shape:', gt_masks_tf.shape)
    print(gt_boxes_tf)
    for i in range(N):
        box = np.round(gt_boxes_tf[i, 0:4])
        box = box.astype(np.int32)
        m = gt_masks_tf[i, box[1]:box[3], box[0]:box[2]]