Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
log = common.getLogFlagFromKarmaFlags();
}
console.log(`Boolean flag log = ${log}`);
const taskType = 'model';
let environmentInfo: EnvironmentInfo;
if (isNodeJS) {
environmentInfo = common.getNodeEnvironmentInfo(tfn);
} else {
environmentInfo = common.getBrowserEnvironmentInfo();
}
const versionSet: VersionSet = isNodeJS ? {versions: tfn.version} : {
versions: {
'tfjs-converter': tfconverter.version_converter,
'tfjs-core': tfc.version_core,
'tfjs-data': tfd.version_data,
'tfjs-layers': tfl.version_layers
}
};
let suiteLog: common.SuiteLog;
if (isNodeJS) {
// tslint:disable-next-line:no-require-imports
const fs = require('fs');
suiteLog = JSON.parse(fs.readFileSync(BENCHMARKS_JSON_PATH, 'utf-8'));
} else {
suiteLog =
await (await fetch(BENCHMARKS_JSON_URL)).json() as common.SuiteLog;
}
const pyEnvironmentInfo = suiteLog.environmentInfo;
const pyEnvironmentId =
log ? await addEnvironmentInfoToFirestore(pyEnvironmentInfo) : null;
async function init() {
try {
// await webcam.setup();
webcamDataset = tfd.webcam(
document.getElementById('webcam') as HTMLVideoElement,
{frameRate: 10, width: 224, height: 224});
await webcamDataset.init();
} catch (e) {
document.getElementById('no-webcam').style.display = 'block';
}
truncatedMobileNet = await loadTruncatedMobileNet();
// Warm up the model. This uploads weights to the GPU and compiles the WebGL
// programs so the first time we collect data from the webcam it will be
// quick.
const screenShot = await webcamDataset.capture();
truncatedMobileNet.predict(screenShot.expandDims(0));
screenShot.dispose();
ui.init();
private async prepareDataset(url: string) {
// We want to predict the column "medv", which represents a median value of
// a home (in $1000s), so we mark it as a label.
const csvDataset = tfd.csv(url, {columnConfigs: {medv: {isLabel: true}}});
// Reduces the object-type data to an array of numbers.
const convertedDataset =
csvDataset.map((row: Array<{[key: string]: number}>) => {
const [rawFeatures, rawLabel] = row;
const convertedFeatures = Object.values(rawFeatures);
const convertedLabel = [rawLabel['medv']];
return [convertedFeatures, convertedLabel];
});
return {
dataset: convertedDataset.shuffle(100),
numFeatures: (await csvDataset.columnNames()).length - 1
};
}
}