Skip to content
Snippets Groups Projects
Select Git revision
  • 3c1ffee8e42b9fc082bafd1099d81ace76c6cb32
  • master default protected
2 results

setup.py

Blame
  • get_yolo_detection.py NaN GiB
    import pandas as pd
    import os
    import ipdb
    from tqdm import tqdm
    import argparse
    from datetime import date
    
    def arg_directory(path):
        if os.path.isdir(path):
            return path
        else:
            raise argparse.ArgumentTypeError(f'`{path}` is not a valid path')
    
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='TODO')
    parser.add_argument('-p','--path_to_data', type=arg_directory, help = 'Path of the folder that contain the .txt files',required=True)
    parser.add_argument('-d','--direction', type=arg_directory, help = 'Directory to wich the dataframe will be stored',required=True)
    args = parser.parse_args()
    
    annots = args.path_to_data
    
    today = date.today()
    out_file = str('YOLO_detection_'+str('_'+str(today.day)+'_'+str(today.month)))
    
    outdir = args.direction
    
    df = pd.concat({f:pd.read_csv(os.path.join(annots, f), sep=' ', names=['espece', 'x', 'y', 'w', 'h','conf'])
    				for f in tqdm(os.listdir(annots))}, names=['file'])
    
    df = df.reset_index(level=[0])
    df = df.reset_index()
    del df['index']
    df['idx'] = df.file.str.split('_').str[-1].str.split('.').str[0]
    df.file = df.file.str.rsplit('.',1).str[0]+'.wav'
    
    DUREE_SPECTRO = 8
    OVERLAP = 2
    
    #put the classes here
    names = []
    
    df['annot'] = 'None'
    for j in range (len(df)):
    	df['annot'].iloc[j] = names[int(df.espece.iloc[j])]
    
    df.to_csv(os.path.join(outdir,str(out_file+'.csv')), index= False)
    print('saved as ',os.path.join(outdir,str(out_file+'.csv')))