(input_dir, out_dir, img_reshape=(300, 994),
                 train_percent=90, overwrite=False, skip_unzip=False)
Ingests the KITTI dataset. Peforms the following ops:
    0. Unzips the files into output directory.
    1. Reshapes image to lower resolution (default reshape of 300x994 maintains KITTI image AR)
    1. Convert annotations to json format
    2. Split the training data into train and validation sets
    3. Write manifest file
    4. Write configuration file

    Arguments:
        input_dir (string): path to folder with KITTI zip files.
        out_dir (string): path to unzip KITTI data
        img_reshape (tuple of int): size to reshape image (default = (300, 994))
        train_percent (float): percent of data to use for training.
        overwrite (bool): overwrite existing files
Ingests the KITTI dataset. Peforms the following ops:
    0. Unzips the files into output directory.
    1. Reshapes image to lower resolution (default reshape of 300x994 maintains KITTI image AR)
    1. Convert annotations to json format
    2. Split the training data into train and validation sets
    3. Write manifest file
    4. Write configuration file
Ingests the KITTI dataset . Peforms the following ops : 0 . Unzips the files into output directory . 1 . Reshapes image to lower resolution ( default reshape of 300x994 maintains KITTI image AR ) 1 . Convert annotations to json format 2 . Split the training data into train and validation sets 3 . Write manifest file 4 . Write configuration file
def ingest_kitti(input_dir, out_dir, img_reshape=(300, 994),
                 train_percent=90, overwrite=False, skip_unzip=False):
    """
    Ingests the KITTI dataset. Peforms the following ops:
    0. Unzips the files into output directory.
    1. Reshapes image to lower resolution (default reshape of 300x994 maintains KITTI image AR)
    1. Convert annotations to json format
    2. Split the training data into train and validation sets
    3. Write manifest file
    4. Write configuration file

    Arguments:
        input_dir (string): path to folder with KITTI zip files.
        out_dir (string): path to unzip KITTI data
        img_reshape (tuple of int): size to reshape image (default = (300, 994))
        train_percent (float): percent of data to use for training.
        overwrite (bool): overwrite existing files
    """

    assert img_reshape is not None, "Target image reshape required."
    hw = '{}x{}'.format(img_reshape[0], img_reshape[1])

    zip_files = ['data_object_image_2.zip', 'data_object_label_2.zip']

    root_dir = os.path.join(out_dir, 'kitti')
    train_manifest = os.path.join(root_dir, 'train_{}.csv'.format(hw))
    val_manifest = os.path.join(root_dir, 'val_{}.csv'.format(hw))

    if os.path.exists(train_manifest) and os.path.exists(val_manifest) and not overwrite:
        print("Manifest files already found, skipping ingest.")
        print("Use --overwrite flag to force re-ingest.")
        return

    util.make_dir(root_dir)

    tags = {'trainval': [], 'test': []}

    if skip_unzip is False:
        util.unzip_files(zip_files, input_dir, root_dir)

    img_folder = os.path.join(root_dir, 'training', 'image_2')
    annot_folder = os.path.join(root_dir, 'training', 'label_2')

    target_img_folder = os.path.join(root_dir, 'training', 'image_2-converted')
    target_annot_folder = os.path.join(root_dir, 'training', 'label_2-json')

    tags = glob.glob(os.path.join(img_folder, '*.png'))
    tags = [os.path.basename(os.path.splitext(tag)[0]) for tag in tags]
    assert len(tags) > 0, "No images found in {}".format(img_folder)

    util.make_dir(target_img_folder)
    util.make_dir(target_annot_folder)

    manifest = []

    for tag in tqdm(tags):

        image = os.path.join(img_folder, tag + '.png')
        annot = os.path.join(annot_folder, tag + '.txt')
        assert os.path.exists(image), "{} not found.".format(image)
        assert os.path.exists(annot), "{} not found.".format(annot)

        target_image = os.path.join(target_img_folder, tag + '.png')
        target_annot = os.path.join(target_annot_folder, tag + '.json')

        convert_annot_to_json(annot, image, target_annot, difficult=True, img_reshape=None)
        util.resize_image(image, target_image, img_reshape=None)

        manifest.append((target_image, target_annot))

    # shuffle files and split into training and validation set.
    np.random.seed(0)
    np.random.shuffle(manifest)

    train_count = (len(manifest) * train_percent) // 100
    train = manifest[:train_count]
    val = manifest[train_count:]

    util.create_manifest(train_manifest, train, root_dir)
    util.create_manifest(val_manifest, val, root_dir)

    # write SSD CONFIG
    ssd_config = get_ssd_config(img_reshape)
    ssd_config_path = os.path.join(root_dir, 'kitti_ssd_{}.cfg'.format(hw))
    util.write_ssd_config(ssd_config, ssd_config_path, True)

    # write SSD VAL CONFIG
    ssd_config_val = get_ssd_config(img_reshape, True)
    ssd_config_path_val = os.path.join(root_dir, 'kitti_ssd_{}_val.cfg'.format(hw))
    util.write_ssd_config(ssd_config_val, ssd_config_path_val, True)

    config_path = os.path.join(root_dir, 'kitti_{}.cfg'.format(hw))
    config = {'manifest': '[train:{}, val:{}]'.format(train_manifest, val_manifest),
              'manifest_root': root_dir,
              'epochs': 100,
              'height': img_reshape[0],
              'width': img_reshape[0],
              'ssd_config': '[train:{}, val:{}]'.format(ssd_config_path, ssd_config_path_val)
              }

    util.write_config(config, config_path)
def ingest_kitti ( input_dir , out_dir , img_reshape = ( 300 , 994 ) , train_percent = 90 , overwrite = False , skip_unzip = False ) : assert img_reshape is not None , "Target image reshape required." hw = '{}x{}' . format ( img_reshape [ 0 ] , img_reshape [ 1 ] ) zip_files = [ 'data_object_image_2.zip' , 'data_object_label_2.zip' ] root_dir = os . path . join ( out_dir , 'kitti' ) train_manifest = os . path . join ( root_dir , 'train_{}.csv' . format ( hw ) ) val_manifest = os . path . join ( root_dir , 'val_{}.csv' . format ( hw ) ) if os . path . exists ( train_manifest ) and os . path . exists ( val_manifest ) and not overwrite : print ( "Manifest files already found, skipping ingest." ) print ( "Use --overwrite flag to force re-ingest." ) return util . make_dir ( root_dir ) tags = { 'trainval' : [ ] , 'test' : [ ] } if skip_unzip is False : util . unzip_files ( zip_files , input_dir , root_dir ) img_folder = os . path . join ( root_dir , 'training' , 'image_2' ) annot_folder = os . path . join ( root_dir , 'training' , 'label_2' ) target_img_folder = os . path . join ( root_dir , 'training' , 'image_2-converted' ) target_annot_folder = os . path . join ( root_dir , 'training' , 'label_2-json' ) tags = glob . glob ( os . path . join ( img_folder , '*.png' ) ) tags = [ os . path . basename ( os . path . splitext ( tag ) [ 0 ] ) for tag in tags ] assert len ( tags ) > 0 , "No images found in {}" . format ( img_folder ) util . make_dir ( target_img_folder ) util . make_dir ( target_annot_folder ) manifest = [ ] for tag in tqdm ( tags ) : image = os . path . join ( img_folder , tag + '.png' ) annot = os . path . join ( annot_folder , tag + '.txt' ) assert os . path . exists ( image ) , "{} not found." . format ( image ) assert os . path . exists ( annot ) , "{} not found." . format ( annot ) target_image = os . path . join ( target_img_folder , tag + '.png' ) target_annot = os . path . join ( target_annot_folder , tag + '.json' ) convert_annot_to_json ( annot , image , target_annot , difficult = True , img_reshape = None ) util . resize_image ( image , target_image , img_reshape = None ) manifest . append ( ( target_image , target_annot ) ) # shuffle files and split into training and validation set. np . random . seed ( 0 ) np . random . shuffle ( manifest ) train_count = ( len ( manifest ) * train_percent ) // 100 train = manifest [ : train_count ] val = manifest [ train_count : ] util . create_manifest ( train_manifest , train , root_dir ) util . create_manifest ( val_manifest , val , root_dir ) # write SSD CONFIG ssd_config = get_ssd_config ( img_reshape ) ssd_config_path = os . path . join ( root_dir , 'kitti_ssd_{}.cfg' . format ( hw ) ) util . write_ssd_config ( ssd_config , ssd_config_path , True ) # write SSD VAL CONFIG ssd_config_val = get_ssd_config ( img_reshape , True ) ssd_config_path_val = os . path . join ( root_dir , 'kitti_ssd_{}_val.cfg' . format ( hw ) ) util . write_ssd_config ( ssd_config_val , ssd_config_path_val , True ) config_path = os . path . join ( root_dir , 'kitti_{}.cfg' . format ( hw ) ) config = { 'manifest' : '[train:{}, val:{}]' . format ( train_manifest , val_manifest ) , 'manifest_root' : root_dir , 'epochs' : 100 , 'height' : img_reshape [ 0 ] , 'width' : img_reshape [ 0 ] , 'ssd_config' : '[train:{}, val:{}]' . format ( ssd_config_path , ssd_config_path_val ) } util . write_config ( config , config_path )