TypeError:尝试训练Keras模型时无法腌制_thread.lock对象

时间:2019-01-31 04:38:21

标签: python numpy keras byte pickle

我正在尝试训练LipNet模型,并且生成器似乎可以很好地检测数据。但是,当泡菜加载火车,验证和对齐(标签)列表时,就会出现问题。

with open (self.get_cache_path(), 'rb') as fp:
   self.train_list, self.val_list, self.align_hash = pickle.load(fp)

这是我得到的错误:

Epoch 1/5000
Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\threading.py", line 914, in _bootstrap_inner
    self.run()
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\utils\data_utils.py", line 666, in _run
    with closing(self.executor_fn(_SHARED_SEQUENCES)) as executor:
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\utils\data_utils.py", line 661, in <lambda>
    initargs=(seqs, self.random_seed))
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\context.py", line 118, in Pool
    context=self.get_context())
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\pool.py", line 168, in __init__
    self._repopulate_pool()
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\pool.py", line 233, in _repopulate_pool
    w.start()
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\context.py", line 313, in _Popen
    return Popen(process_obj)
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\popen_spawn_win32.py", line 66, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\reduction.py", line 59, in dump
    ForkingPickler(file, protocol).dump(obj)
TypeError: can't pickle _thread.lock objects

还有

Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\threading.py", line 914, in _bootstrap_inner
    self.run()
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\utils\data_utils.py", line 666, in _run
    with closing(self.executor_fn(_SHARED_SEQUENCES)) as executor:
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\site-packages\keras\utils\data_utils.py", line 661, in <lambda>
    initargs=(seqs, self.random_seed))
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\context.py", line 118, in Pool
    context=self.get_context())
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\pool.py", line 168, in __init__
    self._repopulate_pool()
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\pool.py", line 233, in _repopulate_pool
    w.start()
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\context.py", line 313, in _Popen
    return Popen(process_obj)
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\popen_spawn_win32.py", line 66, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\reduction.py", line 59, in dump
    ForkingPickler(file, protocol).dump(obj)
TypeError: can't pickle _thread.lock objects

对我来说,第三个错误似乎与另外两个相似:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\spawn.py", line 106, in spawn_main
    exitcode = _main(fd)
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\spawn.py", line 116, in _main
    self = pickle.load(from_parent)
EOFError: Ran out of input
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\spawn.py", line 106, in spawn_main
    exitcode = _main(fd)
  File "C:\Users\Fahim\AppData\Local\Programs\Python\Python35\lib\multiprocessing\spawn.py", line 116, in _main
    self = pickle.load(from_parent)
EOFError: Ran out of input

我查看了Stack Overflow,并尽我所能实现了我所理解的内容。例如,我尝试传递encoding = "ASCII""latin1"进行编码。另外,我将其粘贴在代码之上:

#found at https://stackoverflow.com/questions/44855603/typeerror-cant-pickle-thread-lock-objects-in-seq2seq
import tensorflow as tf
setattr(tf.contrib.rnn.GRUCell, '__deepcopy__', lambda self, _: self)
setattr(tf.contrib.rnn.BasicLSTMCell, '__deepcopy__', lambda self, _: self)
setattr(tf.contrib.rnn.MultiRNNCell, '__deepcopy__', lambda self, _: self)

尽管很幼稚,但我尝试使用常规文本文件而不是字节流,即使尝试没有成功。我进行的许多其他更改均未对结果产生任何重大影响。

可以在模型的herehere is the training script中找到生成器酸洗。

我一直在尝试解决这个问题,并最终对模型进行了几个月的训练,谢谢您的帮助。

0 个答案:

没有答案