TypeError: tf.tensor(a).get(0) is not a function
See original GitHub issueHello,
I am learning TensorFlow.js through an online course. we prepared a very simple KNN function by tfjs but on the teacher’s computer it works but on my computer no.
I installed the 1.7.0 version of TensorFlow ( because of the latest existed document in tfjs website is 1.7.0) Node version: v12.16.1
when I run node on the terminal the below error appears :
.sort((a,b)=>{ return a.get(0)>b.get(0) ? 1 : -1 ; })//return a.get(0)>b.get(0) ? 1 : -1 ;
^
TypeError: a.get is not a function
it is my code :
require("@tensorflow/tfjs-node");
const tf = require("@tensorflow/tfjs");
const loadCSV = require("./load-csv.js");
function knn( features , labels, predictionPoint , k){
return features
.sub(predictionPoint)
.pow(2)
.sum(1)
.pow(0.5)
.expandDims(1)
.concat(labels , 1)
.unstack()
.sort((a,b)=>{ return a.get(0)>b.get(0) ? 1 : -1 ; })//return a.get(0)>b.get(0) ? 1 : -1 ;
.slice(0, k)
.reduce((accumulated , thisObj ) => {
// return accumulated + thisObj.get(1)
}, 0)/k;
}
let { features , labels , testFeatures , testLabels } = loadCSV("./kc_house_data.csv" , {
shuffle : true ,
splitTest : 10,
dataColumns: ['lat','long'],
labelColumns: ['price']
});
const locations = tf.tensor( features );
const prices = tf.tensor( labels );
const weAreLookingFor = tf.tensor( testFeatures[0] );
const result = knn ( locations, prices, weAreLookingFor , 10 );
console.log("KNN result is : ",result);
I could not find any related issues about it. I am completely stuck because of this problem. Please Help !
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Error: tensor.sub(...).get is not a function - Stack Overflow
To download the tensor data from the backend, the following can be used. tf.data ( and the corresponding sync tf.dataSync ).
Read more >tf.Tensor | TensorFlow v2.11.0
This overload raises a TypeError when the user inadvertently treats a Tensor as a boolean (most commonly in an if or while statement),...
Read more >Model.predict() not a function - Google Groups
to TensorFlow.js Discussion. I am trying to do image segementation of cell images to identify cells in tensor flow using data provided in ......
Read more >Problem with TensorFlow load model - Libraries
Hey, first time I'm using TensorFlow.js and I got a problem: ... function setup() { load(); } async function load() { model =...
Read more >Uncaught (In Promise) Typeerror: Tf.Sequential Is Not A ...
tensorboard object is not iterable iterator)) 15 Remember our best friend tf. TypeError: 'int' object is not iterable """ The above exception was...
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
It will work if change some codes to :
… .sort((a,b)=> a.arraySync()[0]> b.arraySync()[0]? 1:-1) .slice(0,k) .reduce((acc,pair)=>acc+pair.arraySync()[1],0)/k; …
get
is a method on TensorBuffer (https://js.tensorflow.org/api/1.7.0/#tf.TensorBuffer.get) not Tensor