报错信息如下:
ImportError: Failed to import test module: seq2seq
Traceback (most recent call last):
File "/usr/lib/python3.5/unittest/loader.py", line 153, in loadTestsFromName
module = __import__(module_name)
File "/home/tfdata/seq2seq/seq2seq/__init__.py", line 26, in <module>
from seq2seq import decoders
File "/home/tfdata/seq2seq/seq2seq/decoders/__init__.py", line 20, in <module>
from seq2seq.decoders.attention_decoder import *
File "/home/tfdata/seq2seq/seq2seq/decoders/attention_decoder.py", line 27, in <module>
from seq2seq.contrib.seq2seq.helper import CustomHelper
File "/home/tfdata/seq2seq/seq2seq/contrib/seq2seq/helper.py", line 35, in <module>
from tensorflow.contrib.distributions.python.ops import bernoulli
ImportError: cannot import name 'bernoulli'
解决方案:
修改 seq2seq/contrib/seq2seq/helper.py 文件
sudo vim seq2seq/contrib/seq2seq/helper.py
找到位置,修改为如下信息:
from tensorflow.contrib.distributions import Bernoulli
from tensorflow.contrib.distributions import Categorical
sampler = Bernoulli(probs=self._sampling_probability)
sample_id_sampler = Categorical(logits=outputs)
很有可能你解决第一个问题后,就会遇见第二个问题
报错信息:
ERROR: test_train_infer (seq2seq.test.pipeline_test.PipelineTest)
Tests training and inference scripts.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/tfdata/seq2seq/seq2seq/test/pipeline_test.py", line 76, in test_train_infer
_clear_flags()
File "/home/tfdata/seq2seq/seq2seq/test/pipeline_test.py", line 44, in _clear_flags
tf.app.flags.FLAGS = tf.app.flags._FlagValues()
AttributeError: module 'tensorflow.python.platform.flags' has no attribute '_FlagValues'
这个问题的解决办法是:
修改 seq2seq/test/pipeline_test.py 这个文件
sudo vim seq2seq/test/pipeline_test.py
修改 def _clear_flags() 这个方法
改为下面这种:
def _clear_flags():
"""Resets Tensorflow's FLAG values"""
#pylint: disable=W0212
for flag_key in dir(tf.app.flags.FLAGS):
delattr(tf.app.flags.FLAGS, flag_key)
#tf.app.flags.FLAGS = tf.app.flags._FlagValues()
tf.app.flags._global_parser = argparse.ArgumentParser()
解决上面两个问题,还会遇见第三个问题:缺少 python3-tk 这个包
报错信息如下:
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 36, in
import _tkinter
ImportError: No module named '_tkinter'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/tfdata/seq2seq/seq2seq/test/pipeline_test.py", line 163, in test_train_infer
os.path.join(BIN_FOLDER, "infer.py"))
File "/usr/lib/python3.5/imp.py", line 172, in load_source
module = _load(spec)
File "" , line 693, in _load
File "" , line 673, in _load_unlocked
File "" , line 665, in exec_module
File "" , line 222, in _call_with_frames_removed
File "/home/tfdata/seq2seq/bin/infer.py", line 32, in
from seq2seq import tasks, models
File "/home/tfdata/seq2seq/seq2seq/tasks/__init__.py", line 20, in
from seq2seq.tasks.dump_attention import DumpAttention
File "/home/tfdata/seq2seq/seq2seq/tasks/dump_attention.py", line 26, in
from matplotlib import pyplot as plt
File "/usr/local/lib/python3.5/dist-packages/matplotlib/pyplot.py", line 115, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib/python3.5/dist-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
[backend_name], 0)
File "/usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_tkagg.py", line 4, in
from . import tkagg # Paint image to Tk photo blitter extension.
File "/usr/local/lib/python3.5/dist-packages/matplotlib/backends/tkagg.py", line 5, in
from six.moves import tkinter as Tk
File "/usr/local/lib/python3.5/dist-packages/six.py", line 92, in __get__
result = self._resolve()
File "/usr/local/lib/python3.5/dist-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/local/lib/python3.5/dist-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/lib/python3.5/tkinter/__init__.py", line 38, in
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
换源教程:https://blog.csdn.net/cow66/article/details/80790451
sudo apt update
sudo apt install python3-tk -y
报错信息如下:
_tkinter.TclError: no display name and no $DISPLAY environment variable
这里只需要
echo "backend : Agg" >> $HOME/.config/matplotlib/matplotlibrc