Skip to content

Commit 25d3b14

Browse files
committed
Reading HDF5 datasets
1 parent ee3f8a5 commit 25d3b14

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

fpm.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ external-modules = "hdf5"
1010
link = ["hdf5", "hdf5_fortran"]
1111

1212
[dependencies]
13+
h5fortran = { git = "https://github.com/geospace-code/h5fortran" }
1314
json-fortran = { git = "https://github.com/jacobwilliams/json-fortran" }

test/test_read_hdf5_dataset.f90

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
program test_read_hdf5_dataset
2+
3+
use iso_fortran_env, only: int64
4+
use h5fortran, only: hdf5_file
5+
6+
implicit none
7+
character(*), parameter :: test_data_path = 'keras_dense_mnist.h5'
8+
type(hdf5_file) :: f
9+
real, allocatable :: bias(:), weights(:,:)
10+
integer(int64), allocatable :: dims(:)
11+
12+
call f % open(test_data_path, 'r')
13+
14+
call f % shape('/model_weights/dense/dense/bias:0', dims)
15+
allocate(bias(dims(1)))
16+
17+
call f % shape('/model_weights/dense/dense/kernel:0', dims)
18+
allocate(weights(dims(1), dims(2)))
19+
20+
call f % read('/model_weights/dense/dense/bias:0', bias)
21+
call f % read('/model_weights/dense/dense/kernel:0', weights)
22+
call f % close()
23+
24+
print *, 'bias shape: ', shape(bias)
25+
print *, 'weights shape: ', shape(weights)
26+
print *, bias
27+
print *, weights
28+
29+
end program test_read_hdf5_dataset

0 commit comments

Comments
 (0)