smash.factory.Net.set_weight#
- Net.set_weight(value=None, random_state=None)[source]#
Set the values of the weight in the neural network
Net.- Parameters:
- valuelist[float or
numpy.ndarray] or None, default None The list of values to set to the weights of all layers. If an element of the list is a
numpy.ndarray, its shape must be broadcastable into the weight shape of that layer. If not used, initialization methods defined in trainable layers will be used with a random or specified seed depending on random_state.- random_stateint or None, default None
Random seed used for the initialization method defined in each trainable layer. Only used if value is not set.
Note
If not given, the parameters will be initialized with a random seed.
- valuelist[float or
See also
Net.get_weightGet the weights of the trainable layers of the neural network
Net.
Examples
>>> from smash.factory import Net >>> net = Net() >>> net.add_dense(2, input_shape=3, kernel_initializer="uniform") >>> net +-------------------------------------------------------+ | Layer Type Input/Output Shape Num Parameters | +-------------------------------------------------------+ | Dense (3,)/(2,) 8 | +-------------------------------------------------------+ Total parameters: 8 Trainable parameters: 8
Set weights with specified values
>>> import numpy as np >>> net.set_weight([np.array([[1, 2, 3], [4, 5, 6]])])
Get the weight values
>>> net.get_weight() [array([[1, 2, 3], [4, 5, 6]])]
Set random weights
>>> net.set_weight(random_state=0) >>> net.get_weight() [array([[ 0.05636498, 0.24847928, 0.11866093], [ 0.05182664, -0.08815584, 0.16846401]])]