Skip to content
Snippets Groups Projects
Commit 615e80ea authored by Stephane Chavin's avatar Stephane Chavin
Browse files

add script

parent bf80eed5
No related branches found
No related tags found
No related merge requests found
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('_'+today.day+'_'+today.month))
outdir = args.direction
df = pd.DataFrame(columns = ['file','idx','espece','x','y','w','h','conf'])
for i in tqdm(os.listdir(annots)):
if i == 'list_results_YOLO.csv':
continue
else:
table = pd.read_csv(str(annots+i), sep=' ')
l=[]
tab= pd.DataFrame(columns = ['file','idx','espece','x','y','w','h','conf'])
tab2 = pd.DataFrame(columns = ['file','idx','espece','x','y','w','h','conf'])
if len (table) == 0:
for j in table.columns:
l.append(j)
name = i.split('.')[0]
if len(name.split('_')[-1]) == 2:
name = name.split('.')[0][0:-3]
elif len(name.split('_')[-1]) == 3:
name = name.split('.')[0][0:-4]
else :
name= name.split('.')[0][0:-2]
name = str(name+'.wav')
idx = i.split('_')[-1]
idx = idx.split('.')[0]
table = pd.DataFrame([[name, idx, l[0],l[1],l[2],l[3],l[4],l[5]]], columns = ['file', 'idx','espece','x','y','w','h','conf'])
df = pd.concat([df,table])
else:
nb = len(table)
name = i.split('.')[0]
if len(name.split('_')[-1]) == 2:
name = name.split('.')[0][0:-3]
elif len(name.split('_')[-1]) == 3:
name = name.split('.')[0][0:-4]
else :
name= name.split('.')[0][0:-2]
name = str(name+'.wav' )
idx = i.split('_')[-1]
idx = idx.split('.')[0]
for j in table.columns:
l.append(j)
try :
tab2 = pd.DataFrame([[name, idx, l[0],l[1],l[2],l[3],l[4],l[5]]],columns = ['file', 'idx','espece','x','y','w','h','conf'])
except:
ipdb.set_trace()
for v in range(nb):
new = pd.DataFrame([[name, idx, table.iloc[v][0],table.iloc[v][1], table.iloc[v][2],table.iloc[v][3],table.iloc[v][4],table.iloc[v][5]]], columns = ['file', 'idx','espece','x','y','w','h','conf'])
tab = pd.concat([tab , new])
table = pd.concat([tab2, tab])
df = pd.concat([df, table])
#put the classes here
names = []
df['annot'] = 'None'
for j in range (len(df)):
df['annot'].iloc[j] = names[int(df.espece.iloc[j])]
print('Calculating the positions','\n')
corres = pd.DataFrame(columns=['start','stop'])
new = pd.DataFrame([['0','8']],columns = ['start','stop'])
corres = pd.concat([corres,new])
new = pd.DataFrame([['6','14']],columns = ['start','stop'])
corres = pd.concat([corres,new])
DUREE_SPECTRO = 8
OVERLAP = 2
for k in range(50):
val = k+1
new = pd.DataFrame([[int(corres.start.iloc[val])+(DUREE_SPECTRO - OVERLAP),int(corres.stop.iloc[val])+(DUREE_SPECTRO - OVERLAP)]],columns = ['start','stop'])
corres = pd.concat([corres,new])
df['midl'] = 'None'
for w in range(len(df.midl)):
if int(df.idx.iloc[w]) == 0:
try:
df.midl.iloc[w] = float(df.x.iloc[w])*DUREE_SPECTRO+float(corres.start.iloc[int(df.idx.iloc[w])])
except:
ipdb.set_trace()
else:
df.midl.iloc[w] = float(df.x.iloc[w])*DUREE_SPECTRO+float(corres.start.iloc[int(df.idx.iloc[w])])
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment