Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not work local model load #792

Open
danekbiglike opened this issue Oct 25, 2023 · 4 comments
Open

Not work local model load #792

danekbiglike opened this issue Oct 25, 2023 · 4 comments

Comments

@danekbiglike
Copy link

My code:

const axios = require('axios');
const tf = require('@tensorflow/tfjs-node');
const nsfwjs = require('nsfwjs');

// Загрузка модели из папки на вашем сервере
const url = "file://" + __dirname + "/nsfwjs/model.json";

async function classifyImage(imageUrl) {
    const pic = await axios.get(imageUrl, {
        responseType: 'arraybuffer',
    });

    const model = await nsfwjs.load(url, { size: 299 });

    // Преобразование изображения в формат tf.tensor3d
    const image = await tf.node.decodeImage(new Uint8Array(pic.data), 3);

    const predictions = await model.classify(image);

    image.dispose(); // Освобождение памяти

    return predictions;
}

My logs:

...
The kernel 'UnsortedSegmentSum' for backend 'webgl' is already registered
The kernel 'ZerosLike' for backend 'webgl' is already registered
node:internal/deps/undici/undici:11600
    Error.captureStackTrace(err, this);
          ^

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11600:11) {
  cause: Error: not implemented... yet...
      at makeNetworkError (node:internal/deps/undici/undici:6911:35)
      at schemeFetch (node:internal/deps/undici/undici:11050:18)
      at node:internal/deps/undici/undici:10930:26
      at mainFetch (node:internal/deps/undici/undici:10947:11)
      at fetching (node:internal/deps/undici/undici:10904:7)
      at fetch2 (node:internal/deps/undici/undici:10782:20)
      at Object.fetch (node:internal/deps/undici/undici:11598:18)
      at fetch (node:internal/process/pre_execution:274:25)
      at PlatformNode.fetch (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:7425:33)
      at HTTPRequest.<anonymous> (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:8289:55)
      at step (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:125:27)
      at Object.next (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:74:53)
      at C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:67:71
      at new Promise (<anonymous>)
      at __awaiter (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:53:12)
      at HTTPRequest.load (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:8284:16)
      at GraphModel.load (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-converter\dist\tf-converter.node.js:30371:39)
      at Object.<anonymous> (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-converter\dist\tf-converter.node.js:30697:48)
      at step (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-converter\dist\tf-converter.node.js:176:27)
      at Object.next (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-converter\dist\tf-converter.node.js:125:53)
      at C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-converter\dist\tf-converter.node.js:118:71
      at new Promise (<anonymous>)
}

Node.js v20.7.0

@danekbiglike
Copy link
Author

Even the example code doesn't work.

const axios = require('axios') //you can use any http client
const tf = require('@tensorflow/tfjs-node')
const nsfw = require('nsfwjs')
async function fn() {
    const pic = await axios.get('xxx.img', {
        responseType: 'arraybuffer',
    })
    const url = "file://" + __dirname + "/min_nsfwjs/model.json";
    const model = await nsfw.load(url, { size: 299 });
    // 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.data,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()
The kernel 'Transpose' for backend 'webgl' is already registered
The kernel 'Unique' for backend 'webgl' is already registered
The kernel 'Unpack' for backend 'webgl' is already registered
The kernel 'UnsortedSegmentSum' for backend 'webgl' is already registered
The kernel 'ZerosLike' for backend 'webgl' is already registered
node:internal/deps/undici/undici:11600
    Error.captureStackTrace(err, this);
          ^

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11600:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: Error: not implemented... yet...
      at makeNetworkError (node:internal/deps/undici/undici:6911:35)
      at schemeFetch (node:internal/deps/undici/undici:11050:18)
      at node:internal/deps/undici/undici:10930:26
      at mainFetch (node:internal/deps/undici/undici:10947:11)
      at fetching (node:internal/deps/undici/undici:10904:7)
      at fetch2 (node:internal/deps/undici/undici:10782:20)
      at Object.fetch (node:internal/deps/undici/undici:11598:18)
      at fetch (node:internal/process/pre_execution:274:25)
      at PlatformNode.fetch (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:7425:33)
      at HTTPRequest.<anonymous> (C:\Users\remot\Documents\resenderbottg\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:8289:55)
}

Node.js v20.7.0

@hubsMIT1
Copy link

hubsMIT1 commented Nov 6, 2023

@danekbiglike, can you help me to install thetensorflow/tfjs-node?
npm i tensorflow/tfjs-node couldn't find.

@MonarthS
Copy link

MonarthS commented Dec 1, 2023

@hubsMIT1, it's npm i @tensorflow/tfjs-node

@motikolorado
Copy link

Did anyone fix this yet??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants