Skip to content

Commit 99c4f2d

Browse files
committed
Merge branch 'main' into hdf5-reader
2 parents ebe4267 + c78c078 commit 99c4f2d

38 files changed

+476
-113
lines changed

CMakeLists.txt

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,51 +64,53 @@ endif()
6464

6565
# library to archive (libneural.a)
6666
add_library(neural
67-
src/nf_activation.f90
68-
src/nf_base_layer.f90
69-
src/nf_base_layer_submodule.f90
70-
src/nf_conv2d_layer.f90
71-
src/nf_conv2d_layer_submodule.f90
72-
src/nf_datasets_mnist.f90
73-
src/nf_datasets_mnist_submodule.f90
74-
src/nf_dense_layer.f90
75-
src/nf_dense_layer_submodule.f90
7667
src/nf.f90
77-
src/nf_input1d_layer.f90
78-
src/nf_input1d_layer_submodule.f90
79-
src/nf_input3d_layer.f90
80-
src/nf_input3d_layer_submodule.f90
81-
src/nf_io.f90
82-
src/nf_io_submodule.f90
83-
src/nf_layer_constructors.f90
84-
src/nf_layer_constructors_submodule.f90
85-
src/nf_layer.f90
86-
src/nf_layer_submodule.f90
87-
src/nf_loss.f90
88-
src/nf_loss_submodule.f90
89-
src/nf_maxpool2d_layer.f90
90-
src/nf_maxpool2d_layer_submodule.f90
91-
src/nf_network.f90
92-
src/nf_network_submodule.f90
93-
src/nf_optimizers.f90
94-
src/nf_parallel.f90
95-
src/nf_parallel_submodule.f90
96-
src/nf_random.f90
97-
src/nf_random_submodule.f90
68+
src/nf/nf_activation.f90
69+
src/nf/nf_base_layer.f90
70+
src/nf/nf_base_layer_submodule.f90
71+
src/nf/nf_conv2d_layer.f90
72+
src/nf/nf_conv2d_layer_submodule.f90
73+
src/nf/nf_datasets_mnist.f90
74+
src/nf/nf_datasets_mnist_submodule.f90
75+
src/nf/nf_dense_layer.f90
76+
src/nf/nf_dense_layer_submodule.f90
77+
src/nf/nf_flatten_layer.f90
78+
src/nf/nf_flatten_layer_submodule.f90
79+
src/nf/nf_input1d_layer.f90
80+
src/nf/nf_input1d_layer_submodule.f90
81+
src/nf/nf_input3d_layer.f90
82+
src/nf/nf_input3d_layer_submodule.f90
83+
src/nf/nf_io.f90
84+
src/nf/nf_io_submodule.f90
85+
src/nf/nf_layer_constructors.f90
86+
src/nf/nf_layer_constructors_submodule.f90
87+
src/nf/nf_layer.f90
88+
src/nf/nf_layer_submodule.f90
89+
src/nf/nf_loss.f90
90+
src/nf/nf_loss_submodule.f90
91+
src/nf/nf_maxpool2d_layer.f90
92+
src/nf/nf_maxpool2d_layer_submodule.f90
93+
src/nf/nf_network.f90
94+
src/nf/nf_network_submodule.f90
95+
src/nf/nf_optimizers.f90
96+
src/nf/nf_parallel.f90
97+
src/nf/nf_parallel_submodule.f90
98+
src/nf/nf_random.f90
99+
src/nf/nf_random_submodule.f90
98100
)
99101

100102
# Remove leading or trailing whitespace
101103
string(REGEX REPLACE "^ | $" "" LIBS "${LIBS}")
102104

103105
# tests
104106
enable_testing()
105-
foreach(execid input1d_layer input3d_layer dense_layer conv2d_layer maxpool2d_layer dense_network conv2d_network)
107+
foreach(execid input1d_layer input3d_layer dense_layer conv2d_layer maxpool2d_layer flatten_layer dense_network conv2d_network)
106108
add_executable(test_${execid} test/test_${execid}.f90)
107109
target_link_libraries(test_${execid} neural ${LIBS})
108110
add_test(test_${execid} bin/test_${execid})
109111
endforeach()
110112

111-
foreach(execid mnist simple sine)
113+
foreach(execid cnn mnist simple sine)
112114
add_executable(${execid} example/${execid}.f90)
113115
target_link_libraries(${execid} neural ${LIBS})
114116
endforeach()

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Read the paper [here](https://arxiv.org/abs/1902.06714).
3030
| Dense (fully-connected) | `dense` | `input` (1-d) | 1 |||
3131
| Convolutional (2-d) | `conv2d` | `input` (3-d), `conv2d`, `maxpool2d` | 3 |||
3232
| Max-pooling (2-d) | `maxpool2d` | `input` (3-d), `conv2d`, `maxpool2d` | 3 |||
33+
| Flatten | `flatten` | `input` (3-d), `conv2d`, `maxpool2d` | 1 |||
3334

3435
## Getting started
3536

@@ -172,9 +173,16 @@ to run the tests.
172173
The easiest way to get a sense of how to use neural-fortran is to look at
173174
examples, in increasing level of complexity:
174175

175-
1. [simple](example/simple.f90): Approximating a simple, constant data relationship
176+
1. [simple](example/simple.f90): Approximating a simple, constant data
177+
relationship
176178
2. [sine](example/sine.f90): Approximating a sine function
177-
3. [mnist](example/mnist.f90): Hand-written digit recognition using the MNIST dataset
179+
3. [mnist](example/mnist.f90): Hand-written digit recognition using the MNIST
180+
dataset
181+
4. [cnn](example/cnn.f90): Creating and running forward a simple CNN using
182+
`input`, `conv2d`, `maxpool2d`, `flatten`, and `dense` layers.
183+
184+
The examples also show you the extent of the public API that's meant to be
185+
used in applications, i.e. anything from the `nf` module.
178186

179187
The MNIST example uses [curl](https://curl.se/) to download the dataset,
180188
so make sure you have it installed on your system.

example/cnn.f90

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
program cnn
2+
3+
use nf, only: conv2d, dense, flatten, input, maxpool2d, network
4+
5+
implicit none
6+
type(network) :: net
7+
real, allocatable :: x(:,:,:)
8+
integer :: n
9+
10+
print '("Creating a CNN and doing a forward pass")'
11+
print '("(backward pass not implemented yet)")'
12+
print '(60("="))'
13+
14+
net = network([ &
15+
input([3, 32, 32]), &
16+
conv2d(filters=16, kernel_size=3, activation='relu'), & ! (16, 30, 30)
17+
maxpool2d(pool_size=2), & ! (16, 15, 15)
18+
conv2d(filters=32, kernel_size=3, activation='relu'), & ! (32, 13, 13)
19+
maxpool2d(pool_size=2), & ! (32, 6, 6)
20+
flatten(), &
21+
dense(10) &
22+
])
23+
24+
! Print a network summary to the screen
25+
call net % print_info()
26+
27+
allocate(x(3,32,32))
28+
call random_number(x)
29+
30+
print *, 'Output:', net % output(x)
31+
32+
end program cnn

example/mnist.f90

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
program mnist
2-
use nf, only: dense, input, network
3-
use nf_datasets_mnist, only: label_digits, load_mnist
4-
use nf_optimizers, only: sgd
2+
3+
use nf, only: dense, input, network, sgd, label_digits, load_mnist
54

65
implicit none
76

src/nf.f90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module nf
2+
!! User API: everything an application needs to reference directly
23
use nf_datasets_mnist, only: label_digits, load_mnist
34
use nf_layer, only: layer
4-
use nf_layer_constructors, only: conv2d, dense, input, maxpool2d
5+
use nf_layer_constructors, only: conv2d, dense, flatten, input, maxpool2d
56
use nf_network, only: network
7+
use nf_optimizers, only: sgd
68
end module nf
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)