From a27721a4f8de23e3c8533a7e0ef8990a95ae2a6c Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 20 Sep 2023 23:26:21 +0500 Subject: [PATCH] Revert accidental examples changes This reverts commit e4d4bce2d0538012a86377e6018a85f6203291c7. --- examples/package.json | 11 +- examples/src/benchmark.js | 36 ++-- examples/src/cartoon_animation_example.js | 6 +- examples/src/cartoon_colorful_example.js | 48 ++--- examples/src/gpu_autoencoder_example.js | 243 ++++++++-------------- 5 files changed, 130 insertions(+), 214 deletions(-) diff --git a/examples/package.json b/examples/package.json index cc495b4..ae5afb2 100644 --- a/examples/package.json +++ b/examples/package.json @@ -3,19 +3,10 @@ "version": "0.0.0", "type": "module", "dependencies": { - "@mind-net.js/gpu": "^1.0.5", - "@tensorflow/tfjs": "^4.11.0", - "@tensorflow/tfjs-node-gpu": "^4.10.0", - "brain.js": "^2.0.0-beta.23", "get-pixels": "^3.3.3", "jimp": "^0.22.10", "json-stream-stringify": "^3.1.0", "jszip": "^3.10.1", - "mind-net.js": "../lib" - }, - "overrides": { - "gpu.js": { - "gl": "^6.0.2" - } + "mind-net.js": "latest" } } diff --git a/examples/src/benchmark.js b/examples/src/benchmark.js index f307b23..3be9edd 100644 --- a/examples/src/benchmark.js +++ b/examples/src/benchmark.js @@ -55,29 +55,29 @@ brModel.train(brSingleData); const trainOpts = {batchSize: BatchSize, epochs: 1, iterations: 1, progress: false}; for (let i = 0; i < 3; i++) { - // await TimeUtils.timeIt(() => pModel.compute(trainData, {batchSize: BatchSize}), `Worker.Compute (Full) #${i}`, ComputeIters / Count); - // await TimeUtils.timeIt(() => trainData.map(data => model.compute(data)), `Compute (Full) #${i}`, ComputeIters / Count); - // await TimeUtils.timeIt(() => tfModel.predict(tfTrainData), `TF.Compute (Full) #${i}`, ComputeIters / Count); - // await TimeUtils.timeIt(() => trainData.map(data => brModel.run(data)), `Brain.Compute (Full) #${i}`, ComputeIters / Count); - // console.log(); - - // await TimeUtils.timeIt(() => pModel.compute(singleTrainData), `Worker.Compute (Single) #${i}`, ComputeIters); - // await TimeUtils.timeIt(() => model.compute(singleTrainData[0]), `Compute (Single) #${i}`, ComputeIters); - // await TimeUtils.timeIt(() => tfModel.predict(tfSingleData), `TF.Compute (Single) #${i}`, ComputeIters); - // await TimeUtils.timeIt(() => brModel.run(singleTrainData[0]), `Brain.Compute (Single) #${i}`, ComputeIters); - // console.log(); + await TimeUtils.timeIt(() => pModel.compute(trainData, {batchSize: BatchSize}), `Worker.Compute (Full) #${i}`, ComputeIters / Count); + await TimeUtils.timeIt(() => trainData.map(data => model.compute(data)), `Compute (Full) #${i}`, ComputeIters / Count); + await TimeUtils.timeIt(() => tfModel.predict(tfTrainData), `TF.Compute (Full) #${i}`, ComputeIters / Count); + await TimeUtils.timeIt(() => trainData.map(data => brModel.run(data)), `Brain.Compute (Full) #${i}`, ComputeIters / Count); + console.log(); + + await TimeUtils.timeIt(() => pModel.compute(singleTrainData), `Worker.Compute (Single) #${i}`, ComputeIters); + await TimeUtils.timeIt(() => model.compute(singleTrainData[0]), `Compute (Single) #${i}`, ComputeIters); + await TimeUtils.timeIt(() => tfModel.predict(tfSingleData), `TF.Compute (Single) #${i}`, ComputeIters); + await TimeUtils.timeIt(() => brModel.run(singleTrainData[0]), `Brain.Compute (Single) #${i}`, ComputeIters); + console.log(); await TimeUtils.timeIt(() => pModel.train(trainData, trainData, trainOpts), `Worker.Train (Full) #${i}`, TrainIters); await TimeUtils.timeIt(() => model.train(trainData, trainData, trainOpts), `Train (Full) #${i}`, TrainIters); - // await TimeUtils.timeIt(() => tfModel.fit(tfTrainData, tfTrainData, trainOpts), `TF.Train (Full) #${i}`, TrainIters); - // await TimeUtils.timeIt(() => brModel.train(brTrainData, trainOpts), `Brain.Train (Full) #${i}`, TrainIters); + await TimeUtils.timeIt(() => tfModel.fit(tfTrainData, tfTrainData, trainOpts), `TF.Train (Full) #${i}`, TrainIters); + await TimeUtils.timeIt(() => brModel.train(brTrainData, trainOpts), `Brain.Train (Full) #${i}`, TrainIters); console.log(); - // await TimeUtils.timeIt(() => pModel.train(singleTrainData, singleTrainData, trainOpts), `Worker.Train (Single) #${i}`, TrainIters * Count); - // await TimeUtils.timeIt(() => model.train(singleTrainData, singleTrainData, trainOpts), `Train (Single) #${i}`, TrainIters * Count); - // await TimeUtils.timeIt(() => tfModel.fit(tfSingleData, tfSingleData, trainOpts), `TF.Train (Single) #${i}`, TrainIters * Count); - // await TimeUtils.timeIt(() => brModel.train(brSingleData, trainOpts), `Brain.Train (Single) #${i}`, TrainIters * Count); - // console.log("\n"); + await TimeUtils.timeIt(() => pModel.train(singleTrainData, singleTrainData, trainOpts), `Worker.Train (Single) #${i}`, TrainIters * Count); + await TimeUtils.timeIt(() => model.train(singleTrainData, singleTrainData, trainOpts), `Train (Single) #${i}`, TrainIters * Count); + await TimeUtils.timeIt(() => tfModel.fit(tfSingleData, tfSingleData, trainOpts), `TF.Train (Single) #${i}`, TrainIters * Count); + await TimeUtils.timeIt(() => brModel.train(brSingleData, trainOpts), `Brain.Train (Single) #${i}`, TrainIters * Count); + console.log("\n"); } await pModel.terminate(); \ No newline at end of file diff --git a/examples/src/cartoon_animation_example.js b/examples/src/cartoon_animation_example.js index 1d6048b..a6c3d0e 100644 --- a/examples/src/cartoon_animation_example.js +++ b/examples/src/cartoon_animation_example.js @@ -4,7 +4,7 @@ import {ModelSerialization, GanSerialization, Matrix, ImageUtils, ParallelModelW import * as ModelUtils from "./utils/model.js"; -const name = "2023-09-14T16:12:01.900Z_100"; +const name = "2023-08-30T12:11:05.784Z_100"; const path = "./out/models"; const outPath = "./out/animation"; @@ -18,8 +18,8 @@ const ae = ModelSerialization.load(JSON.parse(aeDump.toString())); const upscaler = ModelSerialization.load(JSON.parse(upscalerDump.toString())); const gan = GanSerialization.load(JSON.parse(ganDump.toString())); -const count = 10; -const framesPerSample = 10; +const count = 26; +const framesPerSample = 3; const scale = 2; const channels = 3; diff --git a/examples/src/cartoon_colorful_example.js b/examples/src/cartoon_colorful_example.js index 12816a0..5c5d584 100644 --- a/examples/src/cartoon_colorful_example.js +++ b/examples/src/cartoon_colorful_example.js @@ -10,18 +10,15 @@ import { ParallelGanWrapper, Matrix, ProgressUtils, - ImageUtils, - ColorUtils + ImageUtils } from "mind-net.js"; -import {GpuModelWrapper, GpuGanWrapper} from "@mind-net.js/gpu" - import * as DatasetUtils from "./utils/dataset.js"; import * as ModelUtils from "./utils/model.js"; -const DatasetUrl = "https://127.0.0.1:8080/datasets/cartoon_avatar_4000_32.zip"; -const DatasetBigUrl = "https://127.0.0.1:8080/datasets/cartoon_avatar_4000_64.zip"; +const DatasetUrl = "https://github.com/DrA1ex/mind-net.js/files/12407792/cartoon-2500-28.zip"; +const DatasetBigUrl = "https://github.com/DrA1ex/mind-net.js/files/12398103/cartoon-2500-64.zip"; console.log("Fetching datasets..."); @@ -38,7 +35,7 @@ const [trainData, bigTrainData] = await Promise.all([ ]); // You can reduce dataset length -const CNT = 4000; +const CNT = 2500; trainData.splice(CNT); bigTrainData.splice(CNT); @@ -50,20 +47,15 @@ const gsTrainData = ImageUtils.grayscaleDataset(trainData, imageChannel); // Creating grayscale Upscaler training data from the big RGB training data const upscaleTrainData = ImageUtils.grayscaleDataset(bigTrainData); -for (const tData of trainData) { - ColorUtils.transformColorSpace(ColorUtils.tanhToRgb, tData, imageChannel, tData); - ColorUtils.transformColorSpace(ColorUtils.rgbToLab, tData, imageChannel, tData); - ColorUtils.transformColorSpace(ColorUtils.labToTanh, tData, imageChannel, tData); -} // Setting up necessary parameters and dimensions -const inputDim = 64; +const inputDim = 32; const imageDim = trainData[0].length; const gsImageDim = gsTrainData[0].length; const upscaleImageDim = upscaleTrainData[0].length; const epochs = 100; -const batchSize = 128; +const batchSize = 64; const epochSamples = 10; const finalSamples = 20; const outPath = "./out"; @@ -77,8 +69,8 @@ const initializer = "xavier"; // Helper functions and models setup const createOptimizer = (lr) => new AdamOptimizer({lr, decay, beta1: beta, eps: 1e-7}); -const createHiddenLayer = (size, activation = undefined) => new Dense(size, { - activation: activation ?? new LeakyReluActivation({alpha: 0.2}), +const createHiddenLayer = (size) => new Dense(size, { + activation: new LeakyReluActivation({alpha: 0.2}), weightInitializer: initializer, options: { dropout, @@ -88,22 +80,22 @@ const createHiddenLayer = (size, activation = undefined) => new Dense(size, { }); // Creating the generator model -const generator = new SequentialModel(createOptimizer(lr * 1.2), loss); +const generator = new SequentialModel(createOptimizer(lr), loss); generator.addLayer(new Dense(inputDim)); -generator.addLayer(createHiddenLayer(128, "relu")); -generator.addLayer(createHiddenLayer(256, "relu")); +generator.addLayer(createHiddenLayer(64)); +generator.addLayer(createHiddenLayer(128)); generator.addLayer(new Dense(imageDim, {activation: "tanh", weightInitializer: initializer})); // Creating the discriminator model const discriminator = new SequentialModel(createOptimizer(lr), loss); discriminator.addLayer(new Dense(imageDim)); -discriminator.addLayer(createHiddenLayer(256)); discriminator.addLayer(createHiddenLayer(128)); +discriminator.addLayer(createHiddenLayer(64)); discriminator.addLayer(new Dense(1, {activation: "sigmoid", weightInitializer: initializer})); // Creating the generative adversarial (GAN) model const ganModel = new GenerativeAdversarialModel(generator, discriminator, createOptimizer(lr), loss); -const pGan = new GpuGanWrapper(ganModel, {batchSize}); +const pGan = new ParallelGanWrapper(ganModel); // Creating the variational autoencoder (AE) model const ae = new SequentialModel(createOptimizer(lr), "mse"); @@ -116,7 +108,7 @@ ae.addLayer(new Dense(256, {activation: "relu", weightInitializer: initializer}) ae.addLayer(new Dense(gsImageDim, {activation: "tanh", weightInitializer: initializer})); ae.compile(); -const pAe = new GpuModelWrapper(ae, {batchSize}); +const pAe = new ParallelModelWrapper(ae); // Creating the Upscaler model const upscaler = new SequentialModel(createOptimizer(lr), "mse"); @@ -126,7 +118,7 @@ upscaler.addLayer(new Dense(512, {activation: "relu", weightInitializer: initial upscaler.addLayer(new Dense(upscaleImageDim, {activation: "tanh", weightInitializer: initializer})); upscaler.compile(); -const pUpscaler = new GpuModelWrapper(upscaler, {batchSize}); +const pUpscaler = new ParallelModelWrapper(upscaler); async function _filterWithAEBatch(inputs) { return ImageUtils.processMultiChannelDataParallel(pAe, inputs, imageChannel); @@ -154,7 +146,7 @@ async function _saveModel() { let quitRequested = false; process.on("SIGINT", async () => quitRequested = true); -//await Promise.all([pAe.init(), pUpscaler.init(), pGan.init()]); +await Promise.all([pAe.init(), pUpscaler.init(), pGan.init()]); console.log("Training..."); @@ -175,12 +167,6 @@ for (const _ of ProgressUtils.progress(epochs)) { // Saving a snapshot of the generator model's output const generatedImages = await pGan.compute(generatorInput); - for (const tData of generatedImages) { - ColorUtils.transformColorSpace(ColorUtils.tanhToLab, tData, imageChannel, tData); - ColorUtils.transformColorSpace(ColorUtils.labToRgb, tData, imageChannel, tData); - ColorUtils.transformColorSpace(ColorUtils.rgbToTanh, tData, imageChannel, tData); - } - await ModelUtils.saveGeneratedModelsSamples(ganModel.epoch, outPath, generatedImages, {channel: imageChannel, count: epochSamples, time: false, prefix: "generated", scale: 4}); @@ -212,4 +198,4 @@ for (const _ of ProgressUtils.progress(epochs)) { // Save trained models await _saveModel(); -//await Promise.all([pAe.terminate(), pUpscaler.terminate(), pGan.terminate()]); \ No newline at end of file +await Promise.all([pAe.terminate(), pUpscaler.terminate(), pGan.terminate()]); \ No newline at end of file diff --git a/examples/src/gpu_autoencoder_example.js b/examples/src/gpu_autoencoder_example.js index dea5ec8..1fb5f6f 100644 --- a/examples/src/gpu_autoencoder_example.js +++ b/examples/src/gpu_autoencoder_example.js @@ -20,8 +20,7 @@ import { Dense, ChainModel, ProgressUtils, - ImageUtils, - Matrix + Iter, Matrix, ImageUtils } from "mind-net.js"; import {GpuModelWrapper} from "@mind-net.js/gpu" @@ -32,198 +31,138 @@ import * as ModelUtils from "./utils/model.js"; console.log("Fetching datasets..."); -const DatasetSmallUrl = "https://127.0.0.1:8080/datasets/cartoon_avatar_1000_32.zip"; -const DatasetBigUrl = "https://127.0.0.1:8080/datasets/cartoon_avatar_1000_64.zip"; -const DatasetBiggerUrl = "https://127.0.0.1:8080/datasets/cartoon_avatar_1000_128.zip"; -const TestDatasetUrl = "https://127.0.0.1:8080/datasets/doomguy-36-32.zip"; +//const DatasetBigUrl = "https://github.com/DrA1ex/mind-net.js/files/12456697/mnist-10000-28.zip"; +//const DatasetBigUrl = "https://github.com/DrA1ex/mind-net.js/files/12398103/cartoon-2500-64.zip"; +const DatasetBigUrl = "https://github.com/DrA1ex/mind-net.js/files/12407792/cartoon-2500-28.zip"; +const zipData = await ProgressUtils.fetchProgress(DatasetBigUrl); console.log("Preparing...") -const getLoadingProgressFn = () => ProgressUtils.progressCallback({ +const zipLoadingProgress = ProgressUtils.progressCallback({ update: true, color: ProgressUtils.Color.magenta, limit: ProgressUtils.ValueLimit.inclusive, }); - -const CNT = 2500; - -let smallZipData = await ProgressUtils.fetchProgress(DatasetSmallUrl); -const smallDataSet = ImageUtils.grayscaleDataset( - (await DatasetUtils.loadDataset(smallZipData.buffer, getLoadingProgressFn())).slice(0, CNT) -); -smallZipData = undefined; - -let bigZipData = await ProgressUtils.fetchProgress(DatasetBigUrl); -const bigDataSet = ImageUtils.grayscaleDataset( - (await DatasetUtils.loadDataset(bigZipData.buffer, getLoadingProgressFn())).slice(0, CNT) -); -bigZipData = undefined; - -let biggerZipData = await ProgressUtils.fetchProgress(DatasetBiggerUrl); -const biggerDataSet = ImageUtils.grayscaleDataset( - (await DatasetUtils.loadDataset(biggerZipData.buffer, getLoadingProgressFn())).slice(0, CNT) -); -biggerZipData = undefined; - -let testZipData = await ProgressUtils.fetchProgress(TestDatasetUrl); -const testColorfulDataSet = await DatasetUtils.loadDataset(testZipData.buffer, getLoadingProgressFn()); -testZipData = undefined; - -const ShiftingX = 4; -const ShiftingY = 4; +const loadedSet = ImageUtils.grayscaleDataset(await DatasetUtils.loadDataset(zipData.buffer, zipLoadingProgress)); // Create variations with different positioning -const smallDataSetShifted = new Array(smallDataSet.length); -for (let i = 0; i < smallDataSet.length; i++) { - const x = Math.random() * ShiftingX - ShiftingX / 2 - const y = Math.random() * ShiftingY - ShiftingY / 2; - smallDataSetShifted[i] = ImageUtils.shiftImage(smallDataSet[i], x, y, 1); +const setMul = 3; +const dataSet = new Array(loadedSet.length * setMul); +for (let k = 0; k < setMul; k++) { + for (let i = 0; i < loadedSet.length; i++) { + const [x, y] = [Math.random() * 2 - 1, Math.random() * 2 - 1]; + dataSet[k * loadedSet.length + i] = ImageUtils.shiftImage(loadedSet[i], Math.round(x), Math.round(y), 1); + } } -const trainIterations = 50; -const epochsPerIterShifter = 10; -const epochsPerIterUpscaler = 5; -const batchSize = 512; -const batchSizeUpscaler = 512; +const trainIterations = 100; +const epochsPerIter = 5; +const batchSize = 128; const imageChannel = 1; -const testImageChannel = 3; -const epochSampleSize = Math.min(10, Math.floor(Math.sqrt(testColorfulDataSet.length))); -const finalSampleSize = Math.min(20, Math.floor(Math.sqrt(testColorfulDataSet.length))); +const sampleScale = 4; +const epochSampleSize = 10; +const finalSampleSize = 20; const outPath = "./out"; -const lr = 0.0003; -const lrUpscaler = 0.0005; +const lr = 0.001; const decay = 5e-4; const beta1 = 0.5; -const dropout = 0.2; -const activation = "relu"; -const loss = "l2"; +const dropout = 0.3; +const activation = "leakyRelu"; +const loss = "mse"; const initializer = "xavier"; -const FilterSizes = [512, 384, 256, 384, 512]; -const UpscalerSizes = [512, 640, 784, 896, 1024]; -const Upscaler2Sizes = [512, 1024]; - -function createOptimizer(lr) { - return new AdamOptimizer({lr, decay, beta1}); +const LatentSpaceSize = 32; +const Sizes = [256, 128, 64]; + +const encoder = new SequentialModel(new AdamOptimizer({lr, decay, beta1}), loss); +encoder.addLayer(new Dense(dataSet[0].length)); +for (const size of Sizes) { + encoder.addLayer( + new Dense(size, { + activation, + weightInitializer: initializer, + options: {dropout} + }) + ); } - -function createHiddenLayer(size) { - return new Dense(size, { - activation, - weightInitializer: initializer, - options: {dropout} - }); +encoder.addLayer(new Dense(LatentSpaceSize, {activation, weightInitializer: initializer})); + +const decoder = new SequentialModel(new AdamOptimizer({lr, decay, beta1}), loss); +decoder.addLayer(new Dense(LatentSpaceSize)); +for (const size of Iter.reverse(Sizes)) { + decoder.addLayer( + new Dense(size, { + activation, + weightInitializer: initializer, + options: {dropout} + }) + ); } +decoder.addLayer(new Dense(dataSet[0].length, {weightInitializer: initializer, activation: "tanh"})); -function createModel(inSize, outSize, hiddenLayers, lr) { - const model = new SequentialModel(createOptimizer(lr), loss); - model.addLayer(new Dense(inSize)); - for (const size of hiddenLayers) model.addLayer(createHiddenLayer(size)); - model.addLayer(new Dense(outSize, {activation: "tanh"})); - model.compile(); - - return model; -} +const chain = new ChainModel(new AdamOptimizer({lr, decay, beta1}), loss); +chain.addModel(encoder); +chain.addModel(decoder); -const filterModel = createModel(smallDataSet[0].length, smallDataSet[0].length, FilterSizes, lr); -const upscalerModel = createModel(smallDataSet[0].length, bigDataSet[0].length, UpscalerSizes, lrUpscaler); -const upscaler2Model = createModel(bigDataSet[0].length, biggerDataSet[0].length, Upscaler2Sizes, lrUpscaler); +chain.compile(); -const resultingModel = new ChainModel(); -resultingModel.addModel(filterModel); -resultingModel.addModel(upscalerModel); -resultingModel.addModel(upscaler2Model); -resultingModel.compile(); +const pEncoder = new GpuModelWrapper(encoder, {batchSize}); +const pDecoder = new GpuModelWrapper(decoder, {batchSize}); +const pChain = new GpuModelWrapper(chain, {batchSize}); -const gShifter = new GpuModelWrapper(filterModel, {batchSize}); -const gUpscaler = new GpuModelWrapper(upscalerModel, {batchSize: batchSizeUpscaler}); -const gUpscaler2 = new GpuModelWrapper(upscaler2Model, {batchSize}); -const gResult = new GpuModelWrapper(resultingModel, {batchSize}); +async function _decode(from, to) { + const encFrom = pEncoder.compute(from); + const encTo = pEncoder.compute(to); -const testShiftedDataset = new Array(finalSampleSize ** 2); -for (let i = 0; i < testShiftedDataset.length; i++) { - const x = Math.round(Math.random() * ShiftingX - ShiftingX / 2); - const y = Math.round(Math.random() * ShiftingY - ShiftingY / 2); + const count = from.length; + const inputData = new Array(count); + for (let k = 0; k < count; k++) { + inputData[k] = encFrom.map( + (arr, i) => arr.map((value, j) => + value + (encTo[i][j] - value) * k / (count - 1) + ) + ); + } - const sample = smallDataSet[Math.floor(Math.random() * smallDataSet.length)]; - testShiftedDataset[i] = ImageUtils.shiftImage(sample, x, y, sample[0]); + return pDecoder.compute(inputData.flat()); } -let quitRequested = false; -process.on("SIGINT", async () => quitRequested = true); - async function saveModel() { const savePath = path.join(outPath, "models"); - await ModelUtils.saveModels({autoencoder: resultingModel}, savePath); + await ModelUtils.saveModels({autoencoder: chain}, savePath); console.log("Generate final sample set..."); - const finalGenerated = await ImageUtils.processMultiChannelDataParallel( - gResult, testColorfulDataSet.slice(0, finalSampleSize ** 2), testImageChannel - ); - await ModelUtils.saveGeneratedModelsSamples("autoencoder", savePath, finalGenerated, - {channel: testImageChannel, count: finalSampleSize}); + const genFrom = Matrix.fill(() => dataSet[Math.floor(Math.random() * dataSet.length)], finalSampleSize); + const genTo = Matrix.fill(() => dataSet[Math.floor(Math.random() * dataSet.length)], finalSampleSize); + + const generated = await _decode(genFrom, genTo); + await ModelUtils.saveGeneratedModelsSamples("autoencoder", savePath, generated, + {channel: imageChannel, count: finalSampleSize, scale: sampleScale}); } -console.log("Training..."); +let quitRequested = false; +process.on("SIGINT", async () => quitRequested = true); -const epochTestData = testColorfulDataSet.slice(0, epochSampleSize ** 2); -const gsEpochTestData = Matrix.fill(() => smallDataSetShifted[Math.floor(Math.random() * smallDataSetShifted.length)], epochSampleSize ** 2); +const genFrom = Matrix.fill(() => dataSet[Math.floor(Math.random() * dataSet.length)], epochSampleSize); +const genTo = Matrix.fill(() => dataSet[Math.floor(Math.random() * dataSet.length)], epochSampleSize); + +console.log("Training..."); for (const epoch of ProgressUtils.progress(trainIterations)) { - gShifter.train(smallDataSetShifted, smallDataSet, {epochs: epochsPerIterShifter}); - gUpscaler.train(smallDataSet, bigDataSet, {epochs: epochsPerIterUpscaler}); - gUpscaler2.train(bigDataSet, biggerDataSet, {epochs: epochsPerIterUpscaler}); - - const shifterGenerated = gShifter.compute(gsEpochTestData); - await ModelUtils.saveGeneratedModelsSamples(epoch, outPath, shifterGenerated, - { - channel: imageChannel, - count: epochSampleSize, - scale: 4, - time: false, - prefix: "autoencoder", - suffix: "shifter" - }); - - const upscalerGenerated = gUpscaler.compute(gsEpochTestData); - await ModelUtils.saveGeneratedModelsSamples(epoch, outPath, upscalerGenerated, - { - channel: imageChannel, - count: epochSampleSize, - scale: 2, - time: false, - prefix: "autoencoder", - suffix: "upscaler" - }); - - const upscaler2Generated = gUpscaler2.compute(upscalerGenerated); - await ModelUtils.saveGeneratedModelsSamples(epoch, outPath, upscaler2Generated, - { - channel: imageChannel, - count: epochSampleSize, - time: false, - prefix: "autoencoder", - suffix: "upscaler2" - }); - - const finalGenerated = await ImageUtils.processMultiChannelDataParallel(gResult, epochTestData, testImageChannel); - await ModelUtils.saveGeneratedModelsSamples(epoch, outPath, finalGenerated, - { - channel: testImageChannel, - count: epochSampleSize, - time: false, - prefix: "autoencoder", - suffix: "final" - }); + await pChain.train(dataSet, dataSet, {epochs: epochsPerIter}); + + const generated = await _decode(genFrom, genTo); + await ModelUtils.saveGeneratedModelsSamples(epoch, outPath, generated, + {channel: imageChannel, count: epochSampleSize, scale: sampleScale, time: false, prefix: "autoencoder"}); if (quitRequested) break; } await saveModel(); -gShifter.destroy(); -gUpscaler.destroy(); -gResult.destroy(); +pChain.destroy(); +pEncoder.destroy(); +pDecoder.destroy();