Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return tf.tidy(() => {
const xTrains = [];
const yTrains = [];
const xTests = [];
const yTests = [];
for (let i = 0; i < gestureClasses.length; ++i) {
const [xTrain, yTrain, xTest, yTest] = convertToTensors(features[i], labels[i], 0.20);
xTrains.push(xTrain);
yTrains.push(yTrain);
xTests.push(xTest);
yTests.push(yTest);
}
const concatAxis = 0;
return [
tf.concat(xTrains, concatAxis), tf.concat(yTrains, concatAxis),
tf.concat(xTests, concatAxis), tf.concat(yTests, concatAxis)
];
})
}
const xTrains = [];
const yTrains = [];
const xTests = [];
const yTests = [];
for (let i = 0; i < gestureClasses.length; ++i) {
const [xTrain, yTrain, xTest, yTest] = convertToTensors(features[i], labels[i], 0.20);
xTrains.push(xTrain);
yTrains.push(yTrain);
xTests.push(xTest);
yTests.push(yTest);
}
const concatAxis = 0;
return [
tf.concat(xTrains, concatAxis), tf.concat(yTrains, concatAxis),
tf.concat(xTests, concatAxis), tf.concat(yTests, concatAxis)
];
})
}
const xTrains = [];
const yTrains = [];
const xTests = [];
const yTests = [];
for (let i = 0; i < gestureClasses.length; ++i) {
const [xTrain, yTrain, xTest, yTest] = convertToTensors(features[i], labels[i], 0.20);
xTrains.push(xTrain);
yTrains.push(yTrain);
xTests.push(xTest);
yTests.push(yTest);
}
const concatAxis = 0;
return [
tf.concat(xTrains, concatAxis), tf.concat(yTrains, concatAxis),
tf.concat(xTests, concatAxis), tf.concat(yTests, concatAxis)
];
})
}
const xTrains = [];
const yTrains = [];
const xTests = [];
const yTests = [];
for (let i = 0; i < gestureClasses.length; ++i) {
const [xTrain, yTrain, xTest, yTest] = convertToTensors(features[i], labels[i], 0.20);
xTrains.push(xTrain);
yTrains.push(yTrain);
xTests.push(xTest);
yTests.push(yTest);
}
const concatAxis = 0;
return [
tf.concat(xTrains, concatAxis), tf.concat(yTrains, concatAxis),
tf.concat(xTests, concatAxis), tf.concat(yTests, concatAxis)
];
})
}
return tf.tidy(() => {
const xTrains = [];
const yTrains = [];
const xTests = [];
const yTests = [];
for (let i = 0; i < gestureClasses.length; ++i) {
const [xTrain, yTrain, xTest, yTest] = convertToTensors(features[i], labels[i], 0.20);
xTrains.push(xTrain);
yTrains.push(yTrain);
xTests.push(xTest);
yTests.push(yTest);
}
const concatAxis = 0;
return [
tf.concat(xTrains, concatAxis), tf.concat(yTrains, concatAxis),
tf.concat(xTests, concatAxis), tf.concat(yTests, concatAxis)
];
})
}
const xTrains = [];
const yTrains = [];
const xTests = [];
const yTests = [];
for (let i = 0; i < gestureClasses.length; ++i) {
const [xTrain, yTrain, xTest, yTest] = convertToTensors(features[i], labels[i], 0.20);
xTrains.push(xTrain);
yTrains.push(yTrain);
xTests.push(xTest);
yTests.push(yTest);
}
const concatAxis = 0;
return [
tf.concat(xTrains, concatAxis), tf.concat(yTrains, concatAxis),
tf.concat(xTests, concatAxis), tf.concat(yTests, concatAxis)
];
})
}
const centroid = tf.tidy(() => {
const allEmbTensor = tf.concat(allEmbeddings);
if (allEmbTensor.shape[0] !== samples.length) {
throw new Error(`Some embeddings are missing: allEmbTensor.shape[0] !== samples.length: ${allEmbTensor.shape[0]} !== ${samples.length}`);
}
let centroid = allEmbTensor.mean(axis = 0);
if (NORMALIZE_CENTROID) {
centroid = normalize1d(centroid);
}
return centroid.arraySync();
});
allEmbeddings.forEach(emb => emb.dispose());