nsfwjs and tfjs

nsfwjs and tfjs

月光魔力鸭

2021-11-24 17:00 阅读 863 喜欢 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


感谢支持!

赞赏支持
提交评论
评论信息 (请文明评论)
暂无评论,快来快来写想法...
推荐
docker镜像中的puppeteer安装
从豆瓣转到网易云后,发现了不少好听的歌曲,然鹅..当我想把这些歌拿下来扔车上听的时候发现竟然不允许下载..能听不能下?这不科学,作为一名程序猿,必然要迎难而上啊.
thinkjs框架使用ueditor记录。
最近由于系统需要一些数据进行测试,但是正常的流程都是下载pdf ,打印pdf,然后通过涂写答题卡,将涂写的扫描上传..太麻烦了,想做成简单点,通过程序直接生成..卡在了pdf转图片上,今天抽空找了下库,通过gm可以将pdf转为图片,起码第一步已经实现了,后边的涂学号之前已经做过了。
在开发的时候,经常会有css js 文件的变更,然后部署后发现没有起到作用,最终发现是缓存的问题,如何来方便的解决
获取文件夹内所有的文件。支持递归获取、异步或同步、过滤、返回信息处理。
在日常开发中,经常会频繁的做一些重复性的操作,作为一名程序员,解放双手的时刻到了
使用nodejs 连接mysql数据库还是很简单的,有现成的模块可以直接调用。下面介绍下 mysql 的调用