From c8396949852bb485784bfbf4269344d5f7821415 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Thu, 5 Oct 2023 07:18:17 -0400 Subject: [PATCH] Fix entry points --- models/default-model/src/umd.ts | 1 + models/default-model/tsconfig.cjs.json | 2 +- models/default-model/tsconfig.esm.json | 2 +- models/default-model/tsconfig.umd.json | 2 +- packages/shared/src/esrgan/esrgan.d.ts | 12 ++ packages/shared/src/esrgan/esrgan.d.ts.map | 1 + packages/shared/src/esrgan/esrgan.js | 123 +++++++++++++++++++++ packages/shared/src/types.d.ts | 53 +++++++++ packages/shared/src/types.d.ts.map | 1 + packages/shared/src/types.js | 9 ++ 10 files changed, 203 insertions(+), 3 deletions(-) create mode 100644 models/default-model/src/umd.ts create mode 100644 packages/shared/src/esrgan/esrgan.d.ts create mode 100644 packages/shared/src/esrgan/esrgan.d.ts.map create mode 100644 packages/shared/src/esrgan/esrgan.js create mode 100644 packages/shared/src/types.d.ts create mode 100644 packages/shared/src/types.d.ts.map create mode 100644 packages/shared/src/types.js diff --git a/models/default-model/src/umd.ts b/models/default-model/src/umd.ts new file mode 100644 index 000000000..a7f38e858 --- /dev/null +++ b/models/default-model/src/umd.ts @@ -0,0 +1 @@ +export { default as default, } from '.'; diff --git a/models/default-model/tsconfig.cjs.json b/models/default-model/tsconfig.cjs.json index f979f1b58..a5fc66d4c 100644 --- a/models/default-model/tsconfig.cjs.json +++ b/models/default-model/tsconfig.cjs.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.cjs.json", "include": [ - "./src/index.ts", + "./src/cjs.ts", ] } diff --git a/models/default-model/tsconfig.esm.json b/models/default-model/tsconfig.esm.json index 0b8c130e4..c74e5dca1 100644 --- a/models/default-model/tsconfig.esm.json +++ b/models/default-model/tsconfig.esm.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.esm.json", "include": [ - "./src/index.ts", + "./src/esm.ts", ] } diff --git a/models/default-model/tsconfig.umd.json b/models/default-model/tsconfig.umd.json index 7d7e0b242..666c3772f 100644 --- a/models/default-model/tsconfig.umd.json +++ b/models/default-model/tsconfig.umd.json @@ -1,6 +1,6 @@ { "extends": "../tsconfig.umd.json", "include": [ - "./src/index.ts", + "./src/umd.ts", ] } diff --git a/packages/shared/src/esrgan/esrgan.d.ts b/packages/shared/src/esrgan/esrgan.d.ts new file mode 100644 index 000000000..672bd02aa --- /dev/null +++ b/packages/shared/src/esrgan/esrgan.d.ts @@ -0,0 +1,12 @@ +import type { Meta, ModelDefinition } from '../types'; +import type { Tensor4D } from '@tensorflow/tfjs-core'; +export type Inputs = Tensor4D | Tensor4D[]; +export type Scale = 2 | 3 | 4 | 8; +export declare const getESRGANModelDefinition: ({ scale, name, version, meta: { architecture, ...meta }, path: modelPath, }: { + name: string; + version: string; + scale: Scale; + meta: Meta; + path?: string | undefined; +}) => ModelDefinition; +//# sourceMappingURL=esrgan.d.ts.map \ No newline at end of file diff --git a/packages/shared/src/esrgan/esrgan.d.ts.map b/packages/shared/src/esrgan/esrgan.d.ts.map new file mode 100644 index 000000000..a72efce94 --- /dev/null +++ b/packages/shared/src/esrgan/esrgan.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"esrgan.d.ts","sourceRoot":"","sources":["esrgan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAS,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAG,MAAM,uBAAuB,CAAC;AAEvD,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAC;AAE3C,MAAM,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAclC,eAAO,MAAM,wBAAwB;UAU7B,MAAM;aACH,MAAM;WACR,KAAK;UACN,IAAI;;MAER,eAsFH,CAAC"} \ No newline at end of file diff --git a/packages/shared/src/esrgan/esrgan.js b/packages/shared/src/esrgan/esrgan.js new file mode 100644 index 000000000..4147c4038 --- /dev/null +++ b/packages/shared/src/esrgan/esrgan.js @@ -0,0 +1,123 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getESRGANModelDefinition = void 0; +var isTensorArray = function (inputs) { + return Array.isArray(inputs); +}; +var getInput = function (inputs) { + if (isTensorArray(inputs)) { + return inputs[0]; + } + return inputs; +}; +var getESRGANModelDefinition = function (_a) { + var scale = _a.scale, name = _a.name, version = _a.version, _b = _a.meta, architecture = _b.architecture, meta = __rest(_b, ["architecture"]), modelPath = _a.path; + var path = modelPath || "models/".concat(scale, "x/model.json"); + if (architecture === 'rdn') { + return { + scale: scale, + modelType: 'layers', + _internals: { + path: path, + name: name, + version: version, + }, + meta: __assign({ architecture: architecture }, meta), + inputRange: [0, 255,], + outputRange: [0, 255,], + }; + } + var setup = function (tf) { + var Layer = tf.layers.Layer; + var BETA = 0.2; + var MultiplyBeta = (function (_super) { + __extends(MultiplyBeta, _super); + function MultiplyBeta() { + var _this = _super.call(this, {}) || this; + _this.beta = BETA; + return _this; + } + MultiplyBeta.prototype.call = function (inputs) { + return tf.mul(getInput(inputs), this.beta); + }; + MultiplyBeta.className = 'MultiplyBeta'; + return MultiplyBeta; + }(Layer)); + var getPixelShuffle = function (_scale) { + var PixelShuffle = (function (_super) { + __extends(PixelShuffle, _super); + function PixelShuffle() { + var _this = _super.call(this, {}) || this; + _this.scale = _scale; + return _this; + } + PixelShuffle.prototype.computeOutputShape = function (inputShape) { + return [inputShape[0], inputShape[1], inputShape[2], 3,]; + }; + PixelShuffle.prototype.call = function (inputs) { + return tf.depthToSpace(getInput(inputs), this.scale, 'NHWC'); + }; + PixelShuffle.className = "PixelShuffle".concat(scale, "x"); + return PixelShuffle; + }(Layer)); + return PixelShuffle; + }; + [ + MultiplyBeta, + getPixelShuffle(scale), + ].forEach(function (layer) { + tf.serialization.registerClass(layer); + }); + }; + return { + setup: setup, + scale: scale, + modelType: 'layers', + _internals: { + path: path, + name: name, + version: version, + }, + meta: __assign({ architecture: architecture }, meta), + inputRange: [0, 1,], + outputRange: [0, 1,], + }; +}; +exports.getESRGANModelDefinition = getESRGANModelDefinition; diff --git a/packages/shared/src/types.d.ts b/packages/shared/src/types.d.ts new file mode 100644 index 000000000..aa85f256a --- /dev/null +++ b/packages/shared/src/types.d.ts @@ -0,0 +1,53 @@ +import * as tf from '@tensorflow/tfjs-core'; +import type * as tfBrowser from '@tensorflow/tfjs'; +import type * as tfNode from '@tensorflow/tfjs-node'; +import type * as tfNodeGpu from '@tensorflow/tfjs-node-gpu'; +import { Tensor, Tensor4D } from '@tensorflow/tfjs-core'; +export type TF = typeof tfBrowser | typeof tfNode | typeof tfNodeGpu; +export type TFN = typeof tfNode | typeof tfNodeGpu; +export type OpExecutor = tfBrowser.OpExecutor | tfNode.OpExecutor | tfNodeGpu.OpExecutor; +export type GraphModel = tfBrowser.GraphModel | tfNode.GraphModel | tfNodeGpu.GraphModel; +export type ProcessFn = (t: T) => T; +export interface ModelConfigurationInternals { + name: string; + version: string; + path: string; +} +export type Range = [number, number]; +type MetaValue = string | number | Meta | null | undefined | boolean; +export type Meta = { + [key: string]: MetaValue; +}; +export type ModelType = 'graph' | 'layers'; +export type PreProcess = ProcessFn; +export type PostProcess = ProcessFn; +export type FixedShape4D = [null | number, number, number, number]; +export type DynamicShape4D = [null | number, null, null, number]; +export type Shape4D = FixedShape4D | DynamicShape4D; +export type Setup = (tf: TF) => (void | Promise); +export type Teardown = (tf: TF) => (void | Promise); +export interface ModelDefinition { + modelType?: ModelType; + path?: string; + scale?: number; + channels?: 3; + _internals?: ModelConfigurationInternals; + preprocess?: PreProcess; + postprocess?: PostProcess; + inputRange?: Range; + outputRange?: Range; + divisibilityFactor?: number; + meta?: Meta; + setup?: Setup; + teardown?: Teardown; +} +export type ModelDefinitionFn = (tf: TF) => ModelDefinition; +export type ModelDefinitionObjectOrFn = ModelDefinitionFn | ModelDefinition; +export type IsTensor = (pixels: Tensor) => pixels is T; +export declare enum MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE { + UNDEFINED = "undefined", + INVALID_MODEL_TYPE = "invalidModelType", + MISSING_PATH = "missingPath" +} +export {}; +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/packages/shared/src/types.d.ts.map b/packages/shared/src/types.d.ts.map new file mode 100644 index 000000000..f3a207a3b --- /dev/null +++ b/packages/shared/src/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,KAAK,KAAK,SAAS,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,KAAK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kBAAkB,qBAAqB;IACvC,YAAY,gBAAgB;CAC7B"} \ No newline at end of file diff --git a/packages/shared/src/types.js b/packages/shared/src/types.js new file mode 100644 index 000000000..72c0cc696 --- /dev/null +++ b/packages/shared/src/types.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE = void 0; +var MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE; +(function (MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE) { + MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE["UNDEFINED"] = "undefined"; + MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE["INVALID_MODEL_TYPE"] = "invalidModelType"; + MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE["MISSING_PATH"] = "missingPath"; +})(MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE || (exports.MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE = MODEL_DEFINITION_VALIDATION_CHECK_ERROR_TYPE = {}));