Skip to content

Commit

Permalink
Refactor models to use new layout (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinscott authored Oct 8, 2023
1 parent fb9b775 commit 22acf94
Show file tree
Hide file tree
Showing 186 changed files with 1,330 additions and 1,162 deletions.
42 changes: 12 additions & 30 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,11 @@ jobs:
with:
node-version: 16

- name: 'Build Models'
run: pnpm test:integration:browserstack -- --ci --verbose --skipTest --skipUpscalerBuild --skipBundle

- name: 'Bundle'
run: pnpm test:integration:browserstack -- --ci --verbose --skipTest --skipUpscalerBuild --skipModelBuild
run: pnpm test:integration:browserstack -- --ci --verbose --skip-test

- name: 'Integration Tests'
run: pnpm test:integration:browserstack -- --ci --verbose --skipUpscalerBuild --skipModelBuild --skipBundle
run: pnpm test:integration:browserstack -- --ci --verbose --skip-bundle
env:
NODE_OPTIONS: --max_old_space_size=8192

Expand All @@ -178,14 +175,11 @@ jobs:
with:
node-version: 16

- name: 'Build Models'
run: pnpm test:integration:browser -- --ci --verbose --skipTest --skipUpscalerBuild --skipBundle

- name: 'Bundle'
run: pnpm test:integration:browser -- --ci --verbose --skipTest --skipUpscalerBuild --skipModelBuild
run: pnpm test:integration:browser -- --ci --verbose --skip-test

- name: 'Integration Tests'
run: pnpm test:integration:browser -- --ci --verbose --skipUpscalerBuild --skipModelBuild --skipBundle
run: pnpm test:integration:browser -- --ci --verbose --skip-bundle
env:
NODE_OPTIONS: --max_old_space_size=8192

Expand All @@ -203,14 +197,11 @@ jobs:
with:
node-version: 16

- name: 'Build Models'
run: pnpm test:integration:node -- --ci --verbose --skipTest --skipUpscalerBuild --skipBundle

- name: 'Bundle'
run: pnpm test:integration:node -- --ci --verbose --skipTest --skipUpscalerBuild --skipModelBuild
run: pnpm test:integration:node -- --ci --verbose --skip-test

- name: 'Integration Tests'
run: pnpm test:integration:node -- --ci --verbose --skipUpscalerBuild --skipModelBuild --skipBundle
run: pnpm test:integration:node -- --ci --verbose --skip-bundle

integration-models-browser:
name: 'Models / Browser'
Expand All @@ -234,14 +225,11 @@ jobs:
# with:
# detached: true

- name: 'Build Models'
run: pnpm test:model -- --ci --verbose --skipTest --skipUpscalerBuild --skipBundle

- name: 'Bundle'
run: pnpm test:model -- --ci --verbose --skipTest --skipUpscalerBuild --skipModelBuild
run: pnpm test:model -- --ci --verbose --skip-test

- name: 'Integration Tests'
run: pnpm test:model -- --platform browser --ci --verbose --skipUpscalerBuild --skipModelBuild --skipBundle
run: pnpm test:model -- --platform browser --ci --verbose --skip-bundle

integration-models-node:
name: 'Models / Node'
Expand All @@ -257,14 +245,11 @@ jobs:
with:
node-version: 16

- name: 'Build Models'
run: pnpm test:model -- --ci --verbose --skipTest --skipUpscalerBuild --skipBundle

- name: 'Bundle'
run: pnpm test:model -- --ci --verbose --skipTest --skipUpscalerBuild --skipModelBuild
run: pnpm test:model -- --ci --verbose --skip-test

- name: 'Integration Tests'
run: pnpm test:model -- --platform node --ci --verbose --skipUpscalerBuild --skipModelBuild --skipBundle
run: pnpm test:model -- --platform node --ci --verbose --skip-bundle

memory-leaks:
name: 'Memory Leaks'
Expand All @@ -280,14 +265,11 @@ jobs:
with:
node-version: 16

- name: 'Build Models'
run: pnpm test:memory-leaks -- --ci --verbose --skipTest --skipUpscalerBuild --skipBundle

- name: 'Bundle'
run: pnpm test:memory-leaks -- --ci --verbose --skipTest --skipUpscalerBuild --skipModelBuild
run: pnpm test:memory-leaks -- --ci --verbose --skip-test

- name: 'Memory Leak Tests'
run: pnpm test:memory-leaks -- --ci --verbose --skipUpscalerBuild --skipModelBuild --skipBundle
run: pnpm test:memory-leaks -- --ci --verbose --skip-bundle

build-docs:
name: 'Build Documentation'
Expand Down
2 changes: 2 additions & 0 deletions dev/browser/basic/esm/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import Upscaler from 'upscaler';
import flower from '../flower-small.png';
const upscaler = new Upscaler();
upscaler.upscale(flower).then(console.log);
Binary file added dev/browser/basic/flower-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions dev/browser/experiment-with-public-models/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as tf from '@tensorflow/tfjs';
import Upscaler, { ModelDefinition } from '../../../packages/upscalerjs/src/shared/index';
import Upscaler, { ModelDefinition } from '../../../packages/upscalerjs/src/browser/esm/index.js';

const model: ModelDefinition = {
path: './1/model.json',
Expand Down
4 changes: 2 additions & 2 deletions dev/browser/generate-pixel-upsampler-model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const draw = async (t: tf.Tensor3D, scale: number) => {
canvas.height = t.size[0] * scale;
const imageContainer = document.createElement('div');
const h3 = document.createElement('h3');
h3.innerHTML = `${scale}x`;
h3.innerHTML = `x${scale}`;
imageContainer.className = 'image';
imageContainer.appendChild(h3);
imageContainer.appendChild(canvas);
Expand All @@ -53,7 +53,7 @@ const generatePixelUpsampler = async () => {
const prediction = predict(model, input);
draw(prediction.div(255), scale);
});
model.save(`downloads://${scale}x`);
model.save(`downloads://x${scale}`);
}
};

Expand Down
8 changes: 4 additions & 4 deletions dev/browser/specific-model/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as tf from '@tensorflow/tfjs';
// import { ModelDefinitionFn, } from '../../../packages/core/src/index';
import { makeImg } from './image';
import { AVAILABLE_PACKAGES, loadAvailableModels } from './filters';
// import Upscaler, { ModelDefinition } from 'upscaler';
import Upscaler, { ModelDefinition } from '../../../packages/upscalerjs/src/shared/index';
import Upscaler, { ModelDefinition } from '../../../packages/upscalerjs/src/browser/esm/index.js';
import { getFixture, getModelPath, getRoot, importModel, loadPackageJSON } from './utils';

const packages = document.getElementById('packages') as HTMLSelectElement;
Expand Down Expand Up @@ -47,8 +45,10 @@ models.addEventListener('change', async (e) => {
const loadModel = async (packageName: string, modelName: string) => {
console.log(packageName, modelName);
const importedModel = await importModel(packageName, modelName);
console.log(importedModel)
const modelDefinition = (importedModel).default;
const { packageInformation, ...modelJSON }= typeof modelDefinition === 'function' ? modelDefinition(tf) : modelDefinition;
console.log(modelDefinition)
const { packageInformation, ...modelJSON }= modelDefinition;

const fixture = await getFixture(packageName, modelName);

Expand Down
1 change: 1 addition & 0 deletions dev/browser/specific-model/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const loadPackageModel = async (packageName: string, modelName: string) => {
export const importModel = async (packageName: string, modelName = '.') => {
const modelSourceFiles = await loadPackageModel(packageName, modelName);
const importPath = `${getRoot(packageName)}/${modelSourceFiles.import}?ts=${new Date().getTime()}`;
console.log(importPath);
return import(importPath);
};

Expand Down
4 changes: 2 additions & 2 deletions dev/browser/speed-tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Upscaler from '../../../packages/upscalerjs/src/shared/index';
import Upscaler from '../../../packages/upscalerjs/src/browser/esm/index.js';
import * as tf from '@tensorflow/tfjs';
import PixelUpsampler from '../../../models/pixel-upsampler/src/4x';
import PixelUpsampler from '../../../models/pixel-upsampler/src/x4';
import GANs from '../../../models/esrgan-legacy/src/gans';
import './stats';
import { FPS } from './fps';
Expand Down
2 changes: 1 addition & 1 deletion dev/node/src/commands/test-esrgan-in-all-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command } from "commander";
import type { Tensor } from '@tensorflow/tfjs-node';
import { getModel, getUpscaler, isValidEnv, ValidEnv } from '../utils/upscaler';

const DEFAULT_MODEL = 'pixel-upsampler/src/2x';
const DEFAULT_MODEL = 'pixel-upsampler/src/x2';
const DEFAULT_SIZE = '32';
const DEFAULT_MIN_SIZE = '4';
const DEFAULT_MIN_PADDING = '2';
Expand Down
5 changes: 4 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@
},
"wireit": {
"build:dependencies": {
"command": "pnpm --filter @upscalerjs/scripts model:build -a -o cjs -o esm -o umd && pnpm --filter upscaler build"
"command": "pnpm --filter upscaler build",
"dependencies": [
"../models/esrgan-medium:build"
]
},
"build-api": {
"command": "pnpm --filter @upscalerjs/scripts docs:build-api"
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-model-configurations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const setup = (tf) => {
return tf.depthToSpace(getInput(inputs), this.scale, 'NHWC');
}

static className = `PixelShuffle${scale}x`;
static className = `PixelShufflex${scale}`;
}

return PixelShuffle;
Expand Down
8 changes: 4 additions & 4 deletions internals/common/src/package-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ describe('package-json', () => {
const mockReadFile = () => Promise.resolve(JSON.stringify({
"exports": {
"./2x": {
"require": "./dist/cjs/models/esrgan-thick/src/2x.js",
"import": "./dist/esm/models/esrgan-thick/src/2x.js"
"require": "./dist/cjs/models/esrgan-thick/src/x2.js",
"import": "./dist/esm/models/esrgan-thick/src/x2.js"
},
".": {
"require": "./dist/cjs/models/esrgan-thick/src/index.js",
Expand All @@ -71,8 +71,8 @@ describe('package-json', () => {

expect(await getPackageJSONExports('foo')).toEqual([
['./2x', {
"require": "./dist/cjs/models/esrgan-thick/src/2x.js",
"import": "./dist/esm/models/esrgan-thick/src/2x.js"
"require": "./dist/cjs/models/esrgan-thick/src/x2.js",
"import": "./dist/esm/models/esrgan-thick/src/x2.js"
}],
]);
});
Expand Down
Loading

0 comments on commit 22acf94

Please sign in to comment.