tensorflow.js

partition or mask or filter a Tensor in tensorflow.js

本秂侑毒 提交于 2019-12-07 00:40:29
I have 2 Tensors of same length, data and groupIds . I want to split data into several groups by the corresponding values in groupId . For example, const data = tf.tensor([1,2,3,4,5]); const groupIds = tf.tensor([0,1,1,0,0]); // expected result: [tf.tensor([1,4,5]), tf.tensor([2,3])] In Tensorflow there is tf.dynamic_partition which does exactly that. Tensorflow.js doesn't seem to have a similar method. I also looked into mask or filtering as work-arounds, but they don't exist either. Does anyone have an idea how to implement this? To partition your tensor, you can first iterate over your ids

loadFrozenModel does not work with local files

耗尽温柔 提交于 2019-12-07 00:08:31
need help with async/await. currently studying https://github.com/tensorflow/tfjs-converter . and I'm stumped at this part of the code (loading my python converted saved js model for use in the browser): import * as tf from '@tensorflow/tfjs'; import {loadFrozenModel} from '@tensorflow/tfjs-converter'; /*1st model loader*/ const MODEL_URL = './model/web_model.pb'; const WEIGHTS_URL = '.model/weights_manifest.json'; const model = await loadFrozenModel(MODEL_URL, WEIGHTS_URL); /*2nd model execution in browser*/ const cat = document.getElementById('cat'); model.execute({input: tf.fromPixels(cat)}

Getting weights from tensorflow.js neural network

旧街凉风 提交于 2019-12-06 05:52:26
I have this sequential model: this.model = tf.sequential() this.model.add(tf.layers.dense({units : 16, useBias : true, inputDim : 7})) // input this.model.add(tf.layers.dense({units : 16, useBias : true, activation: 'sigmoid'})) // hidden this.model.add(tf.layers.dense({units : 3, useBias : true, activation: 'sigmoid'})) // hidden 2 I checked API for tensorflow.js, but there's nothing about getting weights(kernels) of neural network. So, how can I get weights and then change them, to apply new weights?(for unsupervised learning) Dhruv Guliani It seems like there is probably a simpler and

TensorFlowJS Exception - Cannot start training because another fit() call is ongoing

你说的曾经没有我的故事 提交于 2019-12-06 01:30:50
I used tf.expandDims() to add dimensions. Since I'm able to go into model.fit(), but got stuck due to this error Cannot start training because another fit() call is ongoing. and Cannot read property 'length' of undefined. You can find my code here // Train the model using the data. let tesnor_dim =[]; let tensr;for(var j=0; j<2; j++){ console.log('resize_image',resize_image); tensr = tf.expandDims(ysarr[j], 0); tesnor_dim.push(tensr); console.log('tesnor_dim',tesnor_dim); model.fit(resize_image[j], tesnor_dim[j], {epochs: 100}).then((loss) => { console.log('resize_image[j]',resize_image[j]);

Use Azure custom-vision trained model with tensorflow.js

偶尔善良 提交于 2019-12-05 02:41:01
问题 I've trained a model with Azure Custom Vision and downloaded the TensorFlow files for Android (see: https://docs.microsoft.com/en-au/azure/cognitive-services/custom-vision-service/export-your-model). How can I use this with tensorflow.js? I need a model (pb file) and weights (json file). However Azure gives me a .pb and a textfile with tags. From my research I also understand that there are also different pb files, but I can't find which type Azure Custom Vision exports. I found the tfjs

Get the layers from one model and assign it to another model

旧街凉风 提交于 2019-12-04 06:22:11
问题 Given a model created using tf.sequential() , is it possible to get the layers and to use them to create another model using tf.model() ? const model = tf.sequential(); model.add(tf.layers.dense({units: 32, inputShape: [50]})); model.add(tf.layers.dense({units: 4})); // get the layers layers // use the layers to create another model tf.model({layers}) 回答1: To get the layers of the model created using tf.sequential , one needs to use the property layers of the model const model = tf.sequential

Use Azure custom-vision trained model with tensorflow.js

一个人想着一个人 提交于 2019-12-03 17:07:27
I've trained a model with Azure Custom Vision and downloaded the TensorFlow files for Android (see: https://docs.microsoft.com/en-au/azure/cognitive-services/custom-vision-service/export-your-model ). How can I use this with tensorflow.js ? I need a model (pb file) and weights (json file). However Azure gives me a .pb and a textfile with tags. From my research I also understand that there are also different pb files, but I can't find which type Azure Custom Vision exports. I found the tfjs converter . This is to convert a TensorFlow SavedModel (is the *.pb file from Azure a SavedModel?) or

Model is not learning

巧了我就是萌 提交于 2019-12-02 07:43:54
问题 I am trying to train a Tensor-flow js model on images coming in from my web cam. Basically I'm trying to recreate the pac-man tensor-flow game. The model isn't converging and is pretty much useless after training. I have a feeling its how I'm prepping the data. Grabbing the image from the canvas function takePhoto(label) { let canv = document.getElementById("canv") let cont = canv.getContext("2d") cont.drawImage(video, 0, 0, width, height) let data = tf.browser.fromPixels(canv, 3) data

Model is not learning

白昼怎懂夜的黑 提交于 2019-12-02 05:35:08
I am trying to train a Tensor-flow js model on images coming in from my web cam. Basically I'm trying to recreate the pac-man tensor-flow game. The model isn't converging and is pretty much useless after training. I have a feeling its how I'm prepping the data. Grabbing the image from the canvas function takePhoto(label) { let canv = document.getElementById("canv") let cont = canv.getContext("2d") cont.drawImage(video, 0, 0, width, height) let data = tf.browser.fromPixels(canv, 3) data.toFloat().div(tf.scalar(127)).sub(tf.scalar(1)) return data } function addExample(label){ let data =

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

有些话、适合烂在心里 提交于 2019-12-02 02:15:28
问题 I have a 2d tensor and I would like to get the value of the element of index i,j value. 回答1: 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