在Colab、tf.contrib模块上找不到TensorFlow v1

2024-09-27 21:32:28 发布

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

试图在Google Colab中训练GPT-2。我运行的单元格如下所示:

!git clone https://github.com/shawwn/gpt-2 -b tpu /content/gpt-2

[……]

%tensorflow_version 1.x
!pip freeze | grep tensorflow
mesh-tensorflow==0.1.12
tensorflow==1.15.2
tensorflow-datasets==4.0.1
tensorflow-estimator==1.15.1
tensorflow-gan==2.0.0
tensorflow-gcs-config==2.4.0
tensorflow-hub==0.11.0
tensorflow-metadata==0.28.0
tensorflow-probability==0.7.0
%tensorflow_version 1.x
!PYTHONPATH=src ./train.py --help

我收到以下错误消息:

TensorFlow 1.x selected.
2021-03-14 14:22:11.118915: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
Traceback (most recent call last):
  File "./train.py", line 17, in <module>
    import model, sample, encoder
  File "/content/gpt-2/src/model.py", line 3, in <module>
    from tensorflow.contrib.training import HParams
ModuleNotFoundError: No module named 'tensorflow.contrib'

据我所知,TensorFlow v1.15.2应该包含contrib模块。我做错了什么

请注意,我没有编写这段代码,我正在使用其他人的git repo


Tags: inpyimportgitsrcversiontensorflowline
1条回答
网友
1楼 · 发布于 2024-09-27 21:32:28

Tensorflow 1.15.2有一个改进。 在colab中,确保Tensorflow 1.x安装后重新启动运行时,因为colab具有默认的2.x版本。 我在colab上试过同样的代码,它奏效了

相关问题 更多 >

    热门问题