-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialize weights - easy example #2913
Comments
Seems that you cannot set the weights directly. This was a previous answer to the question. |
To quote the official docs:
So setting the weights and biases should work. It is even added to the answer of the question you linked. |
Use this for walkaround. import cntk as c
import numpy as np
input_var = c.input_variable((180,))
l = c.layers.Dense(1000, activation=c.sigmoid, init=c.glorot_uniform())(input_var) #create Dense layer
weights = l.W.value # extract weights from layer
bias = l.b.value # extract bias from layer
k = c.layers.Dense(1000, activation=c.sigmoid, init_bias=bias)(input_var) #try to create new layer with same weight/bias as before
k.W.value = weights
assert np.array_equal(k.W.value, l.W.value) It seems that the init only support scalar and cntk.initializer, now. Maybe it is a documentaion error. def _initializer_for(init, rank_params=None):
if init is None:
raise ValueError("init parameter cannot be None")
# scalar constant: that's it, nothing further to do here
if np.isscalar(init):
# BUGBUG: this is sometimes required when dimensions are unknown; shouldn't.
from _cntk_py import constant_initializer
return constant_initializer(init)
#return init # TODO: change to this once this works, e.g. for layers.BatchNormalization()
# implant additional rank parameters
if rank_params:
from cntk.initializer import initializer_with_rank
init = initializer_with_rank(init, **rank_params)
return init |
Hi, can i confirm that we still can't set weights directly using numpy array? |
When I try to initialize the weights and bias parameters for a Dense layer using the Python API I am getting a TypeError:
Here is what I am doing:
From the docs it sounds like it should be supported to initialize weights/biases using numpy arrays. Any help is appreciated
The text was updated successfully, but these errors were encountered: