MCPcopy Create free account
hub / github.com/DFin/Neural-Network-Visualisation / decodeSnapshotLayers

Function decodeSnapshotLayers

assets/main.js:806–843  ·  view source on GitHub ↗
(payload, layerMetadata)

Source from the content-addressed store, hash-verified

804}
805
806function decodeSnapshotLayers(payload, layerMetadata) {
807 if (!payload || typeof payload !== "object" || !Array.isArray(payload.layers)) {
808 throw new Error("Snapshot-Datei enthält keine gültigen Layerdaten.");
809 }
810
811 return layerMetadata.map((meta, index) => {
812 const layerPayload =
813 payload.layers[index] ??
814 payload.layers.find((layer) => Number(layer?.layer_index) === meta.layerIndex);
815 if (!layerPayload) {
816 throw new Error(`Snapshot fehlt Layer ${meta.layerIndex}.`);
817 }
818 const weightsInfo = layerPayload.weights ?? {};
819 const biasesInfo = layerPayload.biases ?? {};
820 if (typeof weightsInfo.data !== "string" || typeof biasesInfo.data !== "string") {
821 throw new Error("Snapshot-Layer enthält keine kodierten Gewichte.");
822 }
823
824 const weightShape = normaliseShape(weightsInfo.shape, meta.weightShape);
825 const biasShape = normaliseShape(biasesInfo.shape, meta.biasShape);
826 if (weightShape.length !== 2) {
827 throw new Error("Snapshot-Layer hat eine ungültige Gewichtsdimension.");
828 }
829 if (biasShape.length === 0) {
830 throw new Error("Snapshot-Layer hat eine ungültige Bias-Dimension.");
831 }
832
833 const weights = decodeWeightMatrix(weightsInfo.data, weightShape);
834 const biases = decodeFloat16Base64(biasesInfo.data, biasShape[0]);
835 return {
836 name: typeof layerPayload.name === "string" ? layerPayload.name : meta.name,
837 activation:
838 typeof layerPayload.activation === "string" ? layerPayload.activation : meta.activation,
839 weights,
840 biases,
841 };
842 });
843}
844
845function hydrateTimeline(rawTimeline, options = {}) {
846 if (!Array.isArray(rawTimeline)) return [];

Callers 1

loadLayersFunction · 0.85

Calls 3

normaliseShapeFunction · 0.85
decodeWeightMatrixFunction · 0.85
decodeFloat16Base64Function · 0.85

Tested by

no test coverage detected