我尝试使用以下代码在Google Colab中获得可重复的结果。 但出现错误“ NameError:未定义名称'session_conf'”。
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)
有人知道原因吗?
答案 0 :(得分:1)
您尚未在session_conf
行中声明变量sess = tf.Session(graph=tf.get_default_graph(), config=session_conf)
。