MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / set_weights

Method set_weights

tensorflow/python/keras/engine/base_layer.py:1329–1360  ·  view source on GitHub ↗

Sets the weights of the layer, from Numpy arrays. Arguments: weights: a list of Numpy arrays. The number of arrays and their shape must match number of the dimensions of the weights of the layer (i.e. it should match the output of `get_wei

(self, weights)

Source from the content-addressed store, hash-verified

1327 self._updates += updates
1328
1329 def set_weights(self, weights):
1330 """Sets the weights of the layer, from Numpy arrays.
1331
1332 Arguments:
1333 weights: a list of Numpy arrays. The number
1334 of arrays and their shape must match
1335 number of the dimensions of the weights
1336 of the layer (i.e. it should match the
1337 output of `get_weights`).
1338
1339 Raises:
1340 ValueError: If the provided weights list does not match the
1341 layer's specifications.
1342 """
1343 params = self.weights
1344 if len(params) != len(weights):
1345 raise ValueError('You called `set_weights(weights)` on layer "' +
1346 self.name + '" with a weight list of length ' +
1347 str(len(weights)) + ', but the layer was expecting ' +
1348 str(len(params)) + ' weights. Provided weights: ' +
1349 str(weights)[:50] + '...')
1350 if not params:
1351 return
1352 weight_value_tuples = []
1353 for p, w in zip(params, weights):
1354 ref_shape = p.shape
1355 if not ref_shape.is_compatible_with(w.shape):
1356 raise ValueError('Layer weight shape ' + str(ref_shape) +
1357 ' not compatible with '
1358 'provided weight shape ' + str(w.shape))
1359 weight_value_tuples.append((p, w))
1360 backend.batch_set_value(weight_value_tuples)
1361
1362 def get_weights(self):
1363 """Returns the current weights of the layer.

Calls 2

is_compatible_withMethod · 0.45
appendMethod · 0.45