11program test_parse_keras_model
22
3+ use iso_fortran_env, only: stderr = > error_unit
4+ use nf_datasets, only: download_and_unpack, keras_model_dense_mnist_url
35 use nf_io_hdf5, only: get_h5_attribute_string
46 use json_module
57
68 implicit none
79
810 character (:), allocatable :: model_config_string
9- character (* ), parameter :: test_data_path = ' test/data/mnist_dense .h5'
11+ character (* ), parameter :: test_data_path = ' keras_dense_mnist .h5'
1012 type (json_core) :: json
1113 type (json_value), pointer :: model_config, layers, next_layer, layer
1214 character (:), allocatable :: class_name, layer_type
1315 logical :: found
1416 integer :: n, num_layers
17+ logical :: file_exists
18+ logical :: ok
19+
20+ inquire (file= test_data_path, exist= file_exists)
21+ if (.not. file_exists) call download_and_unpack(keras_model_dense_mnist_url)
1522
1623 model_config_string = &
1724 get_h5_attribute_string(test_data_path, ' .' , ' model_config' )
@@ -20,14 +27,25 @@ program test_parse_keras_model
2027 call json % get(model_config, ' config.layers' , layers)
2128
2229 num_layers = json % count (layers)
23- print * , ' This model has' , num_layers, ' layers.'
2430
2531 do n = 1 , num_layers
2632 call json % get_child(layers, n, layer)
27- print * , ' Layer' , n
33+ ! print *, 'Layer', n
2834 ! call json % print(layer)
2935 call json % get(layer, ' class_name' , layer_type)
30- print * , layer_type
36+ ! print *, layer_type
3137 end do
3238
39+ if (.not. num_layers == 3 ) then
40+ ok = .false.
41+ write (stderr, ' (a)' ) ' Keras dense MNIST model has 3 layers.. failed'
42+ end if
43+
44+ if (ok) then
45+ print ' (a)' , ' test_parse_keras_model: All tests passed.'
46+ else
47+ write (stderr, ' (a)' ) ' test_parse_keras_model: One or more tests failed.'
48+ stop 1
49+ end if
50+
3351end program test_parse_keras_model
0 commit comments