|
| 1 | +program test_parse_keras_model |
| 2 | + |
| 3 | + use nf_io_hdf5, only: get_h5_attribute_string |
| 4 | + use json_module |
| 5 | + |
| 6 | + implicit none |
| 7 | + |
| 8 | + character(:), allocatable :: model_config_string |
| 9 | + character(*), parameter :: test_data_path = 'test/data/mnist_dense.h5' |
| 10 | + type(json_core) :: json |
| 11 | + type(json_value), pointer :: model_config, layers, next_layer, layer |
| 12 | + character(:), allocatable :: class_name, layer_type |
| 13 | + logical :: found |
| 14 | + integer :: n, num_layers |
| 15 | + |
| 16 | + model_config_string = & |
| 17 | + get_h5_attribute_string(test_data_path, '.', 'model_config') |
| 18 | + |
| 19 | + call json % parse(model_config, model_config_string) |
| 20 | + call json % get(model_config, 'config.layers', layers) |
| 21 | + |
| 22 | + num_layers = json % count(layers) |
| 23 | + print *, 'This model has', num_layers, 'layers.' |
| 24 | + |
| 25 | + do n = 1, num_layers |
| 26 | + call json % get_child(layers, n, layer) |
| 27 | + print *, 'Layer', n |
| 28 | + !call json % print(layer) |
| 29 | + call json % get(layer, 'class_name', layer_type) |
| 30 | + print *, layer_type |
| 31 | + end do |
| 32 | + |
| 33 | +end program test_parse_keras_model |
0 commit comments