Skip to content

Commit 651fd08

Browse files
authored
Remove usage of tensor.get() (#227)
Now that tensor.get() is removed in core: [tensorflow/tfjs-core#1537](tensorflow/tfjs-core#1537), replace it with data()[0]
1 parent 61b8763 commit 651fd08

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

website-phishing/index.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ function drawROC(targets, probs, epoch) {
7474
const threshold = thresholds[i];
7575

7676
const threshPredictions = utils.binarize(probs, threshold).as1D();
77-
const fpr = falsePositiveRate(targets, threshPredictions).get();
78-
const tpr = tf.metrics.recall(targets, threshPredictions).get();
77+
const fpr = falsePositiveRate(targets, threshPredictions).dataSync()[0];
78+
const tpr = tf.metrics.recall(targets, threshPredictions).dataSync()[0];
7979
fprs.push(fpr);
8080
tprs.push(tpr);
8181

@@ -140,15 +140,17 @@ data.loadData().then(async () => {
140140
model.evaluate(testData.data, testData.target, {batchSize: batchSize});
141141

142142
const lastTrainLog = trainLogs[trainLogs.length - 1];
143-
const testLoss = result[0].get();
144-
const testAcc = result[1].get();
143+
const testLoss = result[0].dataSync()[0];
144+
const testAcc = result[1].dataSync()[0];
145145

146146
const probs = model.predict(testData.data);
147147
const predictions = utils.binarize(probs).as1D();
148148

149-
const precision = tf.metrics.precision(testData.target, predictions).get();
150-
const recall = tf.metrics.recall(testData.target, predictions).get();
151-
const fpr = falsePositiveRate(testData.target, predictions).get();
149+
const precision =
150+
tf.metrics.precision(testData.target, predictions).dataSync()[0];
151+
const recall =
152+
tf.metrics.recall(testData.target, predictions).dataSync()[0];
153+
const fpr = falsePositiveRate(testData.target, predictions).dataSync()[0];
152154
ui.updateStatus(
153155
`Final train-set loss: ${lastTrainLog.loss.toFixed(4)} accuracy: ${
154156
lastTrainLog.acc.toFixed(4)}\n` +

website-phishing/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"node": ">=8.9.0"
1010
},
1111
"dependencies": {
12-
"@tensorflow/tfjs": "^0.14.2",
12+
"@tensorflow/tfjs": "^0.15.0",
1313
"@tensorflow/tfjs-vis": "^0.4.2",
1414
"papaparse": "^4.5.0"
1515
},

website-phishing/yarn.lock

+30-24
Original file line numberDiff line numberDiff line change
@@ -705,37 +705,38 @@
705705
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
706706
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=
707707

708-
"@tensorflow/tfjs-converter@0.7.2":
709-
version "0.7.2"
710-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-0.7.2.tgz#49e578f71eb82d821af05176754c3452b42cfe9c"
711-
integrity sha512-m46mtaF57x2NcxlNUKdJOCUp3ZSJU9bp9MzyEQ0Iz1bW2kKIxx1DDRjuP0fAeHX5H5Mh/tWIHB9yK6NwLz+aQQ==
708+
"@tensorflow/tfjs-converter@0.8.0":
709+
version "0.8.0"
710+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-0.8.0.tgz#d6c07a64ca376d7d4f4f57623e9ba35d074ca2d5"
711+
integrity sha512-OcraKdqO6M6vPgzcexER0cLXTsy7dM3URvko90Z6Vv9blP36BKZXRQYwqm91J0FbuLDrFJZ3uKubUVsIMbKAMQ==
712712
dependencies:
713713
"@types/long" "~3.0.32"
714+
js-base64 "2.4.9"
714715
protobufjs "~6.8.6"
715716

716-
"@tensorflow/tfjs-core@0.14.5":
717-
version "0.14.5"
718-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-0.14.5.tgz#17c3beeec31c4cd92b0f79a5ef30c4975a11e408"
719-
integrity sha512-CSUgKuC17J1Ylr1s6iD1k2/tJr9lD16sUEjtzJbtiuTYCELOwujGK/1htunA7o3BwLuU7aqEI92MoKElEKa7qA==
717+
"@tensorflow/tfjs-core@0.15.0":
718+
version "0.15.0"
719+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-0.15.0.tgz#c85f1141e42ce5103ae73fdf170b2d4736038533"
720+
integrity sha512-YITCsLeF8lqFQdepdv+a0wRQ4sVtg31cvqRzsuQBeQHyR04Xb3CH0kgKcwTj8FUXn+IlDsjE7m+v8Gier7YfuA==
720721
dependencies:
721722
"@types/seedrandom" "2.4.27"
722723
"@types/webgl-ext" "0.0.30"
723724
"@types/webgl2" "0.0.4"
724725
seedrandom "2.4.3"
725726

726-
"@tensorflow/tfjs-data@0.1.7":
727-
version "0.1.7"
728-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-data/-/tfjs-data-0.1.7.tgz#8a4e43313b3d63cdfab719c0c1c47ced2ef321e3"
729-
integrity sha512-RENjeBdBLq7GS9594kQx2GbM0WQV16VfxzzB0j2sq5vJh9GZQi2DB5Emq2LqZWs5rSeh7PDHZylGOn/ve6f8PA==
727+
"@tensorflow/tfjs-data@0.2.0":
728+
version "0.2.0"
729+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-data/-/tfjs-data-0.2.0.tgz#c66c73e634b56f46c7a17db0af6c3be8b9cc4428"
730+
integrity sha512-ut7TpdJE8I1YoaROKGs/AwZXa9d8GqOeBd/l2JFLQwzLVhA9LLh0fzCdIBnUGa6Gp5MdwD+3OoysV+neMDAs2w==
730731
dependencies:
731732
"@types/node-fetch" "^2.1.2"
732733
node-fetch "~2.1.2"
733734
seedrandom "~2.4.3"
734735

735-
"@tensorflow/tfjs-layers@0.9.2":
736-
version "0.9.2"
737-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-layers/-/tfjs-layers-0.9.2.tgz#f5c1918d1a9660096f259cd1f99f59e689b41b69"
738-
integrity sha512-peB824cEXRBy5IgZPIodd8zpQ/54VGOYbR+zY+Q1Le7v3Np05EoDcL8Z98MtpBHo6jOM7b/3Lf2zjfJVv2qxJA==
736+
"@tensorflow/tfjs-layers@0.10.0":
737+
version "0.10.0"
738+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-layers/-/tfjs-layers-0.10.0.tgz#a282ad3f533ac20645b23b0eaf5d15039ec91b5d"
739+
integrity sha512-O24iUscjutLFjRmJj55FASXtssD2Tldkz6n+MJ64gN0Etq+zA9A+Sbz3pWIjvDaKDhcXHsy4kmSbENF9Cztqqw==
739740

740741
"@tensorflow/tfjs-vis@^0.4.2":
741742
version "0.4.2"
@@ -751,15 +752,15 @@
751752
vega-lib "4.4.0"
752753
vega-lite "3.0.0-rc10"
753754

754-
"@tensorflow/tfjs@^0.14.2":
755-
version "0.14.2"
756-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs/-/tfjs-0.14.2.tgz#f38fa572286dadfe981c219f5639defd586c20c4"
757-
integrity sha512-d+kBdhn3L/BOIwwc44V1lUrs0O5s49ujhYXVHT9Hs6y3yq+OqPK10am16H1fNcxeMn12/3gGphebglObTD0/Sg==
755+
"@tensorflow/tfjs@^0.15.0":
756+
version "0.15.0"
757+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs/-/tfjs-0.15.0.tgz#bd8d7c109f25ba06c5686deca79bb0fff93507bc"
758+
integrity sha512-MP8N8vptlL1sTxH1K8m64SE+8Kw6FBmGtRMOY8R/AVEWW4Z1DD+crsMHUePzxXwU83HHeZPXJauKyzX/U1CgCQ==
758759
dependencies:
759-
"@tensorflow/tfjs-converter" "0.7.2"
760-
"@tensorflow/tfjs-core" "0.14.5"
761-
"@tensorflow/tfjs-data" "0.1.7"
762-
"@tensorflow/tfjs-layers" "0.9.2"
760+
"@tensorflow/tfjs-converter" "0.8.0"
761+
"@tensorflow/tfjs-core" "0.15.0"
762+
"@tensorflow/tfjs-data" "0.2.0"
763+
"@tensorflow/tfjs-layers" "0.10.0"
763764

764765
"@types/long@^4.0.0":
765766
version "4.0.0"
@@ -3523,6 +3524,11 @@ isomorphic-fetch@^2.1.1:
35233524
node-fetch "^1.0.1"
35243525
whatwg-fetch ">=0.10.0"
35253526

3527+
3528+
version "2.4.9"
3529+
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.9.tgz#748911fb04f48a60c4771b375cac45a80df11c03"
3530+
integrity sha512-xcinL3AuDJk7VSzsHgb9DvvIXayBbadtMZ4HFPx8rUszbW1MuNMlwYVC4zzCZ6e1sqZpnNS5ZFYOhXqA39T7LQ==
3531+
35263532
js-base64@^2.1.9:
35273533
version "2.5.0"
35283534
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.5.0.tgz#42255ba183ab67ce59a0dee640afdc00ab5ae93e"

0 commit comments

Comments
 (0)