nsfwjs and tfjs

nsfwjs and tfjs

月光魔力鸭

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


感谢支持!

赞赏支持
提交评论
评论信息 (请文明评论)
暂无评论,快来快来写想法...
推荐
通过imap 来接收邮箱新邮件,类似客户端系列,不过比较简单的,目前只有新邮件,后续也可以通过这个来做一个自己的邮件客户端。
最近有客户提出了这么一个需求:微信dat文件在解码后的图片无法按照时间进行排序。 是的,解码后的文件的时间都是解码的时间,由于软件比较多,当时没做自动更新,所以在这里做一个小工具,可以将对应的解码后的图片的时间修改为微信dat文件对应的时间
在日常开发中,经常会频繁的做一些重复性的操作,作为一名程序员,解放双手的时刻到了
因为自己的记录笔记的应用是有道云,又想着把有道云跟自己的小网站联通起来,所以查找了有道云的,然后实现了nodejs版本的sdk.
碰到个小需求,本来实现挺简单的,用的electron,开发模式下各种顺畅...半个小时就搞定了,结果倒在了electron打包上..这个坑我应该跳进来了好多次了..
从豆瓣转到网易云后,发现了不少好听的歌曲,然鹅..当我想把这些歌拿下来扔车上听的时候发现竟然不允许下载..能听不能下?这不科学,作为一名程序猿,必然要迎难而上啊.
介绍几个日常开发中常用的几个小工具: anywhere / anywhere-auth / watchlessc / changeext
在开发的时候,经常会有css js 文件的变更,然后部署后发现没有起到作用,最终发现是缓存的问题,如何来方便的解决