tf.setBackend makes node-tfjs ignore the bindings
See original GitHub issueTensorFlow.js version
tfjs-node 0.1.18
Browser version
node 10.5.0
Describe the problem or feature request
tf.setBackend(‘cpu’, false); makes tfjs ignore the bindings
Code to reproduce the bug / link to feature request
global.fetch = require('node-fetch');
const fs = require('fs'),
PNG = require('pngjs').PNG;
const tf = require('@tensorflow/tfjs');
require('@tensorflow/tfjs-node');
async function run(opts)
{
const URI = 'http://localhost/pix2pix/models/facades_A2B/tfjs/';
const MODEL_URL = URI + 'tensorflowjs_model.pb';
const WEIGHTS_URL = URI + 'weights_manifest.json';
const model = await tf.loadFrozenModel(MODEL_URL, WEIGHTS_URL);
console.log('model loaded');
try
{
let img = 'C:/test.png';
const cc = await fromPNG(img);
const input = preprocess( cc.toFloat() ) ;
console.log('input ready', input);
tf.setBackend('cpu', false); //if ran out of memory can test in on CPU
//THIS LINE IS GOING TO MAKE TFJS IGNORE THE BINDING
let ts = new Date().getTime();
const X = model.execute( {"input": input} );
console.log( new Date().getTime() - ts );
console.log('X!!', X);
const output = postprocess( X);
toPNG(output, 'C:/out.png');
}catch(e)
{
console.error(e);
}
//model.dispose();
function preprocess(x)
{
return tf.tidy(()=>
{
// Normalize the image. (0, 255)->(-1, 1)
const offset = tf.scalar(127.5);
const norm = x.div(offset).sub( tf.scalar(1) );
//[3,W,H] -> [1, 3, W, H]
const batched = norm.expandDims(0);
return batched;
});
}
function postprocess(x)
{
return tf.tidy(()=>
{
const offset = tf.scalar(127.5);
const denorm = x.mul(offset).add(offset).clipByValue(0, 255).toInt();
//[1, 3, W, H] -> [3,W,H]
const reduced = denorm.squeeze();
return reduced;
});
}
}
run();
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Platform and environment | TensorFlow.js
In Node.js, TensorFlow.js supports binding directly to the TensorFlow API or running with the slower vanilla CPU implementations. Environments.
Read more >WebGL and Node.js: setBackend('webgl') error - Google Groups
In Node.js there are some WebGL bindings, but I was aware that TF team was working to WASM / WebAssembly for that.
Read more >Don't Block the Event Loop (or the Worker Pool) - Node.js
This callback executes synchronously, and may register asynchronous requests to continue processing after it completes. The callbacks for these asynchronous ...
Read more >Node.js v19.3.0 Documentation
Warning: Don't ignore errors! Additions to Error objects; Implicit binding; Explicit binding; domain.create(); Class: Domain.
Read more >Process | Node.js v19.3.0 Documentation
The process.abort() method causes the Node.js process to exit immediately and ... If warning is passed as an Error object, the options argument...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We’ve been evaluating a device-selector API and the design that we’d like to surface internally. These plans are still initial stage and we can share them when we’re ready to cut over for this work.
As for Node.js - V7 has been deprecated for a while, current LTS support is V8.x.
Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!