nsfwjs and tfjs

nsfwjs and tfjs

月光魔力鸭

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


感谢支持!

赞赏支持
提交评论
评论信息 (请文明评论)
暂无评论,快来快来写想法...
推荐
当我们做爬虫或其他的一些应用的时候,如果需要一些短信验证,但是又没有那么多手机号,又不能放人在那里一直输入的时候?怎么办?
最近家里正在装修,实在是不知道怎么做,之前看好好住APP上有不少设计的图,部分还挺好看。。就去看了下有没有WEB端,结果还真有,就有了下文,我抓了几万张图片,然后根据关键字进行分类,从里面找心仪的设计。
开始入手webpack ,直接看的官方文档和demo,对于自动刷新这部分还是希望通过express 加载插件来控制,但是文档没有提供,经过参考github上其他高玩的套路,最终整理了一个基础的配置版本。
发布自己的nodejs应用后,需要进行管理,目前一般都pm2来进行管理,这里记录下常用的命令。
通过nodejs来进行爬取页面的内容,这里简单试试做个小任务..
使用nodejs 连接mysql数据库还是很简单的,有现成的模块可以直接调用。下面介绍下 mysql 的调用
做了一个阿里云开发者社区自动签到,想着能积攒一些换点啥东西,放在服务器上出现了各种错误。
最近看到知乎上一话题:微信公众号文章里的视频怎么下载?。看还是有很多人推荐啥工具啊,很是捉急,当然本次的主题也是通过程序来获取内容,但是目前来说仅仅是娱乐吧。