♻️(frontend) inline model weights to avoid loading them from remote

Inline the model weights instead of fetching them from a Google
remote location at runtime. The weights do not update frequently, so
inlining removes an external dependency.
This commit is contained in:
lebaudantoine
2026-07-11 15:14:21 +02:00
committed by aleb_the_flash
parent 1e5f5c4fe9
commit aabb7d629c
7 changed files with 18 additions and 5 deletions
+1
View File
@@ -20,6 +20,7 @@ and this project adheres to
- ⬆️(mail) update mjml to v5 and @html-to/text-cli - ⬆️(mail) update mjml to v5 and @html-to/text-cli
- 🚸(frontend) initialize the join input name with the persisted full name - 🚸(frontend) initialize the join input name with the persisted full name
- ♻️(frontend) refactor background processors to use the new API - ♻️(frontend) refactor background processors to use the new API
- ♻️(frontend) inline model weights to avoid loading them from remote
### Fixed ### Fixed
@@ -13,6 +13,7 @@ import {
} from './TimerWorker' } from './TimerWorker'
import { import {
BackgroundProcessorInterface, BackgroundProcessorInterface,
SELFIE_SEGMENTER_MODEL_PATH,
type ProcessorConfig, type ProcessorConfig,
type ProcessorType, type ProcessorType,
} from '.' } from '.'
@@ -158,8 +159,7 @@ export class BackgroundCustomProcessor implements BackgroundProcessorInterface {
) )
this.imageSegmenter = await ImageSegmenter.createFromOptions(vision, { this.imageSegmenter = await ImageSegmenter.createFromOptions(vision, {
baseOptions: { baseOptions: {
modelAssetPath: modelAssetPath: SELFIE_SEGMENTER_MODEL_PATH,
'https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter_landscape/float16/latest/selfie_segmenter_landscape.tflite',
delegate: 'CPU', // Use CPU for Firefox. delegate: 'CPU', // Use CPU for Firefox.
}, },
runningMode: 'VIDEO', runningMode: 'VIDEO',
@@ -11,7 +11,7 @@ import {
TIMEOUT_TICK, TIMEOUT_TICK,
timerWorkerScript, timerWorkerScript,
} from './TimerWorker' } from './TimerWorker'
import { ProcessorType } from '.' import { FACE_LANDMARKS_MODEL_PATH, ProcessorType } from '.'
const PROCESSING_WIDTH = 256 * 3 const PROCESSING_WIDTH = 256 * 3
const PROCESSING_HEIGHT = 144 * 3 const PROCESSING_HEIGHT = 144 * 3
@@ -133,8 +133,7 @@ export class FaceLandmarksProcessor implements TrackProcessor<Track.Kind> {
) )
this.faceLandmarker = await FaceLandmarker.createFromOptions(vision, { this.faceLandmarker = await FaceLandmarker.createFromOptions(vision, {
baseOptions: { baseOptions: {
modelAssetPath: modelAssetPath: FACE_LANDMARKS_MODEL_PATH,
'https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/latest/face_landmarker.task',
delegate: 'GPU', delegate: 'GPU',
}, },
runningMode: 'VIDEO', runningMode: 'VIDEO',
@@ -7,6 +7,7 @@ import {
type ProcessorConfig, type ProcessorConfig,
BackgroundProcessorInterface, BackgroundProcessorInterface,
ProcessorType, ProcessorType,
SELFIE_SEGMENTER_MODEL_PATH,
} from '.' } from '.'
export class UnifiedBackgroundTrackProcessor implements BackgroundProcessorInterface { export class UnifiedBackgroundTrackProcessor implements BackgroundProcessorInterface {
@@ -22,12 +23,18 @@ export class UnifiedBackgroundTrackProcessor implements BackgroundProcessorInter
this.processor = BackgroundProcessor({ this.processor = BackgroundProcessor({
mode: 'virtual-background', mode: 'virtual-background',
imagePath: opts.imagePath, imagePath: opts.imagePath,
assetPaths: {
modelAssetPath: SELFIE_SEGMENTER_MODEL_PATH,
},
}) })
} else if (opts.type === 'blur') { } else if (opts.type === 'blur') {
this.processorType = ProcessorType.BLUR this.processorType = ProcessorType.BLUR
this.processor = BackgroundProcessor({ this.processor = BackgroundProcessor({
mode: 'background-blur', mode: 'background-blur',
blurRadius: opts.blurRadius, blurRadius: opts.blurRadius,
assetPaths: {
modelAssetPath: SELFIE_SEGMENTER_MODEL_PATH,
},
}) })
} else { } else {
throw new Error( throw new Error(
@@ -4,6 +4,12 @@ import { BackgroundCustomProcessor } from './BackgroundCustomProcessor'
import { UnifiedBackgroundTrackProcessor } from './UnifiedBackgroundTrackProcessor' import { UnifiedBackgroundTrackProcessor } from './UnifiedBackgroundTrackProcessor'
import { FaceLandmarksOptions } from './FaceLandmarksProcessor' import { FaceLandmarksOptions } from './FaceLandmarksProcessor'
export const SELFIE_SEGMENTER_MODEL_PATH =
'/assets/mediapipe/models/selfie_segmenter_landscape.tflite'
export const FACE_LANDMARKS_MODEL_PATH =
'/assets/mediapipe/models/face_landmarker.task'
export enum ProcessorType { export enum ProcessorType {
BLUR = 'blur', BLUR = 'blur',
VIRTUAL = 'virtual', VIRTUAL = 'virtual',