tensorflow.js

“Only absolute URLs are supported” when loading Keras model in Tensorflow.js with loadLayersModel

℡╲_俬逩灬. 提交于 2019-12-02 00:48:48
问题 I want to load a Keras model in Tensorflow.js from a local file, inside a NodeJS server, but I get the following error: "Only absolute URLs are supported". let tf = require("@tensorflow/tfjs"); (async () => { try { const model = await tf.loadLayersModel("/path/to/model.json"); } catch(error) { console.error(error); } })(); Are local files not supported yet with loadLayersModel? Thank you! 回答1: The Tensorflow documentation indicates that you should use direct to your filesystem using the file:

How to get the value of the element i, j of a tensor

末鹿安然 提交于 2019-12-02 00:36:55
I have a 2d tensor and I would like to get the value of the element of index i,j value. There are many ways one can retrieve the value of the element [i,j] of a tensor2d Consider the following: Using slice to retrieve directly the tensor2d starting at the coordinate [i, j] that has the size [1, 1] h.slice([i, j], 1).as1D().print() Get the row i as a tensor2d with gather and then the element j with slice h.gather(tf.tensor1d([i], 'int32')).slice([0, j], [1, 1]).as1D().print() Using stack to retrieve the row i as tensor1d and slice to retrieve the desired element h.unstack()[i].slice([j], [1])

Getting the result into a variable

人走茶凉 提交于 2019-12-01 23:28:38
I have the following example code. I'm able to see the correct result in the console from the print function. // Define a model for linear regression. const model = tf.sequential(); model.add(tf.layers.dense({units: 1, inputShape: [1]})); model.add(tf.layers.dense({units: 4, inputShape: [1]})); model.add(tf.layers.dense({units: 10, inputShape: [1]})); model.add(tf.layers.dense({units: 1, inputShape: [1]})); // Prepare the model for training: Specify the loss and the optimizer. model.compile({loss: 'meanSquaredError', optimizer: 'sgd'}); // Generate some synthetic data for training. const xs =

How to get data from 2D tensor?

情到浓时终转凉″ 提交于 2019-12-01 21:22:31
问题 I would like to get the data from a 2D tensor with tensorflow.js. I tried to use the data() method like this: const X = tf.tensor2d([[1, 2, 3, 4], [2, 2, 5, 3]]); X.data().then(X => console.log(X)}; But the result is a flatten 1D array: Float32Array(8) [1, 2, 3, 4, 2, 2, 5, 3] Is there a way to keep the shape of the array? 回答1: Data in the Tensor is always stored flattened as types 1 dimensional array, for speed. The example you gave will not work, because 2nd parameter to tensor2d is shape .

Error when checking input: expected dense_Dense1_input to have x dimension(s). but got array with shape y,z

假如想象 提交于 2019-12-01 03:37:05
问题 I'm very new to Tensorflowjs and Tensorflow in general. I have some data, which is capacity used out of 100%, so a number between 0 and 100, and there are 5 hours per day these capacities are noted. So I have a matrix of 5 days, containing 5 percentages out of 100%. I have the following model: const model = tf.sequential(); model.add(tf.layers.dense({units: 1, inputShape: [5, 5] })); model.compile({ loss: 'binaryCrossentropy', optimizer: 'sgd' }); // Input data // Array of days, and their

Tensorflow.js tokenizer

徘徊边缘 提交于 2019-11-30 21:40:21
I'm new to Machine Learning and Tensorflow, since I don't know python so I decide to use there javascript version (maybe more like a wrapper). The problem is I tried to build a model that process the Natural Language. So the first step is tokenizer the text in order to feed the data to model. I did a lot research, but most of them are using python version of tensorflow that use method like: tf.keras.preprocessing.text.Tokenizer which I can't find similar in tensorflow.js. I'm stuck in this step and don't know how can I transfer text to vector that can feed to model. Please help :) To transform

Tensorflow.js tokenizer

痴心易碎 提交于 2019-11-30 05:41:02
问题 I'm new to Machine Learning and Tensorflow, since I don't know python so I decide to use there javascript version (maybe more like a wrapper). The problem is I tried to build a model that process the Natural Language. So the first step is tokenizer the text in order to feed the data to model. I did a lot research, but most of them are using python version of tensorflow that use method like: tf.keras.preprocessing.text.Tokenizer which I can't find similar in tensorflow.js. I'm stuck in this

Retrain image detection with MobileNet

巧了我就是萌 提交于 2019-11-29 10:56:56
Several ways of retraining MobileNet for use with Tensorflow.js have failed for me. Is there any way to use a retrained model with Tensorflow.js? Both using the modern, hub-based tutorial, as well as using retrain.py seem to fail. Convert output of retrain.py to tensorflow.js Error converting keras model to tfjs: duplicate weight name Variable as well as some other open questions Retrain an Image Classifier in tensorflow js Loading of mobilenet v2 works, but pretrained mobilenet v2 fails Can't convert TensorFlow saved model to tfjs_layers_model webmodel The top two other questions show the

Load Tensorflow js model from local file system in javascript

白昼怎懂夜的黑 提交于 2019-11-28 11:43:21
I have converted a keras model to tensorflow json format and saved it locally in my computer. I am trying to load that json model in a javascript code using the below command model = await tf.loadModel('web_model') But the model is not getting loaded. Is there a way to load tensorflow json model from local file system? I know you're trying to load your model in a browser but if anybody lands here that's trying to do it in Node, here's how: const tf = require("@tensorflow/tfjs"); const tfn = require("@tensorflow/tfjs-node"); const handler = tfn.io.fileSystem("./path/to/your/model.json"); const

getting wrong prediction with custom model after loading save model in tensorflow.js

北城余情 提交于 2019-11-28 02:21:57
After compiling and training my custom model, I saved it and got two files such as .bin and .json. Further, I loaded that custom model on another page where I'm giving images as input which I used for training of that model and getting the prediction for those images based on the loaded custom model. Since it works fine for some of the images but returning the wrong prediction for other images. This is my code: $("#predict-button").click(async function(){ let image= $('#selected-image').get(0); let image1 = $('#selected-image1').get(0); console.log('image:::',image); console.log('image1:::'