-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
66 lines (63 loc) · 3.67 KB
/
Copy pathconfig.js
File metadata and controls
66 lines (63 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Number of classes the app trains/classifies. This is the semantic source of
// truth for "how many classes exist" — the random forest owns it (RF_CONFIG),
// the class-selector UI reads it off state.rf.numClasses, and the backends bake
// it into their inference/composite shaders. Colors are a separate, presentation
// concern (see DEFAULT_LABEL_COLORS) and must not be treated as the count.
//
// Fixed at 4 deliberately, not just as a default: WebGL2 packs every class's
// probability into a single RGBA32F texture (one channel per class — see
// `probTexture` in backends/webgl2.js), and its composite/RF-inference shaders
// unpack it as a hardcoded `float p_arr[4] = float[](probs.r, probs.g, probs.b,
// probs.a)` (webgl2.js ~line 964; see also the "RGBA channel cap" comment on the
// RF-inference votes array ~line 895). WebGPU's probability buffer has no such
// limit, but going past 4 classes would need a WebGL2 multi-render-target
// refactor (multiple probability textures + a gather step) to raise this cap —
// not undertaken here since 4 covers the vast majority of use cases.
export const NUM_CLASSES = 4;
// Default per-class overlay colors, indexed by class. These seed the mutable
// state.labelColors palette the UI owns; users may recolor classes at runtime
// without changing NUM_CLASSES. Keep at least NUM_CLASSES entries so every class
// has a default color (the UI falls back to neutral gray if this runs short).
export const DEFAULT_LABEL_COLORS = [
'#ff595e',
'#ffca3a',
'#8ac926',
'#1982c4',
];
export const RF_CONFIG = { numTrees: 8, maxDepth: 8, numClasses: NUM_CLASSES };
// Number of per-pixel features generated by the backend. Must match how many
// features the backend actually emits from gatherFeaturesForTraining (8 floats
// packed from two RGBA float textures — see backends/webgl2.js), since the
// Random Forest's feature stride is keyed off this value.
export const NUM_FEATURES = 8;
export const MIN_LABELS_TO_TRAIN = 5;
export const CAMERA_ZOOM_MIN = 0.1;
export const CAMERA_ZOOM_MAX = 32;
export const CAMERA_ZOOM_SENSITIVITY = 0.01;
export const TRAIN_DEBOUNCE_MS = 300;
// Layout of the per-object stats structs both backends produce (see the WGSL
// STATS_ACCUMULATOR_SHADER / COMPACT_STATS_SHADER in webgpu.js and accumulateStats
// in webgl2.js). The summed fields (total_intensity, sum_x, sum_y) are stored as
// 64-bit values split across two u32 words (lo, hi) so they can't overflow on large
// components — WGSL has no atomic<u64>, so the accumulator emulates it with paired
// u32 atomics. Single source of truth for the field count so consumers stay in sync.
//
// Sparse (per-label accumulator, no `label`): area, total_lo, total_hi, sumx_lo,
// sumx_hi, sumy_lo, sumy_hi, min_intensity, max_intensity → 9 u32.
// Dense (compacted, `label` prepended): the above with `label` first → 10 u32.
export const STATS_LAYOUT = {
sparseCount: 9,
denseCount: 10,
minIndex: 7, // index of min_intensity within the sparse struct (seeded to 0xFFFFFFFF)
};
// Centroid marker overlay: a circle drawn over each detected object's centroid,
// with radius derived from the object's area on a log scale so large blobs don't
// yield huge circles. radius(px) = minRadius + logScale * Math.log(area). Markers
// are drawn in image-pixel units on the per-image overlay canvas, so lineWidth
// scales with camera zoom the same way painted labels do.
export const CENTROID_OVERLAY = {
minRadius: 1.5, // floor so tiny objects still show a visible circle
logScale: 1.6, // px added per natural-log unit of area
lineWidth: 1, // ring stroke width (image px)
haloAlpha: 0.5, // opacity of the dark under-stroke that keeps the ring legible
};