Closed caoyonghao closed 3 years ago
正在重新实现预测,可以看下这个 PR:#816
简单示例
const tf = require('@tensorflow/tfjs-node');
const { Image } = require('@pipcook/datacook');
(async () => {
const model = await tf.loadLayersModel(
'file:///pipcook/example/pipelines/20210804172628/model/model.json' // 模型本地位置
);
model.summary(); // 查看模型概要信息
const img = (
await Image.read(
'/pipcook/example/pipelines/20210804172628/data/test/0a3e8b60-1cb9-11ea-a3c0-69b27346a20f-screenshot.png'
)
)
.resize(416, 416) // 根据概要输入来修改
.toTensor();
// 转成四维
const res = model.predict(img.reshape([1, ...img.shape]));
console.log(res.toString());
})();
参考demo运行成功
简单示例
const tf = require('@tensorflow/tfjs-node'); const { Image } = require('@pipcook/datacook'); (async () => { const model = await tf.loadLayersModel( 'file:///pipcook/example/pipelines/20210804172628/model/model.json' // 模型本地位置 ); model.summary(); // 查看模型概要信息 const img = ( await Image.read( '/pipcook/example/pipelines/20210804172628/data/test/0a3e8b60-1cb9-11ea-a3c0-69b27346a20f-screenshot.png' ) ) .resize(416, 416) // 根据概要输入来修改 .toTensor(); // 转成四维 const res = model.predict(img.reshape([1, ...img.shape])); console.log(res.toString()); })();
使用文本分类训练出了一个model.json。怎么运用model进行判断 ? 使用@tensorflow/tfjs 的loadLayersModel时报错
Error: The JSON from HTTP path http://127.0.0.1:8080/textClassification/model/model.json contains neither model topology or manifest for weights.
@weimingxinas 参考一下text-classification-bayes训练模型的源码,注意输入参数的处理和predict函数对预测结构的处理
按照官网进行了训练,发现v2版本没有提到怎么运用model进行判断,类似v1的这个