From 06274cdf7a4a464f7b702dbb55c200e58d827770 Mon Sep 17 00:00:00 2001 From: Norman Koch Date: Thu, 19 Oct 2023 22:01:32 +0200 Subject: [PATCH 1/2] fix --- asanai.js | 112 +++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/asanai.js b/asanai.js index a85dd19a69..1644691bb2 100644 --- a/asanai.js +++ b/asanai.js @@ -24,15 +24,15 @@ class asanAI { #model_height = null; #model_width = null; #model = null; + #images_to_repredict = []; + #images_to_repredict_divs = []; + #custom_tensors = {}; constructor (...args) { var last_tested_tf_version = "4.11.0"; var last_tested_jquery_version = "3.6.0"; var last_tested_plotly_version = "2.14.0"; - this.custom_tensors = {}; - this.images_to_repredict = []; - this.images_to_repredict_divs = []; this.tf_version = this.get_version(`tf.version["tfjs-core"]`, last_tested_tf_version, "tensorflow.js"); this.jquery_version = this.get_version(`jQuery().jquery`, last_tested_jquery_version, "jQuery"); @@ -620,7 +620,7 @@ class asanAI { _register_tensors (...args) { for (var i = 0; i < args.length; i++) { if(this.is_tf_tensor(args[i])) { - this.custom_tensors["" + args[i].id] = [this.get_stack_trace(), args[i], this.tensor_print_to_string(args[i])]; + this.#custom_tensors["" + args[i].id] = [this.get_stack_trace(), args[i], this.tensor_print_to_string(args[i])]; this.clean_custom_tensors(); } } @@ -639,7 +639,7 @@ class asanAI { var first_tensor = args.shift(); var res = first_tensor.toInt(); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -650,7 +650,7 @@ class asanAI { var first_tensor = args.shift(); var res = first_tensor.toFloat(); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -661,7 +661,7 @@ class asanAI { var first_tensor = args.shift(); var res = first_tensor.toTensor(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -671,7 +671,7 @@ class asanAI { this._register_tensors(...args); var res = tf.mean(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -681,7 +681,7 @@ class asanAI { this._register_tensors(...args); var res = tf.relu(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -692,7 +692,7 @@ class asanAI { var first_tensor = args.shift(); var res = first_tensor.concat(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -702,7 +702,7 @@ class asanAI { this._register_tensors(...args); var res = tf.expandDims(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -712,7 +712,7 @@ class asanAI { this._register_tensors(...args); var res = tf.transpose(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -723,7 +723,7 @@ class asanAI { this._register_tensors(...args); var res = tf.sub(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -733,7 +733,7 @@ class asanAI { this._register_tensors(...args); var res = tf.min(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -743,7 +743,7 @@ class asanAI { this._register_tensors(...args); var res = tf.max(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -759,7 +759,7 @@ class asanAI { } var res = first_tensor.add(second_arg, ...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -770,7 +770,7 @@ class asanAI { this._register_tensors(...args); var res = tf.mul(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -780,7 +780,7 @@ class asanAI { this._register_tensors(...args); var res = tf.div(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -797,7 +797,7 @@ class asanAI { this._register_tensors(...args); var res = tf.reshape(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); return res; @@ -807,8 +807,8 @@ class asanAI { this._register_tensors(...args); var res = tf.unique(...args); - this.custom_tensors["" + res.values.id] = [this.get_stack_trace(), res.values, this.tensor_print_to_string(res.values)]; - this.custom_tensors["" + res.indices.id] = [this.get_stack_trace(), res.indices, this.tensor_print_to_string(res.indices)]; + this.#custom_tensors["" + res.values.id] = [this.get_stack_trace(), res.values, this.tensor_print_to_string(res.values)]; + this.#custom_tensors["" + res.indices.id] = [this.get_stack_trace(), res.indices, this.tensor_print_to_string(res.indices)]; this.clean_custom_tensors(); return res; @@ -907,8 +907,8 @@ class asanAI { var tensor_id = item.id; tf.dispose(item); - if(this.custom_tensors[tensor_id]) { - delete this.custom_tensors[tensor_id]; + if(this.#custom_tensors[tensor_id]) { + delete this.#custom_tensors[tensor_id]; } await this.nextFrame(); @@ -980,7 +980,7 @@ class asanAI { try { var k = res.layers[res.layers.length - 1].kernel; if(k) { - asanai_this.custom_tensors["" + k.id] = ["UUID:" + model_uuid, k, "[kernel in tf_sequential]"]; + asanai_this.#custom_tensors["" + k.id] = ["UUID:" + model_uuid, k, "[kernel in tf_sequential]"]; } } catch (e) { asanai_this.wrn(e); @@ -990,7 +990,7 @@ class asanAI { var b = res.layers[res.layers.length - 1].bias; if(b) { - asanai_this.custom_tensors["" + b.id] = ["UUID:" + model_uuid, b, "[bias in tf_sequential]"]; + asanai_this.#custom_tensors["" + b.id] = ["UUID:" + model_uuid, b, "[bias in tf_sequential]"]; } } catch (e) { asanai_this.wrn(e); @@ -1001,7 +1001,7 @@ class asanAI { return r; }; - asanai_this.custom_tensors["" + res.id] = ["UUID:" + model_uuid, res, "[model in tf_sequential]"]; + asanai_this.#custom_tensors["" + res.id] = ["UUID:" + model_uuid, res, "[model in tf_sequential]"]; asanai_this.clean_custom_tensors(); @@ -1013,7 +1013,7 @@ class asanAI { try { var res = tf.buffer(...args); - //this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + //this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1036,7 +1036,7 @@ class asanAI { try { var res = tf.browser.fromPixels(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1057,7 +1057,7 @@ class asanAI { try { var res = tf.input(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, "[input]"]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, "[input]"]; this.clean_custom_tensors(); @@ -1078,7 +1078,7 @@ class asanAI { try { var res = tf.ones(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1099,7 +1099,7 @@ class asanAI { try { var res = tf.reshape(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1120,7 +1120,7 @@ class asanAI { try { var res = tf.min(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1141,7 +1141,7 @@ class asanAI { try { var res = tf.max(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1162,7 +1162,7 @@ class asanAI { try { var res = tf.add(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1183,7 +1183,7 @@ class asanAI { try { var res = tf.abs(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1223,7 +1223,7 @@ class asanAI { try { var res = tf.image.resizeNearestNeighbor(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, "[resizeNearestNeighbor]"]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, "[resizeNearestNeighbor]"]; this.clean_custom_tensors(); @@ -1244,7 +1244,7 @@ class asanAI { try { var res = tf.image.resizeBilinear(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, "[resizeBilinear]"]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, "[resizeBilinear]"]; this.clean_custom_tensors(); @@ -1265,7 +1265,7 @@ class asanAI { try { var res = tf.image.rotateWithOffset(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1286,7 +1286,7 @@ class asanAI { try { var res = tf.image.flipLeftRight(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1307,7 +1307,7 @@ class asanAI { try { var res = tf.clipByValue(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1328,7 +1328,7 @@ class asanAI { try { var res = tf.randomUniform(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1349,7 +1349,7 @@ class asanAI { try { var res = tf.square(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1370,7 +1370,7 @@ class asanAI { try { var res = tf.mean(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1391,7 +1391,7 @@ class asanAI { try { var res = tf.sqrt(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1412,7 +1412,7 @@ class asanAI { try { var res = tf.tensor1d(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1433,7 +1433,7 @@ class asanAI { try { var res = tf.tensor2d(...args); - this.custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1454,7 +1454,7 @@ class asanAI { try { var res = tf.tensor(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1492,7 +1492,7 @@ class asanAI { try { var res = tf.divNoNan(...args); - this.custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1513,7 +1513,7 @@ class asanAI { try { var res = tf.oneHot(...args); - this.custom_tensors[res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; + this.#custom_tensors[res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; this.clean_custom_tensors(); @@ -1530,7 +1530,7 @@ class asanAI { } clean_custom_tensors () { - var keys = Object.keys(this.custom_tensors); + var keys = Object.keys(this.#custom_tensors); if(!keys.length) { return; @@ -1541,11 +1541,11 @@ class asanAI { var key = keys[i]; try { - if(!Object.keys(this.custom_tensors).includes(key) || this.custom_tensors[key][1].isDisposedInternal || this.custom_tensors[key][1].isDisposed) { + if(!Object.keys(this.#custom_tensors).includes(key) || this.#custom_tensors[key][1].isDisposedInternal || this.#custom_tensors[key][1].isDisposed) { disposed_keys.push(key); } } catch (e) { - if(("" + e).includes("this.custom_tensors[key] is undefined")) { + if(("" + e).includes("this.#custom_tensors[key] is undefined")) { // } else { this.wrn(e); @@ -1554,7 +1554,7 @@ class asanAI { } for (var i in disposed_keys) { - delete this.custom_tensors[disposed_keys[i]]; + delete this.#custom_tensors[disposed_keys[i]]; } } @@ -1715,7 +1715,7 @@ class asanAI { if(this.images_to_repredict) { for (var i = 0; i < this.images_to_repredict.length; i++) { var this_img_element = this.images_to_repredict[i]; - var this_div_element = this.images_to_repredict_divs[i]; + var this_div_element = this.#images_to_repredict_divs[i]; this.predict_image(this_img_element, this_div_element, 0); } } @@ -1849,8 +1849,8 @@ class asanAI { this.dispose(data); if(_add_to_repredict) { - this.images_to_repredict.push(img_element_or_div); - this.images_to_repredict_divs.push(write_to_div); + this.#images_to_repredict.push(img_element_or_div); + this.#images_to_repredict_divs.push(write_to_div); } return result; From a95b5a88e5aa3799e286f2861c6b11840f5a3ba5 Mon Sep 17 00:00:00 2001 From: Norman Koch Date: Thu, 19 Oct 2023 22:10:28 +0200 Subject: [PATCH 2/2] fix --- asanai.js | 224 +++++++++++++++++++++++++++--------------------------- 1 file changed, 112 insertions(+), 112 deletions(-) diff --git a/asanai.js b/asanai.js index 1644691bb2..10256239ad 100644 --- a/asanai.js +++ b/asanai.js @@ -6,7 +6,7 @@ class asanAI { #show_bars_instead_of_numbers = true; #max_neurons_fcnn = 32; #draw_internal_states = false; - #draw_internal_states_div = ""; + #internal_states_div = ""; #pixel_size = 3; #divide_by = 1; #labels = []; @@ -56,7 +56,7 @@ class asanAI { if(Object.keys(args[0]).includes("divide_by")) { if(typeof(args[0].divide_by) == "number" || this.#looks_like_number(args[0].divide_by)) { - this.#divide_by= this.parse_float(args[0].divide_by); + this.#divide_by= this.#parse_float(args[0].divide_by); } else { throw new Error("divide_by is not a number"); } @@ -70,11 +70,11 @@ class asanAI { } } - if(Object.keys(args[0]).includes("draw_internal_states_div")) { - if(typeof(args[0].draw_internal_states_div) == "string") { - this.#draw_internal_states_div = args[0].draw_internal_states_div; + if(Object.keys(args[0]).includes("internal_states_div")) { + if(typeof(args[0].internal_states_div) == "string") { + this.#internal_states_div = args[0].internal_states_div; } else { - throw new Error("draw_internal_states_div is not a string"); + throw new Error("internal_states_div is not a string"); } } @@ -108,7 +108,7 @@ class asanAI { return; } - var model_uuid = this.uuidv4(); + var model_uuid = this.#uuidv4(); var __model = this.tf_sequential(model_uuid); for (var layer_idx = 0; layer_idx < model_data.length; layer_idx++) { @@ -146,7 +146,7 @@ class asanAI { this.#model.summary(); } - uuidv4() { + #uuidv4() { var res = ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) ); @@ -180,7 +180,7 @@ class asanAI { try { var units = this.get_item_value_model(i); if(units) { - units = this.parse_int(units); + units = this.#parse_int(units); } else { units = 0; } @@ -621,7 +621,7 @@ class asanAI { for (var i = 0; i < args.length; i++) { if(this.is_tf_tensor(args[i])) { this.#custom_tensors["" + args[i].id] = [this.get_stack_trace(), args[i], this.tensor_print_to_string(args[i])]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); } } } @@ -640,7 +640,7 @@ class asanAI { var res = first_tensor.toInt(); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -651,7 +651,7 @@ class asanAI { var res = first_tensor.toFloat(); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -662,7 +662,7 @@ class asanAI { var res = first_tensor.toTensor(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -672,7 +672,7 @@ class asanAI { var res = tf.mean(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -682,7 +682,7 @@ class asanAI { var res = tf.relu(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -693,17 +693,17 @@ class asanAI { var res = first_tensor.concat(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } - expand_dims (...args) { + #expand_dims (...args) { this._register_tensors(...args); var res = tf.expandDims(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -713,7 +713,7 @@ class asanAI { var res = tf.transpose(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -724,7 +724,7 @@ class asanAI { var res = tf.sub(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -734,7 +734,7 @@ class asanAI { var res = tf.min(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -744,7 +744,7 @@ class asanAI { var res = tf.max(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -761,7 +761,7 @@ class asanAI { this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -771,7 +771,7 @@ class asanAI { var res = tf.mul(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -781,7 +781,7 @@ class asanAI { var res = tf.div(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -798,7 +798,7 @@ class asanAI { var res = tf.reshape(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -809,7 +809,7 @@ class asanAI { this.#custom_tensors["" + res.values.id] = [this.get_stack_trace(), res.values, this.tensor_print_to_string(res.values)]; this.#custom_tensors["" + res.indices.id] = [this.get_stack_trace(), res.indices, this.tensor_print_to_string(res.indices)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } @@ -919,7 +919,7 @@ class asanAI { */ } - this.clean_custom_tensors(); + this.#clean_custom_tensors(); } catch (e) { if(Object.keys(e).includes("message")) { e = e.message; @@ -952,7 +952,7 @@ class asanAI { try { var res = tf.tidy(...args); - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -996,14 +996,14 @@ class asanAI { asanai_this.wrn(e); } - asanai_this.clean_custom_tensors(); + asanai_this.#clean_custom_tensors(); return r; }; asanai_this.#custom_tensors["" + res.id] = ["UUID:" + model_uuid, res, "[model in tf_sequential]"]; - asanai_this.clean_custom_tensors(); + asanai_this.#clean_custom_tensors(); return res; } @@ -1015,7 +1015,7 @@ class asanAI { //this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1038,7 +1038,7 @@ class asanAI { this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1059,7 +1059,7 @@ class asanAI { this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, "[input]"]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1080,7 +1080,7 @@ class asanAI { this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1101,7 +1101,7 @@ class asanAI { this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1122,7 +1122,7 @@ class asanAI { this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1143,7 +1143,7 @@ class asanAI { this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1164,7 +1164,7 @@ class asanAI { this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1185,7 +1185,7 @@ class asanAI { this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1204,7 +1204,7 @@ class asanAI { try { var res = await tf.data.webcam(...args); - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1218,14 +1218,14 @@ class asanAI { } } - resizeNearestNeighbor(...args) { + #resizeNearestNeighbor(...args) { this._register_tensors(...args); try { var res = tf.image.resizeNearestNeighbor(...args); - this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, "[resizeNearestNeighbor]"]; + this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, "[#resizeNearestNeighbor]"]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1239,14 +1239,14 @@ class asanAI { } } - resizeBilinear(...args) { + #resizeBilinear(...args) { this._register_tensors(...args); try { var res = tf.image.resizeBilinear(...args); this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, "[resizeBilinear]"]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1260,14 +1260,14 @@ class asanAI { } } - rotateWithOffset (...args) { + #rotateWithOffset (...args) { this._register_tensors(...args); try { var res = tf.image.rotateWithOffset(...args); this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1281,14 +1281,14 @@ class asanAI { } } - flipLeftRight (...args) { + #flipLeftRight (...args) { this._register_tensors(...args); try { var res = tf.image.flipLeftRight(...args); this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1302,14 +1302,14 @@ class asanAI { } } - clipByValue (...args) { + #clipByValue (...args) { this._register_tensors(...args); try { var res = tf.clipByValue(...args); this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1323,14 +1323,14 @@ class asanAI { } } - randomUniform (...args) { + #randomUniform (...args) { this._register_tensors(...args); try { var res = tf.randomUniform(...args); this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1344,14 +1344,14 @@ class asanAI { } } - tf_square (...args) { + tf_square (...args) { this._register_tensors(...args); try { var res = tf.square(...args); this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1365,14 +1365,14 @@ class asanAI { } } - tf_mean (...args) { + tf_mean (...args) { this._register_tensors(...args); try { var res = tf.mean(...args); this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1386,14 +1386,14 @@ class asanAI { } } - sqrt (...args) { + sqrt (...args) { this._register_tensors(...args); try { var res = tf.sqrt(...args); this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1407,14 +1407,14 @@ class asanAI { } } - tensor1d (...args) { + tensor1d (...args) { this._register_tensors(...args); try { var res = tf.tensor1d(...args); this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1428,14 +1428,14 @@ class asanAI { } } - tensor2d (...args) { + tensor2d (...args) { this._register_tensors(...args); try { var res = tf.tensor2d(...args); this.#custom_tensors["" + res.dataId.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1449,14 +1449,14 @@ class asanAI { } } - tensor (...args) { + tensor (...args) { this._register_tensors(...args); try { var res = tf.tensor(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1470,7 +1470,7 @@ class asanAI { } } - grad (...args) { + grad (...args) { this._register_tensors(...args); try { var res = tf.grad(...args); @@ -1487,14 +1487,14 @@ class asanAI { } } - divNoNan (...args) { + divNoNan (...args) { this._register_tensors(...args); try { var res = tf.divNoNan(...args); this.#custom_tensors["" + res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1508,14 +1508,14 @@ class asanAI { } } - oneHot (...args) { + oneHot (...args) { this._register_tensors(...args); try { var res = tf.oneHot(...args); this.#custom_tensors[res.id] = [this.get_stack_trace(), res, this.tensor_print_to_string(res)]; - this.clean_custom_tensors(); + this.#clean_custom_tensors(); return res; } catch (e) { @@ -1529,7 +1529,7 @@ class asanAI { } } - clean_custom_tensors () { + #clean_custom_tensors () { var keys = Object.keys(this.#custom_tensors); if(!keys.length) { @@ -1558,22 +1558,22 @@ class asanAI { } } - parse_int (...args) { + #parse_int (...args) { var res = parseInt(...args); if(isNaN(res)) { - this.wrn("NaN detected in parse_int, args: " + JSON.stringify(args)); + this.wrn("NaN detected in #parse_int, args: " + JSON.stringify(args)); console.trace(); } return res; } - parse_float (...args) { + #parse_float (...args) { var res = parseFloat(...args); if(isNaN(res)) { - this.wrn("NaN detected in parse_int, args: " + JSON.stringify(args)); + this.wrn("NaN detected in #parse_float, args: " + JSON.stringify(args)); console.trace(); } @@ -1597,7 +1597,7 @@ class asanAI { } } - toPixels (...args) { + toPixels (...args) { this._register_tensors(...args); try { var res = tf.browser.toPixels(...args); @@ -1761,12 +1761,12 @@ class asanAI { } - tensor_shape_fits_input_shape (tensor_shape, model_shape) { + #tensor_shape_fits_input_shape (tensor_shape, model_shape) { this.assert(Array.isArray(tensor_shape), "tensor_shape is not an array"); this.assert(Array.isArray(model_shape), "model_shape is not an array"); if(tensor_shape.length != model_shape.length) { - this.wrn(`tensor_shape_fits_input_shape failed. Different number of values: tensor_shape: [${tensor_shape.join(", ")}], model_shape: [${model_shape.join(", ")}]`); + this.wrn(`#tensor_shape_fits_input_shape failed. Different number of values: tensor_shape: [${tensor_shape.join(", ")}], model_shape: [${model_shape.join(", ")}]`); return false; } @@ -1834,12 +1834,12 @@ class asanAI { var _width = model_input_shape[2]; var data = this.tidy(() => { - var image_tensor = this.expand_dims(this.fromPixels(img_element_or_div, this.#num_channels)); - image_tensor = this.resizeNearestNeighbor(image_tensor, [_height, _width]); + var image_tensor = this.#expand_dims(this.fromPixels(img_element_or_div, this.#num_channels)); + image_tensor = this.#resizeNearestNeighbor(image_tensor, [_height, _width]); return image_tensor; }); - var result = this.predict_manually(data); + var result = this.#predict_manually(data); if(write_to_div) { this.#_show_output(result, write_to_div); @@ -1856,29 +1856,29 @@ class asanAI { return result; } - predict_manually (_tensor) { + #predict_manually (_tensor) { if(!this.#model) { - this.err("[predict_image] Cannot predict without a model"); + this.err("[#predict_manually] Cannot predict without a model"); return; } if(!this.#model.input) { - this.err("[predict_image] Cannot predict without a model.input"); + this.err("[#predict_manually] Cannot predict without a model.input"); return; } if(!this.#model.input.shape) { - this.err("[predict_image] Cannot predict without a model.input.shape"); + this.err("[#predict_manually] Cannot predict without a model.input.shape"); return; } if(this.#num_channels != 3) { this.#num_channels = 3; - this.wrn(`[predict_image] Setting num_channels to 3, because webcam data does not have transparency.`); + this.wrn(`[#predict_manually] Setting num_channels to 3, because webcam data does not have transparency.`); } - if(!this.tensor_shape_fits_input_shape(_tensor.shape, this.#model.input.shape)) { - this.err(`[predict_image] Tensor does not fit model shape. Not predicting. Tensor shape: [${_tensor.shape.join(", ")}], model_shape: [${this.#model.input.shape.join(", ")}].`) + if(!this.#tensor_shape_fits_input_shape(_tensor.shape, this.#model.input.shape)) { + this.err(`[#predict_manually] Tensor does not fit model shape. Not predicting. Tensor shape: [${_tensor.shape.join(", ")}], model_shape: [${this.#model.input.shape.join(", ")}].`) return; } @@ -1995,8 +1995,8 @@ class asanAI { this.#camera = await tf.data.webcam($video_element); while (this.#started_webcam) { - if(this.internal_states_div) { - $("#" + this.internal_states_div).html(""); + if(this.#internal_states_div) { + $("#" + this.#internal_states_div).html(""); } var image; @@ -2024,14 +2024,14 @@ class asanAI { var worked = this.tidy(() => { try { - var _data = asanai_this.resizeNearestNeighbor(image, [asanai_this.#model_height, asanai_this.#model_width]); - var resized = asanai_this.expand_dims(_data); + var _data = asanai_this.#resizeNearestNeighbor(image, [asanai_this.#model_height, asanai_this.#model_width]); + var resized = asanai_this.#expand_dims(_data); //resized = asanai_this.tf_div(resized, asanai_this.#divide_by); var res; try { - res = asanai_this.predict_manually(resized) + res = asanai_this.#predict_manually(resized) } catch (e) { if(Object.keys(e).includes("message")) { e = e.message; @@ -2082,7 +2082,7 @@ class asanAI { #visualize_numbers_on_canvas (numberArray, blockWidth = 1, blockHeight = 25) { var canvas = document.createElement("canvas"); - canvas.id = "neurons_canvas_" + this.uuidv4(); + canvas.id = "neurons_canvas_" + this.#uuidv4(); canvas.classList.add("neurons_canvas_class"); // Calculate the canvas width based on the number of elements @@ -2112,14 +2112,14 @@ class asanAI { return canvas; } - get_methods (obj) { + #get_methods (obj) { return Object.getOwnPropertyNames(obj).filter(item => typeof obj[item] === "function") } hide_internals () { this.#draw_internal_states = false; - $("#" + this.internal_states_div).html(""); - this.internal_states_div = ""; + $("#" + this.#internal_states_div).html(""); + this.#internal_states_div = ""; } show_internals (divname="") { @@ -2135,11 +2135,11 @@ class asanAI { this.#draw_internal_states = true; if(divname) { - this.internal_states_div = divname; + this.#internal_states_div = divname; } } - normalize_to_image_data(input_data) { + #normalize_to_image_data(input_data) { var res = this.tidy(() => { var flattened_input = input_data; @@ -2205,10 +2205,10 @@ class asanAI { } for (var batchnr = 0; batchnr < number_of_items_in_this_batch; batchnr++) { - var input_data = this.normalize_to_image_data(inputs); - var output_data = this.normalize_to_image_data(applied); + var input_data = this.#normalize_to_image_data(inputs); + var output_data = this.#normalize_to_image_data(applied); - var __parent = $("#" + this.internal_states_div); + var __parent = $("#" + this.#internal_states_div); var layer_div = __parent.find($($(".layer_data")[layer])); if(layer_div.length == 0) { @@ -2251,7 +2251,7 @@ class asanAI { } - kernel_data = this.normalize_to_image_data(kernel_data); + kernel_data = this.#normalize_to_image_data(kernel_data); } var canvasses_input = this.#draw_image_if_possible(layer, "input", input_data); @@ -2336,12 +2336,12 @@ class asanAI { var red, green, blue; if(black_and_white) { - //red = green = blue = this.parse_int(colors[j][i]); // TODO + //red = green = blue = this.#parse_int(colors[j][i]); // TODO red = green = blue = parseInt(colors[j][i]); } else { - red = this.parse_int(colors[j][i][0]); - green = this.parse_int(colors[j][i][1]); - blue = this.parse_int(colors[j][i][2]); + red = this.#parse_int(colors[j][i][0]); + green = this.#parse_int(colors[j][i][1]); + blue = this.#parse_int(colors[j][i][2]); } var color = `rgb(${red}, ${green}, ${blue})`; @@ -2430,7 +2430,7 @@ class asanAI { set_pixel_size (_new) { if(this.#looks_like_number(_new)) { - this.#pixel_size = this.parse_int(_new); + this.#pixel_size = this.#parse_int(_new); } } @@ -2532,7 +2532,7 @@ class asanAI { var _uuid = ""; var _uuid_str = ""; if (use_uuid) { - _uuid = uuidv4(); + _uuid = this.#uuidv4(); _uuid_str = " id='" + _uuid + "'"; } var new_canvas = $("", {class: "layer_image", style: 'margin: 5px'}).prop({ @@ -2776,7 +2776,7 @@ class asanAI { set_divide_by (number) { if(this.#looks_like_number(number)) { - this.#divide_by = this.parse_float(number); + this.#divide_by = this.#parse_float(number); return this.#divide_by; } @@ -2810,7 +2810,7 @@ class asanAI { var asanai_this = this; var normalized = this.tidy(() => { - var _n = asanai_this.tensor(asanai_this.normalize_to_image_data(asanai_this.array_sync(predictions_tensor))); + var _n = asanai_this.tensor(asanai_this.#normalize_to_image_data(asanai_this.array_sync(predictions_tensor))); return _n; });