【问题标题】:How to export a custom model from TensorflowJS to Tensorflow Python如何将自定义模型从 TensorflowJS 导出到 Tensorflow Python
【发布时间】:2021-11-23 10:51:24
【问题描述】:

我正在尝试将使用 TensorflowJS 制作的自定义模型导出到 Tensorflow Python。主要问题是 TF.JS 保存了两个工件:"model-js.json" 和 "model-js.weights.bin"

我尝试导入 JSON:

    with open('model-js/model-js.json') as json_file:
        json_config = str(json.loads(json_file.read())["modelTopology"])
    
    json_config=json_config.replace("'","\"")

    new_model = tf.keras.models.model_from_json(json_config)

但我收到下一个错误:

~\anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
    353             obj, end = self.scan_once(s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

所以,Json 文件中的第 103 行是“Null”中的“N”:

    "config": {
        "batch_input_shape": [
            null,
            128,
            128,
            1
         ],
         "dtype": "float32",
         "sparse": false,
         "name": "conv2d_input"
    }

当您将 JSON 导入到 python 时,稍后将 "Null" 更改为 "None"。

为什么 TensorflowJS 模型工件不适合 Python Tensorflow?

另一件事是我不知道如何在 .bin 文件中导入权重。还有其他方法可以做到这一点吗?或者还有其他类型的文件可以从TF.JS导出?

提前致谢

【问题讨论】:

    标签: javascript python tensorflow keras tensorflow.js


    【解决方案1】:

    格式完全不同,永远不会那样工作

    并且没有官方方法可以将TFJS Graph Model转换为TF Saved Model,因为转换是单向的,方向相反

    使用 3rd 方转换工具可能会有一些运气,请查看https://github.com/patlevin/tfjs-to-tf

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-15
      • 1970-01-01
      • 2018-10-08
      • 2020-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多