Skip to content

Commit d090199

Browse files
committed
Add a CNN (forward-only) example
1 parent ab1faa6 commit d090199

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ foreach(execid input1d_layer input3d_layer dense_layer conv2d_layer maxpool2d_la
110110
add_test(test_${execid} bin/test_${execid})
111111
endforeach()
112112

113-
foreach(execid mnist simple sine)
113+
foreach(execid cnn mnist simple sine)
114114
add_executable(${execid} example/${execid}.f90)
115115
target_link_libraries(${execid} neural ${LIBS})
116116
endforeach()

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

0 commit comments

Comments
 (0)