|
| 1 | +program example_save_and_load |
| 2 | + |
| 3 | + use mod_network, only: network_type |
| 4 | + implicit none |
| 5 | + |
| 6 | + type(network_type) :: net1, net2 |
| 7 | + real, allocatable :: input(:), output(:) |
| 8 | + integer :: i |
| 9 | + |
| 10 | + net1 = network_type([3, 5, 2]) |
| 11 | + |
| 12 | + input = [0.2, 0.4, 0.6] |
| 13 | + output = [0.123456, 0.246802] |
| 14 | + |
| 15 | + ! train network 1 |
| 16 | + do i = 1, 500 |
| 17 | + call net1 % train(input, output, eta=1.0) |
| 18 | + end do |
| 19 | + |
| 20 | + ! save network 1 to file |
| 21 | + call net1 % save('my_simple_net.txt') |
| 22 | + |
| 23 | + ! load network 2 from file |
| 24 | + !net2 = network_type([3, 5, 2]) |
| 25 | + call net2 % load('my_simple_net.txt') |
| 26 | + call net2 % set_activation('sigmoid') |
| 27 | + |
| 28 | + print *, 'Network 1 output: ', net1 % output(input) |
| 29 | + print *, 'Network 2 output: ', net2 % output(input) |
| 30 | + print *, 'Outputs match: ', all(net1 % output(input) == net2 % output(input)) |
| 31 | + |
| 32 | +end program example_save_and_load |
0 commit comments