<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>NSFWJS 鉴黄</title> <!-- TensorFlow.js --> <script src="https://ss.netnr.com/@tensorflow/tfjs@2.8.6/dist/tf.min.js"></script> <!-- Load the NSFWJS library --> <script src="https://ss.netnr.com/nsfwjs@2.4.2/dist/nsfwjs.min.js"></script> </head> <body> <input type="file" onchange="showImg()" accept="image/*"> <button onclick="judge()">鉴别</button><br> <img id="myImg" src="/favicon.ico" alt="Thumb preview..."> </body> </html>
img { max-width: 300px; max-height: 300px; }
function judge() { const img = document.getElementById('myImg') console.log("Loading ...") nsfwjs.load('https://ss.netnr.com/@clicks/nsfwjs@3.0.3/example/nsfw_demo/public/quant_nsfw_mobilenet/').then(function (model) { console.log("Ready ...") model.classify(img).then(function (predictions) { console.table(predictions) }) }) } function showImg() { var demoImage = document.querySelector('img'); var file = document.querySelector('input[type=file]').files[0]; var reader = new FileReader(); reader.onload = function () { demoImage.src = reader.result; } reader.readAsDataURL(file); }