VIDA-NYU / tile2net

Automated mapping of pedestrian networks from aerial imagery tiles
BSD 3-Clause "New" or "Revised" License
146 stars 22 forks source link

Local/tile2net/dhodcz2 #44

Closed dhodcz2 closed 7 months ago

dhodcz2 commented 7 months ago

Added commandline arg result_percent with default = 0 to describe the percentage of images that should be dumped:


    def dump(self, dump_dict, val_idx, testing=None, grid=None):
        if self.result_percent < 100:
            return
        self.result_percent -= 100
        self.result_percent += cfg.RESULT_PERCENT

        if (val_idx % self.dump_frequency or cfg.GLOBAL_RANK != 0):
            return

        os.makedirs(self.save_dir, exist_ok=True)
        colorize_mask_fn = cfg.DATASET_INST.colorize_mask

this is available as cfg.RESULT_PERCENT or args.result_percent. Removed mkdir from ImageDumper.__init__

Asserted tile_step power of 2 in Raster.__init__:

            raise ValueError('Tile step must be a power of 2')

Inference only calls mkdir if result_percent:

@commandline
def inference(args: Namespace):
    # sys.stdin
    if args.result_percent:
        if not os.path.exists(args.result_dir):
            os.mkdir(args.result_dir)
        assert os.path.exists(args.result_dir), 'Result directory does not exist'
        logging.info(f'Inferencing. Segmentation results will be saved to {args.result_dir}')
    else:
        logging.info('Inferencing. Segmentation results will not be saved.')
dhodcz2 commented 7 months ago

name has been changed to dump_percent, added to cfg/args, and visible in documentation in inference.ipynb and inference.commandline:

    def create_composite_image(self, input_image, prediction_pil, img_name):
        if not self.args.dump_percent:
            return
        self.dump_percent += self.args.dump_percent
        if self.dump_percent < 100:
            return
        self.dump_percent -= 100
        parent = os.path.dirname(self.save_dir)
        os.makedirs(parent, exist_ok=True)
dhodcz2 commented 7 months ago

We don't have automated tests yet but these checks were passed:

try:
    raster = Raster(
        location='Boston Common',
        zoom=19,
        tile_step=3,
        dump_percent=10,
    )
except ValueError:
    ...
else:
    raise AssertionError('Raster should have failed')

try:
    raster = Raster(
        location='Boston Common',
        zoom=19,
        tile_step=-5,
        dump_percent=10,
    )
except ValueError:
    ...
else:
    raise AssertionError('Raster should have failed')

examples/example.sh did not create seg_results under example/segmentation

raster = Raster(
    location='Boston Common',
    zoom=19,
    dump_percent=10,
    # dump_percent=0,
)
raster.generate(2)
raster.inference()

4 images were created under segmentation/seg_results