(payload, layerMetadata)
| 804 | } |
| 805 | |
| 806 | function 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 | |
| 845 | function hydrateTimeline(rawTimeline, options = {}) { |
| 846 | if (!Array.isArray(rawTimeline)) return []; |
no test coverage detected