我想用TensorFlow C++ API讀取SavedModel。該模型是保存TF Python代碼和我的模型目錄結構如下:無法讀取保存的TensorFlow模型(找不到頭文件)
saved_model.pb
variables
├── variables.data-00000-of-00001
└── variables.index
我設法在Ubuntu與下面的代碼行成功地讀取它:
tensorflow::LoadSavedModel(sessOpt, runOpt, modelDir, {tensorflow::kSavedModelTagServe}, &model);
然而,當我建立Windows的相同代碼無法讀取模型。這是TensorFlow輸出:
2017-07-25 16:16:15.112591: I C:\all\lib\serving\tensorflow\tensorflow\cc\saved_model\loader.cc:155]
Restoring SavedModel bundle.
2017-07-25 16:16:15.126391: W op_kernel.cc:1192]
Data loss: Unable to read file (C:/model/1/variables/variables.index).
Perhaps the file is corrupt or was produced by a newer version of TensorFlow with format changes (failed to seek to header entry): corrupted compressed block contents
2017-07-25 16:16:15.127325: W op_kernel.cc:1192]
Data loss: Unable to read file (C:/model/1/variables/variables.index).
Perhaps the file is corrupt or was produced by a newer version of TensorFlow with format changes (failed to seek to header entry): corrupted compressed block contents
...
Same lines over and over, 40 times in total
...
2017-07-25 16:16:15.162735: I C:\all\lib\serving\tensorflow\tensorflow\cc\saved_model\loader.cc:284] Loading SavedModel: fail. Took 80176 microseconds.
TensorFlow的版本是完全一樣的,所以有與無的問題。發生在下面一行的構造函數BundleReader::BundleReader
的錯誤:
iter_->Seek(kHeaderEntryKey);
這是從文件系統當前會話恢復權重函數的所有部分。 TF基本上運行save/restore_all
操作來加載權重。有趣的是,它是在我的機器上有12個線程的線程池上完成的。由於這12個線程同時訪問variables.index
文件,我知道Windows不喜歡這樣的事情。
我試圖優化會話選項LoadSavedModel
功能:
sessionOpt.config.set_inter_op_parallelism_threads(1);
sessionOpt.config.set_intra_op_parallelism_threads(1);
sessionOpt.config.set_use_per_session_threads(1);
但不幸的是這似乎並沒有改變任何東西。
有沒有人有任何想法我可以嘗試什麼?我應該提交一個錯誤報告,或者我的代碼有問題嗎?