license import * as tf from '@tensorflow/tfjs' ; /**
 * Convert an ArrayBuffer to a Buffer.
 */ export function toBuffer ( ab ) { const view = new Uint8Array ( ab ) ; return Buffer . from ( view ) ; } /**
 * Convert a Buffer or an Array of Buffers to an ArrayBuffer.
 *
 * If the input is an Array of Buffers, they will be concatenated in the
 * specified order to form the output ArrayBuffer.
 */ export function toArrayBuffer ( buf ) { if ( Array . isArray ( buf ) ) { let totalLength = 0 ; for ( const buffer of buf ) { totalLength += buffer . length ; } const ab = new ArrayBuffer ( totalLength ) ; const view = new Uint8Array ( ab ) ; let pos = 0 ; for ( const buffer of buf ) { pos += buffer . copy ( view , pos ) ; } return ab ; } else { return buf . buffer . slice ( buf . byteOffset , buf . byteOffset + buf . byteLength ) ; } } param modelArtifacts returns export function getModelArtifactsInfoForJSON ( modelArtifacts ) { if ( modelArtifacts . modelTopology instanceof ArrayBuffer ) { throw new Error ( 'Expected JSON model topology, received ArrayBuffer.' ) ; } return { dateSaved : new Date ( ) , modelTopologyType : 'JSON' , modelTopologyBytes : modelArtifacts . modelTopology == null ? 0 : Buffer . byteLength ( JSON . stringify ( modelArtifacts . modelTopology ) , 'utf8' ) , weightSpecsBytes : modelArtifacts . weightSpecs == null ? 0 : Buffer . byteLength ( JSON . stringify ( modelArtifacts . weightSpecs ) , 'utf8' ) , weightDataBytes : modelArtifacts . weightData == null ? 0 : modelArtifacts . weightData . byteLength , } ; }