2

I want to train a CNN in Google Colab and try to get reproducible results as possible. In the following code I am not sure if the order of the instructions for reproduciblity is correct. I wonder if os.environ['PYTHONHASHSEED']='0' is in the right place, or should it appear first in the code, before import numpy as np etc.


import numpy as np
import tensorflow as tf
import random as rn

import os
os.environ['PYTHONHASHSEED']='0'
np.random.seed(1)
rn.seed(1)

from keras import backend as K

if 'tensorflow' == K.backend():
  import tensorflow as tf
  from keras.backend.tensorflow_backend import set_session
  config = tf.ConfigProto()
  config.gpu_options.allow_growth = true
  config.gpu_options.allow_growth = True
  config.gpu_options.visible_device_liste = "0"
  set_session(tf.Session(config=config))

tf.set_random_seed(1) 
sess = tf.Session(graph=tf.get_default_graph(), config=session_conf)   
K.set_session(sess)   


!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials 

auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

I would be very happy and very thankful if someone could take a look at this code and could confirm the order as right or wrong.

Code Now
  • 711
  • 2
  • 9
  • 20

0 Answers0