python - 在 colab 中运行 jupyter 笔记本

标签 python jupyter-notebook tensorflow-probability

在 tensorflow 概率中运行 colab 示例时出现错误。

https://github.com/tensorflow/probability/blob/master/tensorflow_probability/examples/jupyter_notebooks/Bayesian_Gaussian_Mixture_Model.ipynb

尝试更改它,但我认为代码需要更新。

def session_options(enable_gpu_ram_resizing=True):
  """Convenience function which sets common `tf.Session` options."""
  config = tf.ConfigProto()
  config.log_device_placement = True
  if enable_gpu_ram_resizing:
    # `allow_growth=True` makes it possible to connect multiple colabs to your
    # GPU. Otherwise the colab malloc's all GPU ram.
    config.gpu_options.allow_growth = True
  return config

def reset_sess(config=None):
  """Convenience function to create the TF graph and session, or reset them."""
  if config is None:
    config = session_options()
  tf.reset_default_graph()
  global sess
  try:
    sess.close()
  except:
    pass
  sess = tf.InteractiveSession(config=config)

reset_sess()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-8f3c54a802d4> in <module>()
     21   sess = tf.InteractiveSession(config=config)
     22 
---> 23 reset_sess()

1 frames
<ipython-input-8-8f3c54a802d4> in reset_sess(config)
     12   """Convenience function to create the TF graph and session, or reset them."""
     13   if config is None:
---> 14     config = session_options()
     15   tf.reset_default_graph()
     16   global sess

<ipython-input-8-8f3c54a802d4> in session_options(enable_gpu_ram_resizing)
      1 def session_options(enable_gpu_ram_resizing=True):
      2   """Convenience function which sets common `tf.Session` options."""
----> 3   config = tf.ConfigProto()
      4   config.log_device_placement = True
      5   if enable_gpu_ram_resizing:

AttributeError: module 'tensorflow' has no attribute 'ConfigProto'

没有错误。 Colab 笔记本应该运行最新的更新。 我认为代码需要更新,我尝试更新配置但出现更多错误。

最佳答案

由于错误显示模块“tensorflow”没有属性“ConfigProto”,这意味着您需要导入它..如果它不起作用,则在虚拟环境中导入

关于python - 在 colab 中运行 jupyter 笔记本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57336047/

相关文章:

ipython - 如何在 ipython 笔记本中的 javascript 代码中使用 python 定义的变量?

python - 在 TensorFlow 中保存和恢复函数

python - 我可以使用 DistributionLambda 层优化三个参数吗?

tensorflow-probability - tensorflow 概率中外行术语中的双射是什么

python - 使用python requests模块获取验证码图像的问题

Python urlopen 错误

Python:在 setup.py 中处理 numpy、scipy 和 matplotlib 依赖项

python - 日期时间到文件时间 (Python)

jupyter-notebook - iPython 笔记本 : render cell as HTML from variable content

python - 从库 python-chess on line 命令可视化完整的棋盘