MCPcopy Create free account
hub / github.com/tensorflow/tfjs / getConfig

Function getConfig

tfjs-layers/src/engine/container.ts:1082–1182  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1080 }
1081
1082 override getConfig(): serialization.ConfigDict {
1083 const config: serialization.ConfigDict = {name: this.name};
1084
1085 // Build a map from layer unique name (self._node_key)
1086 // to the index of the nodes that are saved in the config.
1087 // Only nodes in container_nodes are saved.
1088 const nodeConversionMap: {[nodeKey: string]: number} =
1089 this.buildNodeConversionMap(this.layers);
1090
1091 // Serialize and save the layers in layerConfigs
1092 const layerConfigs = [];
1093 for (const layer of this.layers) {
1094 const layerClassName = layer.getClassName();
1095 const layerConfig = layer.getConfig();
1096 const filteredInboundNodes = [];
1097 for (let originalNodeIndex = 0;
1098 originalNodeIndex < layer.inboundNodes.length; originalNodeIndex++) {
1099 const node = layer.inboundNodes[originalNodeIndex];
1100 const nodeKey = Container.nodeKey(layer, originalNodeIndex);
1101 let kwargs = {};
1102 if (this.containerNodes.has(nodeKey)) {
1103 // The node is relevant to the model:
1104 // add to filteredInboundNodes.
1105 if (node.callArgs) {
1106 try {
1107 JSON.stringify(node.callArgs);
1108 kwargs = node.callArgs;
1109 } catch (err) {
1110 console.warn(
1111 `Layer ${layer.name} was passed ` +
1112 `non-serializable keyword arguments: ` +
1113 `${node.callArgs}. They will not be included ` +
1114 `in the serialized model (and thus will be ` +
1115 `missing at deserialization time).`);
1116 kwargs = {};
1117 }
1118 }
1119 if (node.inboundLayers.length > 0) {
1120 const nodeData = [];
1121 for (let i = 0; i < node.inboundLayers.length; i++) {
1122 const inboundLayer = node.inboundLayers[i];
1123 const nodeIndex = node.nodeIndices[i];
1124 const tensorIndex = node.tensorIndices[i];
1125 const nodeKey = Container.nodeKey(inboundLayer, nodeIndex);
1126 let newNodeIndex = nodeConversionMap[nodeKey];
1127 if (newNodeIndex == null) {
1128 newNodeIndex = 0;
1129 }
1130 nodeData.push(
1131 [inboundLayer.name, newNodeIndex, tensorIndex, kwargs]);
1132 }
1133 filteredInboundNodes.push(nodeData);
1134 }
1135 }
1136 }
1137 const dict: serialization.ConfigDict = {};
1138 dict['name'] = layer.name;
1139 dict['className'] = layerClassName;

Callers

nothing calls this directly

Calls 4

hasMethod · 0.80
getClassNameMethod · 0.65
getConfigMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…