1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[26],{4026:function(e,t,s){s.r(t),s.d(t,{BertNLClassifier:function(){return N},BertQuestionAnswerer:function(){return I},ImageClassifier:function(){return g},ImageSegmenter:function(){return y},NLClassifier:function(){return b},ObjectDetector:function(){return T},OutputType:function(){return r},TFLiteModel:function(){return c},getDTypeFromTFLiteType:function(){return u},getWasmFeatures:function(){return m},loadTFLiteModel:function(){return l},setWasmPath:function(){return p}});var n,r,a=s(6819),i=s(2976);/** 2 * @license 3 * Copyright 2021 Google LLC. All Rights Reserved. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * ============================================================================= 16 */ let o="?lite-format=tflite";class c{constructor(e){this.modelRunner=e}get inputs(){let e=this.modelRunner.getInputs();return this.convertTFLiteTensorInfos(e)}get outputs(){let e=this.modelRunner.getOutputs();return this.convertTFLiteTensorInfos(e)}predict(e,t){let s=this.modelRunner.getInputs(),n=this.modelRunner.getOutputs();if(e instanceof a.esB||Array.isArray(e)){let r;if(r=e instanceof a.esB?[e]:e,s.length!==r.length)throw Error(`The size of TFLite model inputs (${s.length}) does not match the size of the input tensors (${r.length})`);for(let i=0;i<s.length;i++)this.setModelInputFromTensor(s[i],r[i])}else{let o=Object.keys(e),c={};s.forEach(e=>{c[e.name]=e});let l=Object.keys(c);for(let u of(this.checkMapInputs(o,l),o))this.setModelInputFromTensor(c[u],e[u])}let h=this.modelRunner.infer();if(!h)throw Error("Failed running inference");let p={};for(let m=0;m<n.length;m++){let f=n[m],d=f.data();switch(f.dataType){case"int8":case"int16":case"uint32":d=Int32Array.from(d);break;
16case"float64":console.warn("WARNING: converting output tensor from 'float64' to 'float32'"),d=Float32Array.from(d)}let g=(0,a.XeE)(d,this.getShapeFromTFLiteTensorInfo(f));p[f.name]=g}let y=Object.keys(p);return 1===y.length?p[y[0]]:p}execute(e,t){throw Error("execute() of TFLiteModel is not supported yet.")}getProfilingResults(){return this.modelRunner.getProfilingResults()}getProfilingSummary(){return this.modelRunner.getProfilingSummary()}setModelInputFromTensor(e,t){if("string"===t.dtype||"complex64"===t.dtype)throw Error(`Data type '${t.dtype}' not supported.`);let s=e.shape.split(",").map(e=>Number(e));if(!t.shape.every((e,t)=>-1===s[t]||s[t]===e))throw Error(`Input tensor shape mismatch: expect '${e.shape}', got '${t.shape.join(",")}'.`);switch(e.dataType){case"bool":case"int8":case"uint8":case"int16":case"uint32":case"int32":if("float32"===t.dtype)throw this.getDataTypeMismatchError(e.dataType,t.dtype);e.dataType!==t.dtype&&console.warn(`WARNING: converting '${t.dtype}' to '${e.dataType}'`);break;case"float32":case"float64":e.dataType!==t.dtype&&console.warn(`WARNING: convert
16ing '${t.dtype}' to '${e.dataType}'`)}let n=e.data();switch(e.dataType){case"int8":n.set(Int8Array.from(t.dataSync()));break;case"uint8":case"bool":n.set(Uint8Array.from(t.dataSync()));break;case"int16":n.set(Int16Array.from(t.dataSync()));break;case"int32":n.set(Int32Array.from(t.dataSync()));break;case"uint32":n.set(Uint32Array.from(t.dataSync()));break;case"float32":n.set(Float32Array.from(t.dataSync()));break;case"float64":n.set(Float64Array.from(t.dataSync()))}}convertTFLiteTensorInfos(e){return e.map(e=>{let t=u(e.dataType);return{name:e.name,shape:this.getShapeFromTFLiteTensorInfo(e),dtype:t}})}checkMapInputs(e,t){let s=e.filter(e=>!t.includes(e)),n=t.filter(t=>!e.includes(t));if(0===s.length&&0===n.length)return;let r=["The model input names don't match the model input names."];throw s.length>0&&r.push(`Names in input but missing in model: [${s}].`),n.length>0&&r.push(`Names in model but missing in inputs: [${n}].`),Error(r.join(" "))}getShapeFromTFLiteTensorInfo(e){return e.shape.split(",").map(e=>Number(e))}getDataTypeMismatchError(e,t){return Error(`Data type mismatch: input tensor expects '${e}', got '${t}'`)}}async function l(e,t){"string"==typeof e&&e.includes("tfhub.dev")&&e.includes("lite-model")&&!e.endsWith(o)&&(e=`${e}${o}`);let s=await i.tfweb.TFLiteWebModelRunner.create(e,t);return new c(s)}function u(e){let t;switch(e){case"float32":case"float64":t="float32";break;case"int8":case"uint8":case"int16":case"int32":case"uint32":t="int32";break;case"bool":t="bool"}return t}/** 17 * @license 18 * Copyright 2021 Google LLC. All Rights Reserved. 19 * Licensed under the Apache License, Version 2.0 (the "License"); 20 * you may not use this file except in compliance with the License. 21 * You may obtain a copy of the License at 22 * 23 * http://www.apache.org/licenses/LICENSE-2.0 24 * 25 * Unless required by applicable law or agreed to in writing, software 26 * distributed under the License is distributed on an "AS IS" BASIS, 27 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28 * See the License for the specific language governing permissions and 29 * limitations under the License. 30 * ============================================================================= 31 */ function h(e){let t=[];return e.forEach(e=>{t.push({className:e.getDisplayName()||e.getClassName(),probability:e.getScore()})}),t}let p=i.tfweb.tflite_web_api.setWasmPath,m=i.tfweb.tflite_web_api.getWasmFeatures;class f{constructor(e){this.instance=e}cleanUp(){this.instance.cleanUp()}}async function d(){let e=(await i.tfweb.tflite_web_api.getWasmFeatures()).multiThreading;return e?navigator.hardwareConcurrency/2:-1}/** 32 * @license 33 * Copyright 2021 Google LLC. All Rights Reserved. 34 * Licensed under the Apache License, Version 2.0 (the "License"); 35 * you may not use this file except in compliance with the License. 36 * You may obtain a copy of the License at 37 * 38 * http://www.apache.org/licenses/LICENSE-2.0 39 * 40 * Unless required by applicable law or agreed to in writing, software 41 * distributed under the License is distributed on an "AS IS" BASIS, 42 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 43 * See the License for the specific language governing permissions and 44 * limitations under the License. 45 * ============================================================================= 46 */ class g extends f{constructor(e){super(e),this.instance=e}static async create(e,t){let s=new i.tfweb.ImageClassifierOptions;t&&(void 0!==t.maxResults&&s.setMaxResults(t.maxResults),void 0!==t.scoreThreshold&&s.setScoreThreshold(t.scoreThreshold),void 0!==t.numThreads&&s.setNumThreads(t.numThreads)),t&&void 0!==t.numThreads||s.setNumThreads(await d());let n=await i.tfweb.ImageClassifier.create(e,s);return new g(n)}classify(e){let t=this.instance.classify(e);if(!t)return[];let s=[];return t.getClassificationsList().length>0&&(s=h(t.getClassificationsList()[0].getClassesList())),s}}(n=r||(r={}))[n.CATEGORY_MASK=1]="CATEGORY_MASK",n[n.CONFIDENCE_MASK=2]="CONFIDENCE_MASK",n[n.UNSPECIFIED=0]="UNSPECIFIED";class y extends f{constructor(e){super(e),this.instance=e}static async create(e,t){let s=new i.tfweb.ImageSegmenterOptions;t&&(t.outputType&&s.setOutputType(t.outputType),void 0!==t.numThreads&&s.setNumThreads(t.numThreads)),t&&void 0!==t.numThreads||s.setNumThreads(await d());let n=await i.tfweb.ImageSegmenter.create(e,s);return new y(n)}segment(e){let t=this.instance.segment(e);
46if(!t)return[];let s=[];return t.getSegmentationList().length>0&&t.getSegmentationList().forEach(e=>{let t=e.getColoredLabelsList().map(e=>({r:e.getR(),g:e.getG(),b:e.getB(),className:e.getClassName(),displayName:e.getDisplayName()}));s.push({width:e.getWidth(),height:e.getHeight(),categoryMask:e.getCategoryMask_asU8(),coloredLabels:t})}),s}}/** 47 * @license 48 * Copyright 2021 Google LLC. All Rights Reserved. 49 * Licensed under the Apache License, Version 2.0 (the "License"); 50 * you may not use this file except in compliance with the License. 51 * You may obtain a copy of the License at 52 * 53 * http://www.apache.org/licenses/LICENSE-2.0 54 * 55 * Unless required by applicable law or agreed to in writing, software 56 * distributed under the License is distributed on an "AS IS" BASIS, 57 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 58 * See the License for the specific language governing permissions and 59 * limitations under the License. 60 * ============================================================================= 61 */ class T extends f{constructor(e){super(e),this.instance=e}static async create(e,t){let s=new i.tfweb.ObjectDetectorOptions;t&&(void 0!==t.maxResults&&s.setMaxResults(t.maxResults),void 0!==t.scoreThreshold&&s.setScoreThreshold(t.scoreThreshold),void 0!==t.numThreads&&s.setNumThreads(t.numThreads)),t&&void 0!==t.numThreads||s.setNumThreads(await d());let n=await i.tfweb.ObjectDetector.create(e,s);return new T(n)}detect(e){let t=this.instance.detect(e);if(!t)return[];let s=[];return t.getDetectionsList().length>0&&t.getDetectionsList().forEach(e=>{let t=e.getBoundingBox(),n={originX:t.getOriginX(),originY:t.getOriginY(),width:t.getWidth(),height:t.getHeight()},r=h(e.getClassesList());s.push({boundingBox:n,classes:r})}),s}}/** 62 * @license 63 * Copyright 2021 Google LLC. All Rights Reserved. 64 * Licensed under the Apache License, Version 2.0 (the "License"); 65 * you may not use this file except in compliance with the License. 66 * You may obtain a copy of the License at 67 * 68 * http://www.apache.org/licenses/LICENSE-2.0 69 * 70 * Unless required by applicable law or agreed to in writing, software 71 * distributed under the License is distributed on an "AS IS" BASIS, 72 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 73 * See the License for the specific language governing permissions and 74 * limitations under the License. 75 * ============================================================================= 76 */ let w={inputTensorIndex:0,outputScoreTensorIndex:0,outputLabelTensorIndex:-1,inputTensorName:"INPUT",outputScoreTensorName:"OUTPUT_SCORE",outputLabelTensorName:"OUTPUT_LABEL"};class b extends f{constructor(e){super(e),this.instance=e}static async create(e,t=w){let s=await i.tfweb.NLClassifier.create(e,t);return new b(s)}classify(e){return this.instance.classify(e).map(e=>({probability:e.score,className:e.className}))}}/** 77 * @license 78 * Copyright 2021 Google LLC. All Rights Reserved. 79 * Licensed under the Apache License, Version 2.0 (the "License"); 80 * you may not use this file except in compliance with the License. 81 * You may obtain a copy of the License at 82 * 83 * http://www.apache.org/licenses/LICENSE-2.0 84 * 85 * Unless required by applicable law or agreed to in writing, software 86 * distributed under the License is distributed on an "AS IS" BASIS, 87 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 88 * See the License for the specific language governing permissions and 89 * limitations under the License. 90 * ============================================================================= 91 */ class N extends f{constructor(e){super(e),this.instance=e}static async create(e,t){let s=new i.tfweb.BertNLClassifierOptions;t&&t.maxSeqLen&&s.setMaxSeqLen(t.maxSeqLen);let n=await i.tfweb.BertNLClassifier.create(e,s);return new N(n)}classify(e){return this.instance.classify(e).map(e=>({probability:e.score,className:e.className}))}}/** 92 * @license 93 * Copyright 2021 Google LLC. All Rights Reserved. 94 * Licensed under the Apache License, Version 2.0 (the "License"); 95 * you may not use this file except in compliance with the License. 96 * You may obtain a copy of the License at 97 * 98 * http://www.apache.org/licenses/LICENSE-2.0 99 * 100 * Unless required by applicable law or agreed to in writing, softw
100are 101 * distributed under the License is distributed on an "AS IS" BASIS, 102 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 103 * See the License for the specific language governing permissions and 104 * limitations under the License. 105 * ============================================================================= 106 */ class I extends f{constructor(e){super(e),this.instance=e}static async create(e){let t=await i.tfweb.BertQuestionAnswerer.create(e);return new I(t)}answer(e,t){let s=this.instance.answer(e,t);return s?s.map(e=>({text:e.text,pos:e.pos})):[]}}/** 107 * @license 108 * Copyright 2021 Google LLC. All Rights Reserved. 109 * Licensed under the Apache License, Version 2.0 (the "License"); 110 * you may not use this file except in compliance with the License. 111 * You may obtain a copy of the License at 112 * 113 * http://www.apache.org/licenses/LICENSE-2.0 114 * 115 * Unless required by applicable law or agreed to in writing, software 116 * distributed under the License is distributed on an "AS IS" BASIS, 117 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 118 * See the License for the specific language governing permissions and 119 * limitations under the License. 120 * ============================================================================= 121 */ }}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.