Go to the documentation of this file.
2 import tensorflow
as tf
6 ''' Initialize the numpy and tensorflow random states, setting the tensorflow global random state
7 since most tensorflow methods don't yet pass around a random state appropriately. TF random
8 states might also not play nice with tf.functions:
9 https://www.tensorflow.org/api_docs/python/tf/random/set_global_generator
11 np_random = np.random.RandomState(seed)
12 tf_seed = np_random.randint(1e10, dtype=np.int64)
13 tf_random = tf.random.Generator.from_seed(tf_seed)
14 tf.random.set_global_generator(tf_random)
15 return {
'np_random' : np_random,
'tf_random' : tf_random}
19 ''' Ensure passed array has two dimensions [n_sample, n_feature], and add the n_feature axis if not '''
20 arr = np.array(arr).
copy().astype(np.float32)
21 return (arr[:,
None]
if len(arr.shape) == 1
else arr)
25 ''' Return the tf.device a job should run on. Logic based
26 on e.g. model size may be added in the future.
28 gpus = tf.config.list_physical_devices(
'GPU')
29 cpus = tf.config.list_physical_devices(
'CPU')
30 name = (gpus+cpus)[0].name.replace(
'physical_device:',
'')
31 return tf.device(
'/cpu:0')
def initialize_random_states(seed=None)
void copy(double **aout, double **ain, int n)
def get_device(model_config)