Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint automatic fixes #1381

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/CharRNN/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A LSTM Generator: Run inference mode for a pre-trained LSTM.

import * as tf from "@tensorflow/tfjs";
import axios from "axios";
import sampleFromDistribution from "./../utils/sample";
import sampleFromDistribution from "../utils/sample";
import CheckpointLoader from "../utils/checkpointLoader";
import callCallback from "../utils/callcallback";

Expand Down Expand Up @@ -309,6 +309,6 @@ class CharRNN {
}
}

const charRNN = (modelPath = "./", callback) => new CharRNN(modelPath, callback);
const charRNN = (modelPath, callback) => new CharRNN(modelPath, callback);

export default charRNN;
9 changes: 3 additions & 6 deletions src/DBSCAN/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ async function loadDataset(inputData) {
} else {
data = inputData;
}
const dataFlat = data.map(d => {
return Object.values(d);
});
const dataFlat = data.map(d => Object.values(d));
return dataFlat;
}

Expand Down Expand Up @@ -138,6 +136,7 @@ class DBSCAN {
getClusterId() {
return this.lastClusterId;
}

/**
* increment cluster id
*/
Expand All @@ -159,9 +158,7 @@ class DBSCAN {
return tf
.stack([values.asType("float32"), indices.asType("float32")], 1)
.arraySync()
.filter(v => {
return v[0] <= this.config.eps;
})
.filter(v => v[0] <= this.config.eps)
.reduce((prev, cur) => {
prev.push(cur[1]);
return prev;
Expand Down
6 changes: 3 additions & 3 deletions src/FaceApi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class FaceApiBase {
* @param {Object} faceApiOptions
*/
setReturnOptions(faceApiOptions) {
const output = Object.assign({}, this.config);
const output = { ...this.config};
const options = ["withLandmarks", "withDescriptors"];

options.forEach(prop => {
Expand Down Expand Up @@ -306,7 +306,7 @@ class FaceApiBase {
if (Array.isArray(result) === true) {
output = result.map(item => {
// if landmarks exist return parts
const newItem = Object.assign({}, item);
const newItem = { ...item};
if (newItem.landmarks) {
const { landmarks } = newItem;
newItem.parts = {
Expand All @@ -333,7 +333,7 @@ class FaceApiBase {
});
// single detection is an object
} else {
output = Object.assign({}, result);
output = { ...result};
if (output.landmarks) {
const { landmarks } = result;
output.parts = {
Expand Down
6 changes: 3 additions & 3 deletions src/FeatureExtractor/Mobilenet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A class that extract features from Mobilenet
import * as tf from "@tensorflow/tfjs";
import axios from "axios";
import handleArguments from "../utils/handleArguments";
import Video from "./../utils/Video";
import Video from "../utils/Video";
import { imgToTensor } from "../utils/imageUtilities";
import { saveBlob } from "../utils/io";
import callCallback from "../utils/callcallback";
Expand Down Expand Up @@ -127,7 +127,7 @@ class Mobilenet {
* the video is ready. If no callback is provided, it will return a
* promise that will be resolved once the video element has loaded.
*/
classification(video, objOrCallback = null, callback) {
classification(video, objOrCallback, callback) {
const { options, callback: cb } = handleArguments(objOrCallback, callback);

this.usageType = "classifier";
Expand Down Expand Up @@ -367,7 +367,7 @@ class Mobilenet {
return { value: prediction[0] };
}

async load(filesOrPath = null, callback) {
async load(filesOrPath, callback) {
if (typeof filesOrPath !== "string") {
let model = null;
let weights = null;
Expand Down
8 changes: 3 additions & 5 deletions src/KMeans/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ async function loadDataset(inputData) {
} else {
data = inputData;
}
const dataFlat = data.map((d) => {
return Object.values(d)
});
const dataFlat = data.map(d => Object.values(d));
return dataFlat;
}

Expand Down Expand Up @@ -158,7 +156,7 @@ class KMeans {
const centroidKTensor = centroidK.map(d => d.tensor);
if (centroidKTensor.length === 0) {
return centroid;
} else if (centroidKTensor.length === 1) {
} if (centroidKTensor.length === 1) {
return centroidKTensor[0];
}
// grab mean for for cluster
Expand Down Expand Up @@ -186,4 +184,4 @@ class KMeans {

const kmeans = (dataset, options, callback) => new KMeans(dataset, options, callback);

export default kmeans;
export default kmeans;
14 changes: 5 additions & 9 deletions src/NeuralNetwork/NeuralNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ class NeuralNetwork {
* @param {*} _inputs
*/
predictSync(_inputs) {
const output = tf.tidy(() => {
return this.model.predict(_inputs);
});
const output = tf.tidy(() => this.model.predict(_inputs));
const result = output.arraySync();

output.dispose();
Expand All @@ -145,9 +143,7 @@ class NeuralNetwork {
* @param {*} _inputs
*/
async predict(_inputs) {
const output = tf.tidy(() => {
return this.model.predict(_inputs);
});
const output = tf.tidy(() => this.model.predict(_inputs));
const result = await output.array();

output.dispose();
Expand Down Expand Up @@ -211,16 +207,16 @@ class NeuralNetwork {
* @param {*} filesOrPath
* @param {*} callback
*/
async load(filesOrPath = null, callback) {
async load(filesOrPath, callback) {
if (filesOrPath instanceof FileList) {
const files = await Promise.all(
Array.from(filesOrPath).map(async file => {
if (file.name.includes('.json') && !file.name.includes('_meta')) {
return { name: 'model', file };
} else if (file.name.includes('.json') && file.name.includes('_meta.json')) {
} if (file.name.includes('.json') && file.name.includes('_meta.json')) {
const modelMetadata = await file.text();
return { name: 'metadata', file: modelMetadata };
} else if (file.name.includes('.bin')) {
} if (file.name.includes('.bin')) {
return { name: 'weights', file };
}
return { name: null, file: null };
Expand Down
46 changes: 20 additions & 26 deletions src/NeuralNetwork/NeuralNetworkData.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class NeuralNetworkData {
* @param {*} dataRaw
*/
getDataStats(dataRaw) {
const meta = Object.assign({}, this.meta);
const meta = { ...this.meta};

const inputMeta = this.getInputMetaStats(dataRaw, meta.inputs, 'xs');
const outputMeta = this.getInputMetaStats(dataRaw, meta.outputs, 'ys');
Expand All @@ -125,7 +125,7 @@ class NeuralNetworkData {
*/
// eslint-disable-next-line no-unused-vars, class-methods-use-this
getInputMetaStats(dataRaw, inputOrOutputMeta, xsOrYs) {
const inputMeta = Object.assign({}, inputOrOutputMeta);
const inputMeta = { ...inputOrOutputMeta};

Object.keys(inputMeta).forEach(k => {
if (inputMeta[k].dtype === 'string') {
Expand All @@ -151,7 +151,7 @@ class NeuralNetworkData {
*/
getDataUnits(dataRaw, _arrayShape = null) {
const arrayShape = _arrayShape !== null ? _arrayShape : undefined;
const meta = Object.assign({}, this.meta);
const meta = { ...this.meta};

// if the data has a shape pass it in
let inputShape;
Expand Down Expand Up @@ -182,7 +182,7 @@ class NeuralNetworkData {
// eslint-disable-next-line class-methods-use-this, no-unused-vars
getInputMetaUnits(_dataRaw, _inputsMeta) {
let units = 0;
const inputsMeta = Object.assign({}, _inputsMeta);
const inputsMeta = { ..._inputsMeta};

Object.entries(inputsMeta).forEach(arr => {
const { dtype } = arr[1];
Expand Down Expand Up @@ -271,7 +271,7 @@ class NeuralNetworkData {
*/
// eslint-disable-next-line class-methods-use-this, no-unused-vars
convertRawToTensors(dataRaw) {
const meta = Object.assign({}, this.meta);
const meta = { ...this.meta};
const dataLength = dataRaw.length;

return tf.tidy(() => {
Expand All @@ -281,18 +281,14 @@ class NeuralNetworkData {
dataRaw.forEach(row => {
// get xs
const xs = Object.keys(meta.inputs)
.map(k => {
return row.xs[k];
})
.map(k => row.xs[k])
.flat();

inputArr.push(xs);

// get ys
const ys = Object.keys(meta.outputs)
.map(k => {
return row.ys[k];
})
.map(k => row.ys[k])
.flat();

outputArr.push(ys);
Expand All @@ -319,7 +315,7 @@ class NeuralNetworkData {
* @param {*} dataRaw
*/
normalizeDataRaw(dataRaw) {
const meta = Object.assign({}, this.meta);
const meta = { ...this.meta};

const normXs = this.normalizeInputData(dataRaw, meta.inputs, 'xs');
const normYs = this.normalizeInputData(dataRaw, meta.outputs, 'ys');
Expand All @@ -340,7 +336,7 @@ class NeuralNetworkData {
// the data length
const dataLength = dataRaw.length;
// the copy of the inputs.meta[inputOrOutput]
const inputMeta = Object.assign({}, inputOrOutputMeta);
const inputMeta = { ...inputOrOutputMeta};

// normalized output object
const normalized = {};
Expand Down Expand Up @@ -392,9 +388,7 @@ class NeuralNetworkData {
// value with the onehot array
// if none exists, return the given value
if (options.legend) {
const normalized = inputArray.map(v => {
return options.legend[v] ? options.legend[v] : v;
});
const normalized = inputArray.map(v => options.legend[v] ? options.legend[v] : v);
return normalized;
}

Expand Down Expand Up @@ -460,7 +454,7 @@ class NeuralNetworkData {
* @param {*} _meta
*/
applyOneHotEncodingsToDataRaw(dataRaw) {
const meta = Object.assign({}, this.meta);
const meta = { ...this.meta};

const output = dataRaw.map(row => {
const xs = {
Expand Down Expand Up @@ -498,7 +492,7 @@ class NeuralNetworkData {
* @param {*} dataRaw
*/
getDataOneHot(dataRaw) {
const meta = Object.assign({}, this.meta);
const meta = { ...this.meta};

const inputMeta = this.getInputMetaOneHot(dataRaw, meta.inputs, 'xs');
const outputMeta = this.getInputMetaOneHot(dataRaw, meta.outputs, 'ys');
Expand All @@ -521,7 +515,7 @@ class NeuralNetworkData {
* @param {*} xsOrYs
*/
getInputMetaOneHot(_dataRaw, _inputsMeta, xsOrYs) {
const inputsMeta = Object.assign({}, _inputsMeta);
const inputsMeta = { ..._inputsMeta};

Object.entries(inputsMeta).forEach(arr => {
// the key
Expand Down Expand Up @@ -615,7 +609,7 @@ class NeuralNetworkData {
let json;
// handle loading parsedJson
if (dataUrlOrJson instanceof Object) {
json = Object.assign({}, dataUrlOrJson);
json = { ...dataUrlOrJson};
} else {
const {data} = await axios.get(dataUrlOrJson);
json = data;
Expand Down Expand Up @@ -684,7 +678,7 @@ class NeuralNetworkData {
* @param {*} filesOrPath
* @param {*} callback
*/
async loadData(filesOrPath = null, callback) {
async loadData(filesOrPath, callback) {
try {
let loadedData;

Expand Down Expand Up @@ -769,7 +763,7 @@ class NeuralNetworkData {
* @param {*} filesOrPath
* @param {*} callback
*/
async loadMeta(filesOrPath = null, callback) {
async loadMeta(filesOrPath, callback) {
if (filesOrPath instanceof FileList) {
const files = await Promise.all(
Array.from(filesOrPath).map(async file => {
Expand All @@ -778,13 +772,13 @@ class NeuralNetworkData {
name: 'model',
file,
};
} else if (file.name.includes('.json') && file.name.includes('_meta.json')) {
} if (file.name.includes('.json') && file.name.includes('_meta.json')) {
const modelMetadata = await file.text();
return {
name: 'metadata',
file: modelMetadata,
};
} else if (file.name.includes('.bin')) {
} if (file.name.includes('.bin')) {
return {
name: 'weights',
file,
Expand Down Expand Up @@ -925,11 +919,11 @@ class NeuralNetworkData {
* @param {*} _data
*/
findEntries(_data) {
const parentCopy = Object.assign({}, _data);
const parentCopy = { ..._data};

if (parentCopy.entries && parentCopy.entries instanceof Array) {
return parentCopy.entries;
} else if (parentCopy.data && parentCopy.data instanceof Array) {
} if (parentCopy.data && parentCopy.data instanceof Array) {
return parentCopy.data;
}

Expand Down
Loading