nsfwjs and tfjs

nsfwjs and tfjs

月光魔力鸭

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


感谢支持!

赞赏支持
提交评论
评论信息 (请文明评论)
暂无评论,快来快来写想法...
推荐
写文章总会需要一些素材,但是好多素材都是收费或有限制的,还是我要求不高,在千库网看了下还不错,有各签到还送VIP,于是就有了想法....
在开发的时候,经常会有css js 文件的变更,然后部署后发现没有起到作用,最终发现是缓存的问题,如何来方便的解决
thinkjs框架使用ueditor记录。
前几天给朋友帮忙,想要一个一模一样的网站...自告奋勇去帮忙.. 结果发现之前一直没处理过类似的情况,虽然也写过爬虫,不过看了下网站,也不算麻烦。于是简单实现了这个自动抓站的功能,最终整理成为一个自动抓站的工具,能省很多的事情。
因为自己的记录笔记的应用是有道云,又想着把有道云跟自己的小网站联通起来,所以查找了有道云的,然后实现了nodejs版本的sdk.
docker镜像中的puppeteer安装
从豆瓣转到网易云后,发现了不少好听的歌曲,然鹅..当我想把这些歌拿下来扔车上听的时候发现竟然不允许下载..能听不能下?这不科学,作为一名程序猿,必然要迎难而上啊.
使用nodejs 连接mysql数据库还是很简单的,有现成的模块可以直接调用。下面介绍下 mysql 的调用