ilovin / lstm_ctc_ocr

Use CTC + tensorflow to OCR
https://ilovin.github.io/2017-04-06/tensorflow-lstm-ctc-ocr/
354 stars 140 forks source link

got AttributeError when training #37

Closed ugtony closed 6 years ago

ugtony commented 6 years ago

Hi, I run the program with python3.5 using the command:

python ./lstm/train_net.py --network=LSTM_train --cfg=./lstm/lstm.yml --restore=0

and got the following error

  File "./lstm/train_net.py", line 89, in <module>
    restore=bool(int(args.restore)))
  File "./lstm/..\lib\lstm\train.py", line 177, in train_net
    sw.train_model(sess, max_iters, restore=restore)
  File "./lstm/..\lib\lstm\train.py", line 122, in train_model
    img_Batch,targets,time_step_Batch = next(train_gen)
  File "./lstm/..\lib\lstm\utils\gen.py", line 120, in get_batch
    enqueuer.start(max_queue_size=24, workers=num_workers)
  File "./lstm/..\lib\utils\data_util.py", line 81, in start
    thread.start()
  File "C:\Users\ugton\Anaconda3\envs\py3.5\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Users\ugton\Anaconda3\envs\py3.5\lib\multiprocessing\context.py", line 212, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Users\ugton\Anaconda3\envs\py3.5\lib\multiprocessing\context.py", line 313, in _Popen
    return Popen(process_obj)
  File "C:\Users\ugton\Anaconda3\envs\py3.5\lib\multiprocessing\popen_spawn_win32.py", line 66, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\Users\ugton\Anaconda3\envs\py3.5\lib\multiprocessing\reduction.py", line 59, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'GeneratorEnqueuer.start.<locals>.data_generator_task'

(py3.5) D:\git\lstm_ctc_ocr-beta>Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\ugton\Anaconda3\envs\py3.5\lib\multiprocessing\spawn.py", line 106, in spawn_main
    exitcode = _main(fd)
  File "C:\Users\ugton\Anaconda3\envs\py3.5\lib\multiprocessing\spawn.py", line 116, in _main
    self = pickle.load(from_parent)
EOFError: Ran out of input

It seems like the data_generator_task function cannot be pickled because it is not defined at the top level of a module (https://docs.python.org/3/library/pickle.html#what-can-be-pickled-and-unpickled), but I don't know how to fix it. Does anyone encounter the same error?

BTW, it runs fine when use_multiprocessing is set to False.

ilovin commented 6 years ago

"img_Batch,targets,time_step_Batch = next(train_gen)" I did not wrote the code, the warpctc requires four inputs

ugtony commented 6 years ago

Yes, I've changed the codes a little bit to train the model with tf.nn.ctc_loss. I'll check that later, thanks for the hint. I was also wondering what Python version did you run you codes with? 2.x or 3.x? Thanks.

ilovin commented 6 years ago

README: python3