示例#1
0
def main(_):
    assert FLAGS.out
    assert FLAGS.db and os.path.exists(FLAGS.db)

    picpac_config = dict(
        seed=2016,
        #loop=True,
        shuffle=True,
        reshuffle=True,
        #resize_width=256,
        #resize_height=256,
        round_div=FLAGS.stride,
        batch=1,
        split=1,
        split_fold=0,
        annotate='json',
        channels=FLAGS.channels,
        stratify=True,
        pert_color1=20,
        pert_angle=20,
        pert_min_scale=0.8,
        pert_max_scale=1.2,
        #pad=False,
        pert_hflip=True,
        pert_vflip=True,
        channel_first=False  # this is tensorflow specific
        # Caffe's dimension order is different.
    )

    stream = picpac.ImageStream(FLAGS.db,
                                perturb=False,
                                loop=False,
                                **picpac_config)

    gal = Gallery(FLAGS.out)
    cc = 0
    with Model(FLAGS.model, name=FLAGS.name, prob=True) as model:
        for images, _, _ in stream:
            #images *= 600.0/1500
            #images -= 800
            #images *= 3000 /(2000-800)
            _, H, W, _ = images.shape
            if FLAGS.max_size:
                if max(H, W) > FLAGS.max_size:
                    continue
            if FLAGS.patch:
                stch = Stitcher(images, FLAGS.patch)
                probs = stch.stitch(model.apply(stch.split()))
            else:
                probs = model.apply(images)
            cc += 1
            save(gal.next(), images, probs)
            if FLAGS.max and cc >= FLAGS.max:
                break
    gal.flush()
    pass