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:
+72
-11
@@ -3,6 +3,13 @@ import { ASPECTS, BW_FILTERS, HUE_BANDS, identityCurve, MAX_LOCAL_COMPONENTS, MA
|
||||
import { computeAutoEdits, computeAutoWhiteBalance } from '../lib/auto';
|
||||
import { autoNoiseFor } from '../lib/noiseProfile';
|
||||
import { clearDenoised, getDenoiseJob, startDenoise } from '../lib/api';
|
||||
import {
|
||||
DENOISE_MODELS,
|
||||
denoiseProgressLabel,
|
||||
withDenoiseRender,
|
||||
type DenoiseModel,
|
||||
} from '../lib/denoiseModels';
|
||||
import type { DenoiseProgress } from '../lib/api';
|
||||
import { clamp } from '../lib/curves';
|
||||
import type {
|
||||
CurveChannel,
|
||||
@@ -610,34 +617,60 @@ export function EffectsPanel({ edits, photo, set, grainFreeze }: PanelSetProps &
|
||||
export function DetailPanel({ edits, photo, set }: PanelSetProps) {
|
||||
const [aiBusy, setAiBusy] = useState(false);
|
||||
const [aiNote, setAiNote] = useState<string | null>(null);
|
||||
const [aiStartedAt, setAiStartedAt] = useState<number | null>(null);
|
||||
const [aiElapsed, setAiElapsed] = useState(0);
|
||||
const [aiProgress, setAiProgress] = useState<DenoiseProgress | null>(null);
|
||||
const aiActive = Boolean(edits.aiDenoise.key);
|
||||
|
||||
// A render reports no progress of its own, so the elapsed time is the one
|
||||
// honest measurement the panel can show. It ticks only while one is running:
|
||||
// a full-size frame is seconds of solid CPU on the server, not a spinner.
|
||||
useEffect(() => {
|
||||
if (aiStartedAt == null) return;
|
||||
setAiElapsed(0);
|
||||
const timer = window.setInterval(
|
||||
() => setAiElapsed(Math.round((performance.now() - aiStartedAt) / 1000)),
|
||||
1000,
|
||||
);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [aiStartedAt]);
|
||||
|
||||
// Poll rather than stream: the job is seconds long, and a failed poll just
|
||||
// leaves the previous note on screen instead of breaking the panel.
|
||||
const generateAi = async () => {
|
||||
const generateAi = async (base: DenoiseModel = edits.aiDenoise.model) => {
|
||||
if (aiBusy) return;
|
||||
setAiBusy(true);
|
||||
setAiNote('Rendering the denoised version on the server…');
|
||||
setAiStartedAt(performance.now());
|
||||
setAiProgress(null);
|
||||
setAiNote(null);
|
||||
try {
|
||||
const { jobId } = await startDenoise(photo.id);
|
||||
const { jobId } = await startDenoise(photo.id, base);
|
||||
for (let attempt = 0; attempt < 180; attempt++) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
const job = await getDenoiseJob(jobId);
|
||||
// The worker names its stage and counts SCUNet tiles; poll it rather than
|
||||
// inventing a percentage on the client.
|
||||
if (job.state === 'running') setAiProgress(job.progress ?? null);
|
||||
if (job.state === 'done') {
|
||||
set({ aiDenoise: { ...edits.aiDenoise, key: job.key } }, 'AI denoise');
|
||||
// `edits` here is the render captured when the run started -- before
|
||||
// the chip click that picked the model was committed. Spreading it
|
||||
// writes the previous model back, so an SCUNet render would flip the
|
||||
// picker to Guided on completion. The key belongs to one specific
|
||||
// base, so pin the model to the base that actually rendered.
|
||||
set({ aiDenoise: withDenoiseRender(edits.aiDenoise, base, job.key) }, 'AI denoise');
|
||||
// The pipeline tapers itself down on frames it measures as clean. That
|
||||
// taper is in the rendered file now, so report it -- the Amount slider
|
||||
// multiplies it rather than replacing it.
|
||||
const applied = job.stats?.autoGate ?? 1;
|
||||
const base = job.cached
|
||||
const note = job.cached
|
||||
? 'Using the cached version'
|
||||
: job.ms != null
|
||||
? `Cleaned in ${(job.ms / 1000).toFixed(1)}s`
|
||||
: 'Denoise ready';
|
||||
setAiNote(
|
||||
applied < 0.95
|
||||
? `${base} · clean frame, correction reduced to ${Math.round(applied * 100)}%`
|
||||
: base,
|
||||
? `${note} · clean frame, correction reduced to ${Math.round(applied * 100)}%`
|
||||
: note,
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -650,6 +683,8 @@ export function DetailPanel({ edits, photo, set }: PanelSetProps) {
|
||||
} catch (err) {
|
||||
setAiNote(err instanceof Error ? err.message : 'Denoise failed');
|
||||
} finally {
|
||||
setAiStartedAt(null);
|
||||
setAiProgress(null);
|
||||
setAiBusy(false);
|
||||
}
|
||||
};
|
||||
@@ -747,12 +782,31 @@ export function DetailPanel({ edits, photo, set }: PanelSetProps) {
|
||||
<button
|
||||
className="chip tiny"
|
||||
disabled={aiBusy}
|
||||
onClick={generateAi}
|
||||
title="Clean up noise while keeping edges and fine texture"
|
||||
onClick={() => void generateAi()}
|
||||
title="Clean up noise with a detail-preserving model"
|
||||
>
|
||||
{aiBusy ? 'Working…' : aiActive ? 'Regenerate' : 'Generate'}
|
||||
</button>
|
||||
</div>
|
||||
<div className="model-picker" role="radiogroup" aria-label="AI denoise model">
|
||||
{/* One render belongs to one model: switching mid-run would leave a chip
|
||||
selected with no render behind it. */}
|
||||
{DENOISE_MODELS.map((opt) => (
|
||||
<button
|
||||
key={opt.value}
|
||||
type="button"
|
||||
disabled={aiBusy}
|
||||
className={`chip small ${edits.aiDenoise.model === opt.value ? 'on' : ''}`}
|
||||
onClick={() => {
|
||||
set({ aiDenoise: { ...edits.aiDenoise, model: opt.value } }, 'AI denoise model');
|
||||
void generateAi(opt.value);
|
||||
}}
|
||||
title={opt.title}
|
||||
>
|
||||
{opt.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{aiActive ? (
|
||||
<Slider
|
||||
label="Amount"
|
||||
@@ -763,10 +817,17 @@ export function DetailPanel({ edits, photo, set }: PanelSetProps) {
|
||||
/>
|
||||
) : null}
|
||||
<p className="muted small panel-hint">
|
||||
{aiNote ??
|
||||
{aiBusy ? (
|
||||
<>
|
||||
{denoiseProgressLabel(aiProgress, edits.aiDenoise.model, aiElapsed)}. A full-size frame
|
||||
can take a minute or two; the picker unlocks when it lands.
|
||||
</>
|
||||
) : (
|
||||
aiNote ??
|
||||
(aiActive
|
||||
? 'Detail-preserving denoise, rendered from the full proxy.'
|
||||
: 'Removes noise only where there is no structure to keep.')}
|
||||
: 'Removes noise only where there is no structure to keep.')
|
||||
)}
|
||||
</p>
|
||||
{aiActive ? (
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user