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

updates (correction multiprocess)

parent bfd5e811
No related branches found
No related tags found
No related merge requests found
......@@ -12,9 +12,9 @@ warnings.filterwarnings('ignore')
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='TODO')
parser.add_argument('-f','--file', type=str,required=True,help = 'Name of the file that contain the recording to print')
parser.add_argument('-p','--path_to_data', type=str, help = 'Path of the folder that contain the recodings',required=True)
parser.add_argument('-p','--path_to_data', type=str, help = 'Path of the folder that contain the recordings',required=True)
parser.add_argument('-d','--direction', type=str, help = 'Directory to wich spectrogram will be stored',required=True)
parser.add_argument('-m','--mode', type=str,choices=['uniform','personalized'], help = 'Direction of the saved spectrogram',required=True)
parser.add_argument('-m','--mode', type=str,choices=['unique','multiple'], help = 'Direction of the saved spectrogram',required=True)
args = parser.parse_args()
path_to_data = args.path_to_data
......@@ -22,41 +22,35 @@ direction = args.direction
folder = 'Spectrogram/'
DURATION = 5
OVERLAP = 2
if args.mode == 'unique':
NB_IMG_PER_REC = 1
else:
NB_IMG_PER_REC = 10
count = 0
#import ipdb;ipdb.set_trace()
df = pd.read_csv(str(args.file),low_memory=False)
df['Path'] = ''
for w in range (len(df)):
df.loc[w,'Path']=str(args.path_to_data+ df.code_unique[w]+"_split_" + str(df.chunk_initial_time[w]) + "_" + str(df.chunk_final_time[w]))
#for w in range (len(df)):
# df.loc[w,'Path']=str(args.path_to_data+ df.code_unique[w]+"_split_" + str(df.chunk_initial_time[w]) + "_" + str(df.chunk_final_time[w]))
for w in range (len(df)):
df.loc[w,'Path']=str('/nfs/NAS7/Quebec2'+df.dir[w])
def process(x):
count, (i) = x
_, (i) = x
for j in range (NB_IMG_PER_REC): #30*8 secondes - 30*2 secondes (overlap) = 180 secondes affichées sur 30 images : n'affiche que les 3 premières minutes d'un enregistrement
for count, j in enumerate(range (NB_IMG_PER_REC)): #30*8 secondes - 30*2 secondes (overlap) = 180 secondes affichées sur 30 images : n'affiche que les 3 premières minutes d'un enregistrement
filename = str(i[0])
if args.mode == 'multiple' :
if count ==0:
duration = DURATION
offset = 0
else :
duration = DURATION
offset = offset + (DURATION - OVERLAP)
if args.mode == 'unique':
offset = 0
offset = count * (DURATION - OVERLAP)
try:
y, sr = librosa.load(filename, offset = offset, duration = DURATION)
except Exception:
print(filename)
continue
window_size = 1024
window = np.hanning(window_size)
stft = librosa.core.spectrum.stft(y, n_fft=window_size, hop_length=512, window=window)
out = 2 * np.abs(stft) / np.sum(window)
plt.close()
plt.figure()
......@@ -70,7 +64,6 @@ def process(x):
name = str(i[0].replace('/','_').split('.')[0]+'_'+str(count))
try :
plt.savefig(str(direction+folder+name+'.jpg'))
except FileNotFoundError:
......@@ -78,4 +71,6 @@ def process(x):
os.mkdir(str(direction+folder))
plt.savefig(str(direction+folder+name+'.jpg'))
p_map(process, enumerate(df.groupby('Path')), num_cpus=10) #la colonne dir correspond au path
print('saved to ',str(direction+folder))
\ No newline at end of file
......@@ -18,7 +18,7 @@ today = date.today()
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='TODO')
parser.add_argument('-f','--filename_path', type=str, help = 'Path and name of the file containing the annotations',required=True)
parser.add_argument('-p','--path_to_data', type=str, help = 'Path of the folder that contain the recodings',required=True)
parser.add_argument('-p','--path_to_data', type=str, help = 'Path of the folder that contain the recordings',required=True)
parser.add_argument('-d','--direction', type=str, help = 'Directory to wich spectrograms and .txt files will be stored',required=True)
parser.add_argument('-m','--mode',type=str,choices=['uniform','personalized'],help = 'Choose the mode to calculate the y and height value',required=True)
parser.add_argument('--export',type=str, default=None, help='To export the position of the bounding box on the spectrogram',required=False)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment