peal.web.cache

Per-image cache of a web-demo job, built in ONE pass over the upload:

python -m peal.web.cache <job_dir>

The uploaded classifier is the slow part of a job (an onnx2torch-converted ViT runs at ~90 img/s on an RTX 3090), and before this cache the accuracy check, step 1 of DiDAE, the DFR correction and the per-direction analysis (twice) each pushed every image through it again. Now the accuracy check builds <job>/cache/images.npz and the others read from it:

keys

image key (dataset.keys) of every image, in the order below;

split

0 / 1 / 2 for the train / val / test split of data.yaml;

labels

class index;

logits

the classifier’s two outputs;

feats

its penultimate features (the input of the final linear layer that DFR refits), present only when find_final_linear finds that layer; the logits are then computed from them (checked against the full model);

clip

OpenAI CLIP ViT-L/14 image embedding (the space of the MSAE dictionary), as peal.web.analysis computes it.

Module attributes

CLIP_MEAN

CLIP's input normalization (openai/CLIP, ViT-L/14).

Functions

build

Compute and write the cache (see the module docstring); returns it.

cache_path

Path of the cache file of job_dir.

final_layer

Weight [2, F] and bias [2] of the final linear layer found by find_final_linear, restricted to the model's two selected outputs.

load

The cache of job_dir as a dict of arrays, or None if not built.