{"id":23773377,"url":"https://github.com/beenotung/tensorflow-helpers","last_synced_at":"2026-02-17T22:32:19.791Z","repository":{"id":252530196,"uuid":"840630612","full_name":"beenotung/tensorflow-helpers","owner":"beenotung","description":"Helper functions to use tensorflow in nodejs for transfer learning, image classification, and more","archived":false,"fork":false,"pushed_at":"2026-02-03T07:20:06.000Z","size":1006,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-03T20:12:33.426Z","etag":null,"topics":["classifier","deep-learning","embedding","feature-extration","helpers","image","neural-network","tensorflow","tensorflowjs","tfjs","transfer-learning","typescript","utility"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/tensorflow-helpers","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beenotung.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-10T07:52:14.000Z","updated_at":"2026-02-03T07:15:23.000Z","dependencies_parsed_at":"2024-08-10T14:28:13.500Z","dependency_job_id":"e9d41837-9512-4f3a-8d95-54e0df224d9c","html_url":"https://github.com/beenotung/tensorflow-helpers","commit_stats":null,"previous_names":["beenotung/tensorflow-helpers"],"tags_count":55,"template":false,"template_full_name":null,"purl":"pkg:github/beenotung/tensorflow-helpers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Ftensorflow-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Ftensorflow-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Ftensorflow-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Ftensorflow-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beenotung","download_url":"https://codeload.github.com/beenotung/tensorflow-helpers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Ftensorflow-helpers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29560804,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T21:50:49.831Z","status":"ssl_error","status_checked_at":"2026-02-17T21:46:15.313Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["classifier","deep-learning","embedding","feature-extration","helpers","image","neural-network","tensorflow","tensorflowjs","tfjs","transfer-learning","typescript","utility"],"created_at":"2025-01-01T05:39:33.837Z","updated_at":"2026-02-17T22:32:19.754Z","avatar_url":"https://github.com/beenotung.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tensorflow-helpers\n\nHelper functions to use tensorflow in nodejs/browser for transfer learning, image classification, and more.\n\n[![npm Package Version](https://img.shields.io/npm/v/tensorflow-helpers)](https://www.npmjs.com/package/tensorflow-helpers)\n\n## Features\n\n- Support transfer learning and continuous learning\n- Custom image classifier using embedding features from pre-trained image model\n- Extract both spatial and pooled features from image models\n- Correctly save/load model on filesystem[1]\n- Load image file into tensor with resize and crop\n- List varies pre-trained models (url, image dimension, embedding size)\n- Support both nodejs and browser environment\n- Support caching model and image embedding\n- CLI tool for downloading TensorFlow.js models from various sources\n- Interactive model topology visualization\n- Standard weightsManifest format support for better compatibility\n- Typescript support\n- Works with plain Javascript, Typescript is not mandatory\n\n[1]: The built-in `tf.loadGraphModel()` cannot load the model saved by `model.save()`\n\n## Model Artifacts Management\n\nModels now provide better access to their internal artifacts while maintaining backward compatibility:\n\n```typescript\n// The familiar classNames API still works (now uses getter/setter proxy)\nmodel.classNames = ['cat', 'dog', 'bird']\n\n// New: Direct access to model artifacts\nconst artifacts = model.getArtifacts()\n\n// Access classNames through the artifacts (standard TensorFlow.js format)\nconst classNames = artifacts.userDefinedMetadata?.classNames\n```\n\n## Installation\n\n```bash\nnpm install tensorflow-helpers\n```\n\nYou can also install `tensorflow-helpers` with [pnpm](https://pnpm.io/), [yarn](https://yarnpkg.com/), or [slnpm](https://github.com/beenotung/slnpm)\n\n## Development Scripts\n\nWhen working with the source code, the following scripts are available:\n\n```bash\n# Development\nnpm run dev          # Watch mode for browser testing\nnpm run dev:chart    # Watch mode for model visualization\n\n# Building\nnpm run bundle       # Build browser test bundle\nnpm run bundle:chart # Build chart visualization bundle\nnpm run build        # Build the library for distribution\n\n# Testing\nnpm run test         # TypeScript type checking\nnpm run clean        # Clean build artifacts\n```\n\n## Usage Example\n\nSee [model.test.ts](./model.test.ts) and [classifier.test.ts](./classifier.test.ts) for complete examples.\n\n**Quick Start**: Use the CLI tool to download models: `npx download-tfjs-model \u003csource\u003e \u003coutput-dir\u003e` (see [CLI Tool](#cli-tool) section for details).\n\n**Usage from browser**:\n\n```typescript\nimport {\n  loadImageModel,\n  getImageFeatures,\n  loadImageClassifierModel,\n  toOneTensor,\n} from 'tensorflow-helpers/browser'\n\ndeclare var fileInput: HTMLInputElement\n\nasync function main() {\n  let baseModel = await loadImageModel({\n    url: 'saved_model/mobilenet-v3-large-100',\n    cacheUrl: 'indexeddb://mobilenet-v3-large-100',\n    checkForUpdates: false,\n  })\n\n  let classifier = await loadImageClassifierModel({\n    baseModel,\n    classNames: ['anime', 'real', 'others'],\n    modelUrl: 'saved_model/emotion-classifier',\n    cacheUrl: 'indexeddb://emotion-classifier',\n  })\n\n  fileInput.onchange = async () =\u003e {\n    let file = fileInput.files?.[0]\n    if (!file) return\n\n    // Extract both spatial and pooled features\n    let features = await getImageFeatures({\n      tf,\n      imageModel: baseModel,\n      image: file,\n    })\n    console.log('spatial features shape:', features.spatialFeatures.shape) // [1, 7, 7, 160]\n    console.log('pooled features shape:', features.pooledFeatures.shape) // [1, 1280]\n\n    // Classify the image\n    let result = await classifier.classifyImageFile(file)\n    // classifyImageFile handles end-to-end classification: auto-resize image → extract features → classify\n    console.log('classification result:', result)\n    // result is Array\u003c{ label: string, confidence: number }\u003e - e.g. [{ label: 'anime', confidence: 0.8 }, ...]\n  }\n}\nmain().catch(e =\u003e console.error(e))\n```\n\n**Usage from nodejs**:\n\n```typescript\nimport {\n  loadImageModel,\n  PreTrainedImageModels,\n  getImageFeatures,\n  loadImageClassifierModel,\n  topClassifyResult,\n} from 'tensorflow-helpers'\n\n// Load pre-trained base model\nlet baseModel = await loadImageModel({\n  spec: PreTrainedImageModels.mobilenet['mobilenet-v3-large-100'],\n  dir: 'saved_model/base_model',\n})\nconsole.log('embedding features:', baseModel.spec.features)\n// [print] embedding features: 1280\n\n// Extract both spatial and pooled features\nlet features = await getImageFeatures({\n  tf,\n  imageModel: baseModel,\n  image: 'image.jpg',\n})\nconsole.log('spatial features shape:', features.spatialFeatures.shape) // [1, 7, 7, 160]\nconsole.log('pooled features shape:', features.pooledFeatures.shape) // [1, 1280]\n\n// Create classifier for image classification\nlet classifier = await loadImageClassifierModel({\n  baseModel,\n  modelDir: 'saved_model/classifier_model',\n  hiddenLayers: [128],\n  datasetDir: 'dataset',\n  // classNames: ['anime', 'real', 'others'], // auto scan from datasetDir\n})\n\n// auto load training dataset\nlet history = await classifier.train({\n  epochs: 5,\n  batchSize: 32,\n})\n\n// persist the parameters across restart\nawait classifier.save()\n\n// auto load image from filesystem, resize and crop\nlet classes = await classifier.classifyImageFile('image.jpg')\nlet topClass = topClassifyResult(classes)\n\nconsole.log('result:', topClass)\n// [print] result: { label: 'anime', confidence: 0.7991582155227661 }\n```\n\n## Model Visualization (Local Development)\n\nInteractive model topology visualization for analyzing model structure and selecting feature extraction points:\n\n```bash\n# Start the visualization development server\nnpm run dev:chart\n\n# Open chart.html in your browser to visualize model topology\n```\n\n**Note**: This feature is currently only available for local development due to CORS restrictions. A hosted version is not available at this time.\n\n**Main Purpose**:\n\n- **Model Topology Analysis**: Visualize the complete graph of model nodes and their connections\n- **Feature Selection**: Identify optimal nodes to tap into for extracting intermediate features (spatial features, embeddings, etc.)\n- **Shape Inspection**: See the tensor shapes at each node to understand data flow through the model\n\n**Features**:\n\n- Interactive node exploration with hover and click-to-lock functionality\n- Visual connections showing data flow between layers\n- Node details including operation type and tensor shapes\n- Support for various model formats (GraphModel, LayersModel)\n\n## Typescript Signature\n\nDetails see the type hints from IDE.\n\n\u003cdetails\u003e\n\u003csummary\u003eShortcut to tensorflow\u003c/summary\u003e\n\nexported as `'tensorflow-helpers'`:\n\n```typescript\nimport * as tfjs from '@tensorflow/tfjs-node'\n\nexport let tensorflow: typeof tfjs\nexport let tf: typeof tfjs\n```\n\nexported as `'tensorflow-helpers/browser'`:\n\n```typescript\nimport * as tfjs from '@tensorflow/tfjs'\n\nexport let tensorflow: typeof tfjs\nexport let tf: typeof tfjs\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003ePre-trained model constants\u003c/summary\u003e\n\n```typescript\nexport const PreTrainedImageModels: {\n  mobilenet: {\n    'mobilenet-v3-large-100': {\n      url: 'https://www.kaggle.com/models/google/mobilenet-v3/TfJs/large-100-224-feature-vector/1'\n      width: 224\n      height: 224\n      channels: 3\n      features: 1280\n    }\n    // more models omitted ...\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eModel helper functions\u003c/summary\u003e\n\n```typescript\nexport type Model = tf.GraphModel | tf.LayersModel\n\nexport function saveModel(options: {\n  model: Model\n  dir: string\n}): Promise\u003cSaveResult\u003e\n\nexport function loadGraphModel(options: { dir: string }): Promise\u003ctf.GraphModel\u003e\n\nexport function loadLayersModel(options: {\n  dir: string\n}): Promise\u003ctf.LayersModel\u003e\n\nexport function cachedLoadGraphModel(options: {\n  url: string\n  dir: string\n}): Promise\u003cModel\u003e\n\nexport function cachedLoadLayersModel(options: {\n  url: string\n  dir: string\n}): Promise\u003cModel\u003e\n\n// Model artifacts management\nexport function getModelArtifacts\u003cModel extends object\u003e(\n  model: Model,\n): PatchedModelArtifacts\n\nexport function exposeModelArtifacts\u003cModel extends object\u003e(\n  model: Model,\n): Model \u0026 {\n  getArtifacts: () =\u003e PatchedModelArtifacts\n  classNames?: string[]\n}\n\nexport type PatchedModelArtifacts = ModelJSON \u0026\n  Pick\u003cModelArtifacts, 'weightData' | 'weightSpecs'\u003e \u0026 {\n    userDefinedMetadata?: {\n      classNames?: string[]\n    }\n  }\n\nexport function loadImageModel(options: {\n  spec: ImageModelSpec\n  dir: string\n  aspectRatio?: CropAndResizeAspectRatio\n  cache?: EmbeddingCache | boolean\n}): Promise\u003cImageModel\u003e\n\nexport type EmbeddingCache = {\n  get(filename: string): number[] | null | undefined\n  set(filename: string, values: number[]): void\n}\n\nexport type ImageModelSpec = {\n  url: string\n  width: number\n  height: number\n  channels: number\n  features: number\n}\n\nexport type ImageModel = {\n  spec: ImageModelSpec\n  model: Model\n\n  fileEmbeddingCache: Map\u003cstring, tf.Tensor\u003e | null\n  checkCache(file_or_filename: string): tf.Tensor | void\n\n  loadImageCropped(\n    file: string,\n    options?: {\n      expandAnimations?: boolean\n    },\n  ): Promise\u003ctf.Tensor3D | tf.Tensor4D\u003e\n\n  imageFileToEmbedding(\n    file: string,\n    options?: {\n      expandAnimations?: boolean\n    },\n  ): Promise\u003ctf.Tensor\u003e\n\n  imageTensorToEmbedding(imageTensor: tf.Tensor3D | tf.Tensor4D): tf.Tensor\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eImage helper functions and types\u003c/summary\u003e\n\n```typescript\nexport function loadImageFile(\n  file: string,\n  options?: {\n    channels?: number\n    dtype?: string\n    expandAnimations?: boolean\n    crop?: {\n      width: number\n      height: number\n      aspectRatio?: CropAndResizeAspectRatio\n    }\n  },\n): Promise\u003ctf.Tensor3D | tf.Tensor4D\u003e\n\nexport type ImageTensor = tf.Tensor3D | tf.Tensor4D\n\nexport function getImageTensorShape(imageTensor: tf.Tensor3D | tf.Tensor4D): {\n  width: number\n  height: number\n}\n\nexport type Box = [top: number, left: number, bottom: number, right: number]\n\n/**\n * @description calculate center-crop box\n * @returns [top,left,bottom,right], values range: 0..1\n */\nexport function calcCropBox(options: {\n  sourceShape: { width: number; height: number }\n  targetShape: { width: number; height: number }\n}): Box\n\n/**\n * @description default is 'rescale'\n *\n * 'rescale' -\u003e scratch/transform to target shape;\n *\n * 'center-crop' -\u003e crop the edges, maintain aspect ratio at center\n */\nexport type CropAndResizeAspectRatio = 'rescale' | 'center-crop'\n\nexport function cropAndResizeImageTensor(options: {\n  imageTensor: tf.Tensor3D | tf.Tensor4D\n  width: number\n  height: number\n  aspectRatio?: CropAndResizeAspectRatio\n}): tf.Tensor4D\n\nexport function cropAndResizeImageFile(options: {\n  srcFile: string\n  destFile: string\n  width: number\n  height: number\n  aspectRatio?: CropAndResizeAspectRatio\n}): Promise\u003cvoid\u003e\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eTensor helper functions\u003c/summary\u003e\n\n```typescript\nexport function disposeTensor(tensor: tf.Tensor | tf.Tensor[]): void\n\nexport function toOneTensor(\n  tensor: tf.Tensor | tf.Tensor[] | tf.NamedTensorMap,\n): tf.Tensor\n\nexport function toTensor4D(tensor: tf.Tensor3D | tf.Tensor4D): tf.Tensor4D\n\nexport function toTensor3D(tensor: tf.Tensor3D | tf.Tensor4D): tf.Tensor3D\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eClassifier helper functions\u003c/summary\u003e\n\n```typescript\nexport type ClassifierModelSpec = {\n  embeddingFeatures: number\n  hiddenLayers?: number[]\n  classes: number\n}\n\nexport function createImageClassifier(spec: ClassifierModelSpec): tf.Sequential\n\nexport type ClassificationResult = {\n  label: string\n  /** @description between 0 to 1 */\n  confidence: number\n}\n\nexport type ClassifierModel = {\n  baseModel: {\n    spec: ImageModelSpec\n    model: Model\n    loadImageAsync: (file: string) =\u003e Promise\u003ctf.Tensor4D\u003e\n    loadImageSync: (file: string) =\u003e tf.Tensor4D\n    loadAnimatedImageAsync: (file: string) =\u003e Promise\u003ctf.Tensor4D\u003e\n    loadAnimatedImageSync: (file: string) =\u003e tf.Tensor4D\n    inferEmbeddingAsync: (\n      file_or_image_tensor: string | tf.Tensor,\n    ) =\u003e Promise\u003ctf.Tensor\u003e\n    inferEmbeddingSync: (file_or_image_tensor: string | tf.Tensor) =\u003e tf.Tensor\n  }\n  classifierModel: tf.LayersModel | tf.Sequential\n  classNames: string[]\n  classifyAsync: (\n    file_or_image_tensor: string | tf.Tensor,\n  ) =\u003e Promise\u003cClassificationResult[]\u003e\n  classifySync: (\n    file_or_image_tensor: string | tf.Tensor,\n  ) =\u003e ClassificationResult[]\n  loadDatasetFromDirectoryAsync: () =\u003e Promise\u003c{\n    x: tf.Tensor\u003ctf.Rank\u003e\n    y: tf.Tensor\u003ctf.Rank\u003e\n  }\u003e\n  compile: () =\u003e void\n  train: (options?: tf.ModelFitArgs) =\u003e Promise\u003ctf.History\u003e\n  save: (dir?: string) =\u003e Promise\u003cSaveResult\u003e\n}\n\nexport function loadImageClassifierModel(options: {\n  baseModel: ImageModel\n  hiddenLayers?: number[]\n  modelDir: string\n  datasetDir: string\n  classNames?: string[]\n}): Promise\u003cClassifierModel\u003e\n\nexport function topClassifyResult(\n  items: ClassificationResult[],\n): ClassificationResult\n\n/**\n * @description the values is returned as is.\n * It should has be applied softmax already\n * */\nexport function mapWithClassName(\n  classNames: string[],\n  values: ArrayLike\u003cnumber\u003e,\n  options?: {\n    sort?: boolean\n  },\n): ClassificationResult[]\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eFeature extraction functions\u003c/summary\u003e\n\n```typescript\nexport async function getImageFeatures(options: {\n  tf: typeof import('@tensorflow/tfjs-node')\n  imageModel: ImageModel\n  image: string | Tensor\n  /** default: 'Identity:0' */\n  outputNode?: string\n}): Promise\u003c{\n  spatialFeatures: Tensor // e.g. [1, 7, 7, 160] - spatial feature map\n  pooledFeatures: Tensor // e.g. [1, 1280] - global average pooled features\n}\u003e\n\n/**\n * @description Get the name of the last spatial node in the model\n * Used internally by getImageFeatures to extract spatial features\n */\nexport function getLastSpatialNodeName(model: GraphModel): string\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eModel helper functions\u003c/summary\u003e\n\n```typescript\n/**\n * A factor to give larger hidden layer size for complex tasks:\n * - 1 for easy tasks\n * - 2-3 for medium difficulty tasks\n * - 4-5 for complex tasks\n *\n * Remark: giving too high difficulty may result in over-fitting.\n */\nexport type Difficulty = number\n\n/** Formula `hiddenSize = difficulty * sqrt(inputSize * outputSize)` */\nexport function calcHiddenLayerSize(options: {\n  inputSize: number\n  outputSize: number\n  difficulty?: Difficulty\n})\n\n/** Inject one or more hidden layers that's having large gap between input size and output size. */\nexport function injectHiddenLayers(options: {\n  layers: number[]\n  difficulty?: Difficulty\n  numberOfHiddenLayers?: number\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eFile helper functions\u003c/summary\u003e\n\n```typescript\n/**\n * @description\n * - rename filename to content hash + extname;\n * - return list of (renamed) filenames\n */\nexport async function scanDir(dir: string): Promise\u003cstring[]\u003e\n\nexport function isContentHash(file_or_filename: string): boolean\n\nexport async function saveFile(args: {\n  dir: string\n  content: Buffer\n  mimeType: string\n}): Promise\u003cvoid\u003e\n\nexport function hashContent(\n  content: Buffer,\n  encoding: BufferEncoding = 'hex',\n): string\n\n/** @returns new filename with content hash and extname */\nexport async function renameFileByContentHash(file: string): Promise\u003cstring\u003e\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eCLI Tool\u003c/summary\u003e\n\nThe package includes a command-line tool for downloading and converting TensorFlow.js models:\n\n```bash\n# Usage\nnpx download-tfjs-model \u003csource\u003e \u003coutput-dir\u003e\n\n# Examples\nnpx download-tfjs-model https://www.kaggle.com/models/google/mobilenet-v3/TfJs/large-100-224-feature-vector/1 ./browser-models/mobilenet-v3-large-100\nnpx download-tfjs-model ./hub-models/mobilenet-v2-035-128-feature-vector ./browser-models/mobilenet-v2-035\n```\n\n**Supported sources:**\n\n- TensorFlow Hub URLs\n- Kaggle model URLs\n- Local model directories\n- Local model.json files\n\n**Features:**\n\n- Automatic model format detection (GraphModel vs LayersModel)\n- Standard weightsManifest format conversion\n- Source metadata preservation\n- Recursive directory creation\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e(Browser version) model functions and types\u003c/summary\u003e\n\n````typescript\n/**\n * @example `loadGraphModel({ url: 'saved_model/mobilenet-v3-large-100' })`\n */\nexport function loadGraphModel(options: { url: string }): Promise\u003ctf.GraphModel\u003e\n\n/**\n * @example `loadGraphModel({ url: 'saved_model/emotion-classifier' })`\n */\nexport function loadLayersModel(options: {\n  url: string\n}): Promise\u003ctf.LayersModel\u003e\n\n/**\n * @example ```\n * cachedLoadGraphModel({\n *   url: 'saved_model/mobilenet-v3-large-100',\n *   cacheUrl: 'indexeddb://mobilenet-v3-large-100',\n * })\n * ```\n */\nexport function cachedLoadGraphModel(options: {\n  url: string\n  cacheUrl: string\n  checkForUpdates?: boolean\n}): Promise\u003ctf.GraphModel\u003cstring | tf.io.IOHandler\u003e\u003e\n\n/**\n * @example ```\n * cachedLoadLayersModel({\n *   url: 'saved_model/emotion-classifier',\n *   cacheUrl: 'indexeddb://emotion-classifier',\n * })\n * ```\n */\nexport function cachedLoadLayersModel(options: {\n  url: string\n  cacheUrl: string\n  checkForUpdates?: boolean\n}): Promise\u003ctf.LayersModel\u003e\n````\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e(Browser version) image model functions and types\u003c/summary\u003e\n\n```typescript\nexport type ImageModel = {\n  spec: ImageModelSpec\n  model: tf.GraphModel\u003cstring | tf.io.IOHandler\u003e\n  fileEmbeddingCache: Map\u003cstring, tf.Tensor\u003ctf.Rank\u003e\u003e | null\n  checkCache: (url: string) =\u003e tf.Tensor | void\n  loadImageCropped: (url: string) =\u003e Promise\u003ctf.Tensor4D \u0026 tf.Tensor\u003ctf.Rank\u003e\u003e\n  imageUrlToEmbedding: (url: string) =\u003e Promise\u003ctf.Tensor\u003e\n  imageFileToEmbedding: (file: File) =\u003e Promise\u003ctf.Tensor\u003e\n  imageTensorToEmbedding: (imageTensor: ImageTensor) =\u003e tf.Tensor\n}\n\n/**\n * @description cache image embedding keyed by filename.\n * The dirname is ignored.\n * The filename is expected to be content hash (w/wo extname)\n */\nexport type EmbeddingCache = {\n  get(url: string): number[] | null | undefined\n  set(url: string, values: number[]): void\n}\n\nexport function loadImageModel\u003cCache extends EmbeddingCache\u003e(options: {\n  url: string\n  cacheUrl?: string\n  checkForUpdates?: boolean\n  aspectRatio?: CropAndResizeAspectRatio\n  cache?: Cache | boolean\n}): Promise\u003cImageModel\u003e\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e(Browser version) classifier functions and types\u003c/summary\u003e\n\n```typescript\nexport type ClassifierModel = {\n  baseModel: ImageModel\n  classifierModel: tf.LayersModel | tf.Sequential\n  classNames: string[]\n  classifyImageUrl(url: string): Promise\u003cClassificationResult[]\u003e\n  classifyImageFile(file: File): Promise\u003cClassificationResult[]\u003e\n  classifyImageTensor(\n    imageTensor: tf.Tensor3D | tf.Tensor4D,\n  ): Promise\u003cClassificationResult[]\u003e\n  classifyImage(\n    image: Parameters\u003ctypeof tf.browser.fromPixels\u003e[0],\n  ): Promise\u003cClassificationResult[]\u003e\n  classifyImageEmbedding(embedding: tf.Tensor): Promise\u003cClassificationResult[]\u003e\n  compile(): void\n  train(\n    options: tf.ModelFitArgs \u0026 {\n      x: tf.Tensor\u003ctf.Rank\u003e\n      y: tf.Tensor\u003ctf.Rank\u003e\n      /** @description to calculate classWeight */\n      classCounts?: number[]\n    },\n  ): Promise\u003ctf.History\u003e\n}\n\nexport function loadImageClassifierModel(options: {\n  baseModel: ImageModel\n  hiddenLayers?: number[]\n  modelUrl?: string\n  cacheUrl?: string\n  checkForUpdates?: boolean\n  classNames: string[]\n}): Promise\u003cClassifierModel\u003e\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e(Browser version) feature extraction functions\u003c/summary\u003e\n\n````typescript\nexport async function getImageFeatures(options: {\n  tf: typeof import('@tensorflow/tfjs-core')\n  imageModel: ImageModel\n  image: string | Tensor\n  /** default: 'Identity:0' */\n  outputNode?: string\n  /** default: getLastSpatialNodeName(model) */\n  spatialNode?: node\n}): Promise\u003c{\n  /** e.g. `[1 x 7 x 7 x 160]` spatial feature map */\n  spatialFeatures: Tensor\n  /** e.g. `[1 x 1280]` global average pooled features */\n  pooledFeatures: Tensor\n}\u003e\nexport async function getImageFeatures(options: {\n  tf: typeof import('@tensorflow/tfjs-core')\n  imageModel: ImageModel\n  image: string | Tensor\n  /** default: 'Identity:0' */\n  outputNode?: string\n  /** e.g. `imageModel.spatialNodesWithUniqueShapes` */\n  spatialNodes: node[]\n}): Promise\u003c{\n  /** list of spatial feature maps\n   * e.g.\n   * ```\n   * [\n   *   [1 x 56 x 56 x 24],\n   *   [1 x 28 x 28 x 40],\n   *   [1 x 14 x 14 x 80],\n   *   [1 x 14 x 14 x 112],\n   *   [1 x 7 x 7 x 160],\n   * ]\n   * ```\n   *  */\n  spatialFeatures: Tensor[]\n  /** e.g. `[1 x 1280]` global average pooled features */\n  pooledFeatures: Tensor\n}\u003e\n````\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeenotung%2Ftensorflow-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeenotung%2Ftensorflow-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeenotung%2Ftensorflow-helpers/lists"}