如何从tensorflow.js下载模型和权重 [英] How to download models and weights from tensorflow.js

查看:210
本文介绍了如何从tensorflow.js下载模型和权重的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试下载一个包含权重的预训练tensorflow.js模型,在张量流的标准版本中在python中脱机使用,作为项​​目的一部分,不是在任何早期阶段,所以切换到tensorflow .js不可能。
但我不知道如何下载这些模型以及是否有必要转换到模型。

I'm trying to download a pretrained tensorflow.js model including weights, to be used offline in python in the standard version of tensorflow as part of a project that is not on an early stage by any means, so switching to tensorflow.js is not a possibility. But I cant just figure out how to download those models and if its necessary to to do some conversion to the model.

我知道在javascript中我可以访问模型并通过调用它们来使用它们,如
,但如果是这样的话,我如何实际获取.ckpt文件或冻结模型?

I'm aware that in javascript I can access the models and use them by calling them like this but how do I actually get the .ckpt files or the model frozen if thats the case?

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.3"></script>

<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/posenet@0.2.3"></script>

我的最终目标是获取冻结的模型文件,并获得与正常情况相同的输出tensorflow的版本。
此外,这将在离线环境中使用,因此任何在线参考都没有用。

My final objective is to get the frozen model files, and get the outputs like is done in the normal version of tensorflow. Also this will be used in an offline environment, so any online reference would not be useful.

感谢您的回复

推荐答案

可以通过调用模型的方法 save 来保存模型拓扑及其权重。

It is possible to save the model topology and its weights by calling the method save of the model.

const model = tf.sequential();
model.add(tf.layers.dense(
     {units: 1, inputShape: [10], activation: 'sigmoid'}));
const saveResult = await model.save('downloads://mymodel'));
// This will trigger downloading of two files:
//   'mymodel.json' and 'mymodel.weights.bin'.
console.log(saveResult);

根据保存模型及其权重的位置,有不同的方案字符串(localStorage,IndexDB ,. ..)。 doc

There are different scheme strings depending on where to save the model and its weights (localStorage, IndexDB, ...). doc

这篇关于如何从tensorflow.js下载模型和权重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆