tensorflow / nmt

TensorFlow Neural Machine Translation Tutorial
Apache License 2.0
6.37k stars 1.96k forks source link

hardcode path in saved model #283

Open ttpro1995 opened 6 years ago

ttpro1995 commented 6 years ago

In save model, there is hard code directory. So, when I move to new PC on other folder, I cannot load model

(tf3) ➜  nmt git:(master) ✗ python -m nmt.nmt \
--out_dir=/data/text_data/test/nmt/vi-vi/nmt_attention_model_home \
--inference_input_file=/data/text_data/test/nmt/vi-vi/test.src \
--inference_output_file=/data/text_data/test/nmt/vi-vi/output_home
/home/thaithien/miniconda3/envs/tf3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
# Job id 0
# Loading hparams from /data/text_data/test/nmt/vi-vi/nmt_attention_model_home/hparams
  saving hparams to /data/text_data/test/nmt/vi-vi/nmt_attention_model_home/hparams
  saving hparams to /home/thaithien/workplace/data/test/nmt/vi-vi/nmt_attention_model_home/best_bleu/hparams
Traceback (most recent call last):
  File "/home/thaithien/miniconda3/envs/tf3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/thaithien/miniconda3/envs/tf3/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/thaithien/workplace/experiment/nmt/nmt/nmt.py", line 605, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/home/thaithien/miniconda3/envs/tf3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "/home/thaithien/workplace/experiment/nmt/nmt/nmt.py", line 598, in main
    run_main(FLAGS, default_hparams, train_fn, inference_fn)
  File "/home/thaithien/workplace/experiment/nmt/nmt/nmt.py", line 562, in run_main
    out_dir, default_hparams, flags.hparams_path, save_hparams=(jobid == 0))
  File "/home/thaithien/workplace/experiment/nmt/nmt/nmt.py", line 535, in create_or_load_hparams
    utils.save_hparams(getattr(hparams, "best_" + metric + "_dir"), hparams)
  File "/home/thaithien/workplace/experiment/nmt/nmt/utils/misc_utils.py", line 119, in save_hparams
    f.write(hparams.to_json())
  File "/home/thaithien/miniconda3/envs/tf3/lib/python3.6/codecs.py", line 377, in write
    self.stream.write(data)
  File "/home/thaithien/miniconda3/envs/tf3/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py", line 103, in write
    self._prewrite_check()
  File "/home/thaithien/miniconda3/envs/tf3/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py", line 89, in _prewrite_check
    compat.as_bytes(self.__name), compat.as_bytes(self.__mode), status)
  File "/home/thaithien/miniconda3/envs/tf3/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 516, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: /home/thaithien/workplace/data/test/nmt/vi-vi/nmt_attention_model_home/best_bleu/hparams; No such file or directory

/home/thaithien/workplace/data/test/nmt/vi-vi/nmt_attention_model_home/best_bleu/hparams is directory in another PC

ttpro1995 commented 6 years ago

temporary fix: Use find-and-replace to replace all path in your model file