tensorflow-helpers
Version:
Helper functions to use tensorflow in nodejs for transfer learning, image classification, and more
48 lines (47 loc) • 2.61 kB
TypeScript
import * as tf from '@tensorflow/tfjs';
import { ImageModel } from './model';
import { ClassificationOptions, ClassificationResult } from '../classifier-utils';
export type ClassifierModel = Awaited<ReturnType<typeof loadImageClassifierModel>>;
export declare function loadImageClassifierModel(options: {
baseModel: ImageModel;
hiddenLayers?: number[];
modelUrl?: string;
cacheUrl?: string;
checkForUpdates?: boolean;
/** @description if not provided, will be auto scanned from datasetDir or load from the model.json */
classNames?: string[];
}): Promise<{
baseModel: {
spec: import("..").ImageModelSpec;
model: tf.GraphModel<tf.io.IOHandler> & {
getArtifacts: () => import("../model-artifacts").PatchedModelArtifacts;
classNames?: string[];
};
fileEmbeddingCache: Map<string, tf.Tensor<tf.Rank>> | null;
checkCache: (url: string) => tf.Tensor | void;
loadImageCropped: (image_or_url: import("./model").ImageOrUrl) => Promise<tf.Tensor4D & tf.Tensor<tf.Rank>>;
imageUrlToEmbedding: (url: string, options?: import("..").ImageEmbeddingOptions) => Promise<tf.Tensor>;
imageFileToEmbedding: (file: File, options?: import("..").ImageEmbeddingOptions) => Promise<tf.Tensor>;
imageTensorToEmbedding: (imageTensor: import("..").ImageTensor, options?: import("..").ImageEmbeddingOptions) => tf.Tensor;
};
classifierModel: (tf.Sequential & {
getArtifacts: () => import("../model-artifacts").PatchedModelArtifacts;
classNames?: string[];
}) | (tf.LayersModel & {
getArtifacts: () => import("../model-artifacts").PatchedModelArtifacts;
classNames?: string[];
});
classNames: string[];
classifyImageUrl: (url: string, options?: ClassificationOptions) => Promise<ClassificationResult[]>;
classifyImageFile: (file: File, options?: ClassificationOptions) => Promise<ClassificationResult[]>;
classifyImageTensor: (imageTensor: tf.Tensor3D | tf.Tensor4D, options?: ClassificationOptions) => Promise<ClassificationResult[]>;
classifyImage: (image: Parameters<typeof tf.browser.fromPixels>[0], options?: ClassificationOptions) => Promise<ClassificationResult[]>;
classifyImageEmbedding: (embedding: tf.Tensor, options?: ClassificationOptions) => Promise<ClassificationResult[]>;
compile: () => void;
train: (options: tf.ModelFitArgs & {
x: tf.Tensor<tf.Rank>;
y: tf.Tensor<tf.Rank>;
/** @description to calculate classWeight */
classCounts?: number[];
}) => Promise<tf.History>;
}>;