【问题标题】:"NameError: name 'session_conf' is not defined" when try to get reproducible results in google colab尝试在 google colab 中获得可重现的结果时出现“NameError: name 'session_conf' is not defined”
【发布时间】:2020-02-28 15:25:52
【问题描述】:

我尝试使用以下代码在 Google Colab 中获得可重现的结果。 但我收到错误“NameError: name 'session_conf' is not defined”。

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)

有人知道原因吗?

【问题讨论】:

  • 最明显的原因是该变量从未定义。就是这样。

标签: python tensorflow keras google-colaboratory reproducible-research


【解决方案1】:

您尚未在sess = tf.Session(graph=tf.get_default_graph(), config=session_conf) 行中声明变量session_conf

【讨论】:

  • 谢谢,当然。希望剩下的代码是对的。
猜你喜欢
  • 1970-01-01
  • 2015-11-11
  • 1970-01-01
  • 2023-02-05
  • 2020-11-24
  • 1970-01-01
  • 1970-01-01
  • 2021-02-17
  • 1970-01-01
相关资源
最近更新 更多