在尝试运行 colab 时,多个地方出现问题...
那一行
from bert import run_classifier
失败了(因为 TensorFlow 不再有一个名为 contrib 的模块)。堆栈跟踪如下:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-1ccb11d8dffa> in <module>()
1 import bert
----> 2 from bert import run_classifier
3 from bert import optimization
4 from bert import tokenization
1 frames
/usr/local/lib/python3.6/dist-packages/bert/run_classifier.py in <module>()
22 import csv
23 import os
---> 24 from bert import modeling
25 from bert import optimization
26 from bert import tokenization
/usr/local/lib/python3.6/dist-packages/bert/modeling.py in <module>()
27 import six
28 import tensorflow.compat.v1 as tf
---> 29 from tensorflow.contrib import layers as contrib_layers
30
31
ModuleNotFoundError: No module named 'tensorflow.contrib'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
然后在下面的单元格中,它允许你为模型选择输出目录:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-ba2fc219037b> in <module>()
20 # Doesn't matter if the directory didn't exist
21 pass
---> 22 tf.gfile.MakeDirs(OUTPUT_DIR)
23 print('***** Model output directory: {} *****'.format(OUTPUT_DIR))
AttributeError: module 'tensorflow' has no attribute 'gfile'
新的 TensorFlow 版本需要在这里进行更新。
3条答案
按热度按时间d7v8vwbk1#
将所有
tf.gfile
的调用替换为tf.io.gfile
(然后也修复所有其他调用,因为tf.gile.MakeDirs
现在是tf.io.gfile.makedirs
等,所以不仅仅是sed替换)x0fgdtte2#
我应该使用tf版本<=1.5吗?
omjgkv6w3#
switch to tf 1.x solved all my import problems. Here's the code that I use (make sure to restart runtime before running it)