Skip to content

Commit 9f47395

Browse files
committed
Download test data files from repo
1 parent 01dac87 commit 9f47395

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

test/test_io_hdf5.f90

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
program test_io_hdf5
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

57
implicit none
68

79
character(:), allocatable :: attr
8-
character(*), parameter :: test_data_path = 'test/data/mnist_dense.h5'
10+
character(*), parameter :: test_data_path = 'keras_dense_mnist.h5'
11+
logical :: file_exists
12+
logical :: ok
13+
14+
print *, keras_model_dense_mnist_url
15+
16+
inquire(file=test_data_path, exist=file_exists)
17+
if (.not. file_exists) call download_and_unpack(keras_model_dense_mnist_url)
918

1019
attr = get_h5_attribute_string(test_data_path, '.', 'backend')
1120

21+
if (.not. attr == 'tensorflow') then
22+
ok = .false.
23+
write(stderr, '(a)') &
24+
'HDF5 variable length string attribute not read correctly.. failed'
25+
end if
26+
27+
if (ok) then
28+
print '(a)', 'test_io_hdf5: All tests passed.'
29+
else
30+
write(stderr, '(a)') 'test_io_hdf5: One or more tests failed.'
31+
stop 1
32+
end if
33+
1234
end program test_io_hdf5

test/test_parse_keras_model.f90

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
program 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+
3351
end program test_parse_keras_model

0 commit comments

Comments
 (0)