nsfwjs and tfjs

nsfwjs and tfjs

月光魔力鸭

2021-11-24 17:00 阅读 875 喜欢 2

相关资料

环境准备

由于windows 上没有编译通过,直接在轻量腾讯云上做的测试

yum -y update gcc
yum -y install gcc-c++
npm i @tensorflow/tfjs-node nsfwjs axios --save

代码

参考 nsfwjsNodejs.App

/**
 * nsfw.js 测试
 */

const axios = require('axios') //you can use any http client
const tf = require('@tensorflow/tfjs-node')
const nsfw = require('nsfwjs');
let path = require('path');
let fs = require('fs');

async function fn () {
  // const pic = await axios.get(`img-link`, {
  //   responseType: 'arraybuffer',
  // });
  let pic = fs.readFileSync('./test.png');
  // console.log(pic);
  console.log(path.resolve('./model/model.json'));
  const model = await nsfw.load('file://./model/',{size : 299}) // To load a local model, nsfw.load('file://./path/to/model/')
  // Image must be in tf.tensor3d format
  // you can convert image to tf.tensor3d with tf.node.decodeImage(Uint8Array,channels)
  const image = await tf.node.decodeImage(pic, 3)
  const predictions = await model.classify(image)
  image.dispose() // Tensor memory must be managed explicitly (it is not sufficient to let a tf.Tensor go out of scope for its memory to be released).
  console.log(predictions)
}
fn()

做了两个测试,一类网络图片,一类本地图片。

结果

得到结果

expected input_1 to have shape [null,299,299,3] but got array with shape [1,224,224,3].

load 内 增加一个 size .

const model = await nsfw.load('file://./model/',{size : 299}) 

转载请注明出处: https://chrunlee.cn/article/tf-nsfw-node.html


感谢支持!

赞赏支持
提交评论
评论信息 (请文明评论)
暂无评论,快来快来写想法...
推荐
最近由于系统需要一些数据进行测试,但是正常的流程都是下载pdf ,打印pdf,然后通过涂写答题卡,将涂写的扫描上传..太麻烦了,想做成简单点,通过程序直接生成..卡在了pdf转图片上,今天抽空找了下库,通过gm可以将pdf转为图片,起码第一步已经实现了,后边的涂学号之前已经做过了。
前段时间帮朋友下歌放在车上听..结果好多都是ncm格式,伤心 ,搜索了下发现基本上这格式解密有好多昂,可惜UI我都不太想要..决定抄一下,自己做一个。 这里先记录下核心代码,回头补充个UI 做个小程序。
前段时间做了个微信小程序反编译的小东西,不过因为功能不全,没加分包处理,正好处理下加上,又考虑到后续可能的更新情况,准备上手增加下更新功能。
通过pm2来实现nodejs应用的集群,不过我之前没做session共享,导致.. 登录不上啊 啊啊啊,无奈,又重新对redis进行了集成。
产品版本更新的时候经常会有一些数据库的差异,如果版本管理好的话,一步一步升级即可.. 但是如果好久没更新的话,还是有很多不确定的,只能挨着比对表和字段。比对了一次就烦了,写了这么一个工具,查询差异表和字段并给出sql语句。
docker镜像中的puppeteer安装
经常会遇到需要系统重启后自动执行的一些任务,在windows 上可以将对应的程序打包成service 然后自启动即可