tensorflow-helpers
Version:
Helper functions to use tensorflow in nodejs for transfer learning, image classification, and more
43 lines (42 loc) • 1.97 kB
TypeScript
import * as tf from '@tensorflow/tfjs';
import { ImageModel } from './model';
import { 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<string | tf.io.IOHandler>;
fileEmbeddingCache: Map<string, tf.Tensor<tf.Rank>> | null;
checkCache: (url: string) => tf.Tensor | void;
loadImageCropped: (url: string) => Promise<tf.Tensor4D & tf.Tensor<tf.Rank>>;
imageUrlToEmbedding: (url: string) => Promise<tf.Tensor>;
imageFileToEmbedding: (file: File) => Promise<tf.Tensor>;
imageTensorToEmbedding: (imageTensor: import("..").ImageTensor) => tf.Tensor;
};
classifierModel: (tf.Sequential & {
classNames?: string[];
}) | (tf.LayersModel & {
classNames?: string[];
});
classNames: string[];
classifyImageUrl: (url: string) => Promise<ClassificationResult[]>;
classifyImageFile: (file: File) => Promise<ClassificationResult[]>;
classifyImageTensor: (imageTensor: tf.Tensor3D | tf.Tensor4D) => Promise<ClassificationResult[]>;
classifyImage: (image: Parameters<typeof tf.browser.fromPixels>[0]) => Promise<ClassificationResult[]>;
classifyImageEmbedding: (embedding: tf.Tensor) => 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>;
}>;