Reputation: 674
I'm new to the Flux machine learning package for Julia. I've got a simple neural network consisting of the following:
The architecture is built with this code snippet:
layer_1 = Dense(4,8,relu)
output_layer = Dense(8,3)
model = Chain(layer_1, output_layer, softmax)
I'd like to view all the edge weights (after training). In short, the weights for...
I checked the Flux documentation, but couldn't figure out how to do it. I know I can do sometihng like this:
@show( layer_1([1,0,0,0]) )
Which in turn will return a vector representing the all the outputs of that layer, and then I can reverse the activation function to find the edge weight to each neuron in that layer, but that seems overly clunky for what should be a simple task. I must be missing something.
Do you know how I can get all the edge weights (input -> hidden layer, hidden layer -> output)? A code snippet that would work for the above would be ideal.
Thanks!
Upvotes: 1
Views: 632
Reputation: 925
You can do
@show layer_1.weight
to see the weight matrix of the first layer. To see an individual edge, you can index the matrix.
# edge from input 2 to hidden 1
@show layer_1.weight[1, 2]
EDIT: On older versions of Flux, layer_1.W
is used for Dense
layers.
Upvotes: 2