Offer SCUNet and NLM alongside the guided denoise
The AI denoise panel now picks between three bases: the existing guided filter, non-local means and a learned SCUNet model run through onnxruntime-node on overlapping tiles. The base is part of the render key, so each model keeps its own cached render and switching back is instant, and jobs report stage and tile progress instead of a bare spinner. onnxruntime-node is pinned to 1.23.0, the last release that ships both macOS architectures, and every Docker and desktop install skips its CUDA download because only the CPU binaries in the package are used. The SCUNet weights and ONNX Runtime are added to the third-party notices, the deb copyright file and the README's denoise, API and redistribution sections.
This commit is contained in:
+28
-16
@@ -1,11 +1,13 @@
|
||||
/**
|
||||
* Job runner for the detail-preserving denoise.
|
||||
*
|
||||
* `server/denoise/` is a verbatim copy of the dependency-free pipeline from the
|
||||
* raw-noise package. It reconstructs from a per-pixel crossfade between the
|
||||
* source and a denoised base, so the result is bounded by the original pixels and
|
||||
* cannot ring or overshoot; flat noise is replaced, structure is given back
|
||||
* verbatim. The GPU's own `noise` sliders are a separate, much simpler path.
|
||||
* `server/denoise/` starts from the dependency-free pipeline of the raw-noise
|
||||
* package, which supplies the Guided and NLM bases; SCUNet runs the same stages
|
||||
* around an ONNX model. Every base is reconstructed from a per-pixel crossfade
|
||||
* between the source and the denoised base, so the result is bounded by the
|
||||
* original pixels and cannot ring or overshoot; flat noise is replaced, structure
|
||||
* is given back verbatim. The GPU's own `noise` sliders are a separate, much
|
||||
* simpler path.
|
||||
*
|
||||
* Three things here are deliberate:
|
||||
*
|
||||
@@ -33,6 +35,9 @@ export function clearDenoised(photoId) {
|
||||
return removeDenoised(photoId);
|
||||
}
|
||||
|
||||
/** Every base the picker offers; the cache keeps one render for each of them. */
|
||||
export const DENOISE_BASES = ['guided', 'scunet', 'nlm'];
|
||||
|
||||
/**
|
||||
* Bump whenever the copied modules under `server/denoise/` change output. The key
|
||||
* is the only thing between a fixed pipeline and a stale cached file.
|
||||
@@ -59,23 +64,23 @@ export function getDenoiseJob(id) {
|
||||
return jobs.get(id) ?? null;
|
||||
}
|
||||
|
||||
/** Stable for a photo and a pipeline version -- Amount is the client's business. */
|
||||
export function denoiseKey(photoId) {
|
||||
/** Stable for a photo, a pipeline version and a base denoiser -- Amount is the client's business. */
|
||||
export function denoiseKey(photoId, base = 'guided') {
|
||||
return crypto
|
||||
.createHash('sha1')
|
||||
.update(`${photoId}|${PIPELINE_VERSION}`)
|
||||
.update(`${photoId}|${PIPELINE_VERSION}|${base}`)
|
||||
.digest('hex')
|
||||
.slice(0, 12);
|
||||
}
|
||||
|
||||
export function startDenoise({ photoId, sourcePath }) {
|
||||
const key = denoiseKey(photoId);
|
||||
export function startDenoise({ photoId, sourcePath, base = 'guided' }) {
|
||||
const key = denoiseKey(photoId, base);
|
||||
|
||||
const joined = byKey.get(key);
|
||||
if (joined) return joined;
|
||||
|
||||
const url = `/api/photos/${encodeURIComponent(photoId)}/denoised?v=${key}`;
|
||||
const job = { id: crypto.randomUUID(), photoId, key, state: 'running', startedAt: Date.now() };
|
||||
const job = { id: crypto.randomUUID(), photoId, key, base, state: 'running', startedAt: Date.now() };
|
||||
|
||||
// Re-running after the edit was cleared, or a second browser, should not pay
|
||||
// for the CPU again. The file is the cache; the job just reports it.
|
||||
@@ -108,19 +113,26 @@ function run(job) {
|
||||
active += 1;
|
||||
const outPath = denoisedPath(job.photoId, job.key);
|
||||
const worker = new Worker(new URL('./denoise-worker.mjs', import.meta.url), {
|
||||
workerData: { sourcePath: job.sourcePath, outPath },
|
||||
workerData: { sourcePath: job.sourcePath, outPath, base: job.base },
|
||||
});
|
||||
|
||||
worker.on('message', (message) => {
|
||||
if (message?.type === 'done') {
|
||||
if (message?.type === 'progress') {
|
||||
job.progress = message.progress;
|
||||
} else if (message?.type === 'done') {
|
||||
job.state = 'done';
|
||||
job.progress = null;
|
||||
job.ms = message.ms;
|
||||
job.bytes = message.bytes;
|
||||
job.stats = message.stats;
|
||||
// A version bump (or an older build) leaves its render behind; keep the
|
||||
// current one and drop the rest so the folder cannot grow without bound.
|
||||
// A version bump (or an older build) leaves its render behind. Keep the
|
||||
// current key of every base and drop only the older ones, so switching
|
||||
// models reuses its cached render instead of paying for the CPU again.
|
||||
try {
|
||||
removeDenoised(job.photoId, job.key);
|
||||
removeDenoised(
|
||||
job.photoId,
|
||||
DENOISE_BASES.map((base) => denoiseKey(job.photoId, base)),
|
||||
);
|
||||
} catch {
|
||||
/* cleanup is best effort -- never fail a finished job over it */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user