尝试在google colab中获取可复制结果时出现“NameError:name'session\u conf'未定义”

2024-03-29 09:46:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用以下代码在googlecolab中获得可复制的结果。 但是我得到错误“NameError:name'session\u 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)

有人知道为什么吗?你知道吗


Tags: fromimportauthconfigbackendgpusessiontf