tensorflow.js

How to get a tensor from an image

老子叫甜甜 提交于 2019-12-24 16:18:07
问题 I have an image and I would like to get the tensor from it. Some of the images are already on the frontend server be whereas others will be served by the server 回答1: To do that, one needs to use fromPixels In case the image is already displayed in an html page You can consider doing a querySelector to get the image first and then you can use fromPixels html <img id="my-image" src="mydata.jpg"> js const image = document.querySelector("#my-image") const t = tf.fromPixels(image) If the image is

How to use the classWeight option of model.fit in Tensorflow.js?

霸气de小男生 提交于 2019-12-24 11:30:14
问题 In my training set, my classes are not represented equally. Therefore, I'm trying to use the classWeight option of the model.fit function. Quote from the docs: classWeight ({[classIndex: string]: number}) Optional dictionary mapping class indices (integers) to a weight (float) to apply to the model's loss for the samples from this class during training. This can be useful to tell the model to "pay more attention" to samples from an under-represented class. So this seems to be exactly what I'm

TensorFlow.js Resize 3D Tensor

不羁的心 提交于 2019-12-24 09:26:27
问题 I have a 3D tensor with the the following dimensions : Width x Height x Depth. I need to resize variable sized volumes to a specific shape say 256 x 256 x 256. Unfortunately, in TensorFlow.js the set of methods they have for resizing such as tf.image.resizeBilinear & tf.image.resizeNearestNeighbor only work for 2D images. Is there a workaround to get these methods to work in 3D space? 回答1: To resize a tensor, one can use tf.reshape if the input size matches the output size const x = tf.tensor

Training with an input size of 1 causes NaN in subsequent predictions

倖福魔咒の 提交于 2019-12-24 08:04:07
问题 I'm following the MNIST tutorial here for recognizing handwritten characters. I'm able to load and recognize handwritten digits without issue, but now I want to train the model again on new images (specifically one at a time). For some reason, when I choose a training size equal to 1, all my predictions become NaN. If I pick a value >=2, it works fine. Train Function: async function train(model, data) { const TRAIN_DATA_SIZE = 1; // WHEN THIS IS 1, CAUSES PREDICT TO OUTPUT NaN const [trainXs,

How to train a custom Object detector from scratch in tensorflow.js?

蹲街弑〆低调 提交于 2019-12-24 06:11:30
问题 I followed multiple example, to train a custom object detector in TensorflowJS . The main problem I am facing every where it is using pretrained model. Pretrained models are fine for general use cases, but custom scenario it fails. For example, take this this is example form official Tensorflowjs examples, here it is using mobilenet, and mobilenet and mobilenet has image size restriction 224x224 which defeats all the purpose, because my images are big and also not of same ratio so resizing is

Cannot import @tensorflow/tfjs-node in nodejs

落爺英雄遲暮 提交于 2019-12-24 04:49:07
问题 Cannot import @tensorflow/tfjs-node into my program. I was trying to import it as follows: const tf = require('@tensorflow/tfjs-node') And received an error as follows: internal/modules/cjs/loader.js:638 throw err; ^ Error: Cannot find module '/home/nama/working/Canvas-WEB/node_modules/@tensorflow/tfjs-node/lib/napi-v4/tfjs_binding.node' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module

TFJS-Node: How to load model from url?

余生长醉 提交于 2019-12-23 14:55:52
问题 I want to load a model from an url in node. This works in the broser: mobileNet = await tf.loadModel('https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json'); But not in node Error: browserHTTPRequest is not supported outside the web browser without a fetch polyfill I can do get request with node like this: const https = require('https'); https.get(mobileNetUrl, (res) => { ... }); The get request returns an Object with a modelTopology and a weightManifest. How could

How to download models and weights from tensorflow.js

别来无恙 提交于 2019-12-23 02:49:08
问题 I'm trying to download a pretrained tensorflow.js model including weights, to be used offline in python in the standard version of tensorflow as part of a project that is not on an early stage by any means, so switching to tensorflow.js is not a possibility. But I cant just figure out how to download those models and if its necessary to to do some conversion to the model. I'm aware that in javascript I can access the models and use them by calling them like this but how do I actually get the

print all layers output

倾然丶 夕夏残阳落幕 提交于 2019-12-20 06:01:02
问题 Given the following model, how to print all layers values ? const input = tf.input({shape: [5]}); const denseLayer1 = tf.layers.dense({units: 10, activation: 'relu'}); const denseLayer2 = tf.layers.dense({units: 2, activation: 'softmax'}); const output = denseLayer2.apply(denseLayer1.apply(input)); const model = tf.model({inputs: input, outputs: output}); model.predict(tf.ones([2, 5])).print(); <html> <head> <!-- Load TensorFlow.js --> <script src="https://cdn.jsdelivr.net/npm/@tensorflow

expected first layer to have x dimensions but got an array with shape y

試著忘記壹切 提交于 2019-12-20 04:10:21
问题 (I am just starting tensorflow.js on node) I have been searching the web up and down for an answer. The confusion I have image data from image1 = tf.fromPixels(img) and I tried inputting it along with other image data to xs = tf.tensor([image1, image2]) . The confusion is no matter how I input a bunch of images into xs for model.fit , the program outputs errors described below. What I already tried When I run the program I get the error Error: Error when checking input: expected conv2d