Commit b1d7c011 authored by Michaël Lauer's avatar Michaël Lauer
Browse files

Added set_gpus function in utils to support CPU or GPU configuration. Changed...

Added set_gpus function in utils to support CPU or GPU configuration. Changed script using previous method to use the new function
parent 9902e3bd
import numpy as np
import tensorflow as tf
def load_ircam_hrirs_data(filepath='.//databases//ircam_hrirs_512samples.p'):
import pickle
......@@ -183,3 +183,17 @@ def split_long_wav(rootpath, max_parts=None):
data_parts_loud_enough = [part for i, part in enumerate(data_parts) if rms_values[i] >= rms_quantile]
print(f'selected {len(data_parts_loud_enough)}/{len(data_parts)}')
return data_parts_loud_enough
# from tensorflow GPU guide
def set_gpus():
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
# Currently, memory growth needs to be the same across GPUs
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
logical_gpus = tf.config.experimental.list_logical_devices('GPU')
print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
except RuntimeError as e:
# Memory growth must be set before GPUs have been initialized
print(e)
\ No newline at end of file
......@@ -10,8 +10,9 @@ from ipywidgets import widgets
from core.utils import data_generator
from core.metrics import MeanAbsoluteAzimuthError
physical_devices = tf.config.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)
#set GPUs if any
from core.utils import set_gpus
set_gpus()
root_dirs = ['../tf_results']
......
......@@ -12,10 +12,12 @@ from core.metrics import MeanAbsoluteAzimuthError
import math
import tensorflow.keras.backend as kb
physical_devices = tf.config.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)
#set GPUs if any
from core.utils import set_gpus
set_gpus()
root_dirs = ['../tf_results/comp_2021-01-29_19-07-46_0']
root_dirs = ['../tf_results/']
def generate_df_from_exp_dir(exp_dir):
......
......@@ -8,8 +8,10 @@ from core.model import default_model_creator, conv_model_creator
import pandas as pd
from core.metrics import MeanAbsoluteAzimuthError
physical_devices = tf.config.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)
#set GPUs if any
from core.utils import set_gpus
set_gpus()
parser = argparse.ArgumentParser()
parser.add_argument("--in_dir", type=str, help="input directory")
......@@ -19,7 +21,7 @@ ExperimentConfiguration = dict
ALL_SUBJECTS_EXCEPT_1059 = list(range(1002, 1010)) + list(range(1012, 1019)) + list(range(1021, 1024)) + list(
[1025, 1026]) + list(range(1028, 1035)) + list(range(1037, 1059))
exp_config = ExperimentConfiguration({'n_augment': 20,
exp_config = ExperimentConfiguration({'n_augment': 1,
'n_epochs': 20,
'n_iters': 20,
'batch_size': 512,
......@@ -66,7 +68,7 @@ if __name__ == '__main__':
# reset index
df.reset_index(drop=True, inplace=True)
all_subject_ids = df['subject_id'].cat.categories
all_subject_ids = df['subject_id'].astype('category').cat.categories
valid_train_subject_ids = 'train_subject_ids' in exp_config.keys() and exp_config[
'train_subject_ids'] is not None and len(exp_config['train_subject_ids']) > 0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment