我的解决方法如下。检查
./tf文件夹可以清楚地看到,
model_to_estimator将必要文件存储在
keras子文件夹中的调用,同时
export_model希望这些文件
./tf直接位于文件夹中,因为这是我们为
model_dir参数指定的路径:
$ tree ./tf./tf└── keras ├── checkpoint ├── keras_model.ckpt.data-00000-of-00001 ├── keras_model.ckpt.index └── keras_model.ckpt.meta1 directory, 4 files
一种简单的解决方法是将这些文件上移一个文件夹。这可以使用Python完成:
import osimport shutilfrom pathlib import Pathdef up_one_dir(path): """Move all files in path up one folder, and delete the empty folder """ parent_dir = str(Path(path).parents[0]) for f in os.listdir(path): shutil.move(os.path.join(path, f), parent_dir) shutil.rmtree(path)up_one_dir('./tf/keras')这将使
model_dir目录如下所示:
$ tree ./tf./tf├── checkpoint├── keras_model.ckpt.data-00000-of-00001├── keras_model.ckpt.index└── keras_model.ckpt.meta0 directories, 4 files
在
model_to_estimator和
export_savedmodel调用之间进行此操作可以根据需要导出模型:
export_path = './export'estimator.export_savedmodel( export_path, serving_input_receiver_fn=serving_input_receiver_fn())
INFO:tensorflow:SavedModel写入:./export/temp-b‘1549796240’/saved_model.pb



