Skip to content

Example program that shows how to access internal layer parameters #140

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ foreach(execid
dense_mnist
dense_from_keras
get_set_network_params
network_parameters
simple
sine
quadratic
Expand Down
33 changes: 33 additions & 0 deletions example/network_parameters.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
program network_parameters
! This program demonstrates how to access network parameters (weights and
! biases) from the layers' internal data structures.
use nf, only: dense, input, layer, network
use nf_conv2d_layer, only: conv2d_layer
use nf_dense_layer, only: dense_layer

implicit none

type(network) :: net
integer :: n

net = network([input(3), dense(5), dense(2)])

do n = 1, size(net % layers)
print *, "Layer ", n, "is " // net % layers(n) % name
select type (this_layer => net % layers(n) % p)
type is (dense_layer)
print *, " with weights of shape", shape(this_layer % weights)
print *, " and ", size(this_layer % biases), " biases"
print *, "Weights are:"
print *, this_layer % weights
type is (conv2d_layer)
print *, " with kernel of shape", shape(this_layer % kernel)
print *, " and ", size(this_layer % biases), " biases"
print *, "Kernel is:"
print *, this_layer % kernel
class default
print *, " with no parameters"
end select
end do

end program network_parameters