Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

set seed tensorflow

import tensorflow as tf
import os
import numpy as np
import random

SEED = 0

#Function to initialize seeds for all libraries which might have stochastic behavior
def set_seeds(seed=SEED):
    os.environ['PYTHONHASHSEED'] = str(seed)
    random.seed(seed)
    tf.random.set_seed(seed)
    np.random.seed(seed)

# Activate Tensorflow deterministic behavior
def set_global_determinism(seed=SEED):
    set_seeds(seed=seed)

    os.environ['TF_DETERMINISTIC_OPS'] = '1'
    os.environ['TF_CUDNN_DETERMINISTIC'] = '1'
    
    tf.config.threading.set_inter_op_parallelism_threads(1)
    tf.config.threading.set_intra_op_parallelism_threads(1)

# Call the above function with seed value
set_global_determinism(seed=SEED)
Comment

PREVIOUS NEXT
Code Example
Python :: PYTHON 3.0 MAKE A HEART 
Python :: pd.read_excel 
Python :: alphabet python 
Python :: convert string of list to list python 
Python :: pyramid pattern in python 
Python :: how to extract integers from string python 
Python :: prime number in python 
Python :: the following packages have unmet dependencies python3-tornado 
Python :: decision tree algorithm python 
Python :: error command errored out with exit status 1 face_recognition 
Python :: python operators 
Python :: how to remove a string inside another string python 
Python :: plt.annotate text size 
Python :: python remove first element from list 
Python :: how to make a latency command in discord py 
Python :: how to check an element in a list in python 
Python :: python kill all threads 
Python :: turn false true column into 0 1 pandas 
Python :: python mean ndarray 
Python :: shutdown flask server with request 
Python :: how to import request library in python 
Python :: python pip jupyter notebook install 
Python :: how to convert a set to a list in python 
Python :: como transformar texto a audio y reproducirlo en pyrthon 
Python :: how to use static files in django 
Python :: pandas lamda column reference 
Python :: pandas replace nan with mean 
Python :: python max key dictionary key getter 
Python :: python float print 2 digits 
Python :: copy list python 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =