Signature
OpenComicAI.preload(
steps: OpenComicAIOptions[],
downloading?: Downloading | false
): Promise<void>
Description
Preload models before processing images. This method serves two purposes:
- Download models: Ensures all required model files are downloaded and available locally before processing begins
- Daemon mode: For
upscayl models, spawns daemon processes that keep models loaded in memory, significantly improving processing speed for multiple images
Daemons are only used with compatible models (upscayl-based models) when OpenComicAI.setConcurrentDaemons() is set to a value greater than 0.
Parameters
steps
OpenComicAIOptions[]
required
Array of processing steps to preload. Each step specifies a model and its parameters.See OpenComicAIOptions for available options.
Optional callbacks for monitoring model download progress. Pass false to disable download callbacks.See Downloading for callback options.
Returns
Returns a promise that resolves when all models are downloaded and daemons are started (if enabled).
Daemon mode
When daemon mode is enabled (upscayl models only):
- Models are loaded into memory once and kept running
- Subsequent image processing is 3-7x faster
- Multiple daemons can run concurrently for parallel processing
- Daemons automatically shut down after the configured idle timeout
See the README performance comparison for benchmarks.
Examples
Basic preload
import OpenComicAI from 'opencomic-ai-bin';
OpenComicAI.setModelsPath('./models');
// Download models if not available
await OpenComicAI.preload([
{
model: 'realcugan',
scale: 4,
noise: 0,
}
]);
// Now pipeline() will run immediately without downloading
await OpenComicAI.pipeline('./input.jpg', './output.jpg', [
{
model: 'realcugan',
scale: 4,
noise: 0,
}
]);
Preload with daemon mode
import OpenComicAI from 'opencomic-ai-bin';
OpenComicAI.setModelsPath('./models');
// Enable daemon mode with 3 concurrent daemons
OpenComicAI.setConcurrentDaemons(3);
// Set daemon idle timeout to 60 seconds
OpenComicAI.setDaemonIdleTimeout(60000);
// Preload model and start daemon
await OpenComicAI.preload([
{
model: 'realesrgan-x4plus-anime',
scale: 4,
}
]);
// Process multiple images with daemon (much faster)
for (let i = 0; i < 100; i++) {
await OpenComicAI.pipeline(
`./input-${i}.jpg`,
`./output-${i}.jpg`,
[{ model: 'realesrgan-x4plus-anime', scale: 4 }]
);
}
// Close daemons when done
OpenComicAI.closeAllDaemons();
Preload with download tracking
await OpenComicAI.preload(
[
{
model: '1x_halftone_patch_060000_G',
},
{
model: 'realcugan',
scale: 4,
noise: 0,
}
],
{
start: () => {
console.log('Starting model download...');
},
progress: (progress) => {
console.log(`Downloading: ${Math.round(progress * 100)}%`);
},
end: () => {
console.log('Download complete');
},
}
);
Preload multiple models
import OpenComicAI from 'opencomic-ai-bin';
OpenComicAI.setModelsPath('./models');
OpenComicAI.setConcurrentDaemons(3);
// Preload all models you'll use
await OpenComicAI.preload([
{ model: '1x_halftone_patch_060000_G' },
{ model: 'realesrgan-x4plus-anime', scale: 4 },
{ model: 'ultrasharp-4x', scale: 4 },
]);
// All models are now ready for fast processing