简体   繁体   English

转换 vgg16 时 SavedModel 文件不存在错误

[英]SavedModel file does not exist error while converting vgg16

I want to convert rcmalli_vggface_tf_vgg16.h5 pre-trained model to js format to use in a tensorflow-js project.我想将预训练的 rcmalli_vggface_tf_vgg16.h5 model转换为 js 格式以在 tensorflow-js 项目中使用。

to convert this file I tried different ways but yet I could not to solve the problem.转换这个文件我尝试了不同的方法,但我无法解决问题。

I'm using converters.convert_tf_saved_model method to load and then convert it to a json file.我正在使用converters.convert_tf_saved_model方法加载然后将其转换为 json 文件。

converters.convert_tf_saved_model('rcmalli_vggface_tf_vgg16.h5','web_model')

But every time following error is shown:但是每次显示以下错误:

SavedModel file does not exist at: rcmalli_vggface_tf_vgg16.h5

While I am sure the h5 file is next to the file that is running the program.虽然我确定 h5 文件位于运行程序的文件旁边。

I try full path address but same error occured.我尝试了完整路径地址,但发生了同样的错误。 I do not know what is problem我不知道是什么问题

You are converting a keras saved_model but the model is a keras layers_model because it is stored in h5 file.您正在转换 keras saved_model但 model 是 keras layers_model因为它存储在 h5 文件中。

I find this way the simplest to convert the model. And it did it in about 2 seconds.我发现这种转换 model 的方法最简单。它在大约 2 秒内完成。

  1. Go to TensorflowJS converter Github Go 到TensorflowJS 转换器 Github
  2. Follow installation instructions按照安装说明进行操作
  3. Download the model you point to from the Github repo .从 Github 存储库下载您指向的 model
    • The model is written in the HDF5 file format model写成HDF5文件格式
    • By the way, this is the oldest of the models, why not to download a new one?顺便说一下,这是最旧的模型,为什么不下载一个新的呢?
    • Also, this is a huge model, unless runs on the server it is of no use for a browser (produces 50 shard files of 4MB.)此外,这是一个巨大的 model,除非在服务器上运行它对浏览器毫无用处(产生 50 个 4MB 的碎片文件。)
  4. Perform the conversion*执行转换*
tensorflowjs_converter --input_format=keras rcmalli_vggface_tf_vgg16.h5 ./converted
  1. The output will then be a layers model, and this has to be loaded with the tf.loadLayers API.然后 output 将成为图层 model,并且必须使用tf.loadLayers API 加载它。
  2. For example, use const model = await tf.loadGraphModel('path/to/model.json');例如,使用const model = await tf.loadGraphModel('path/to/model.json');

Note*: ./converted is the output directory, be sure not to overwrite your own stuff.注意*:./converted是./converted目录,一定不要覆盖你自己的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM