@@ -23,18 +23,21 @@ program test_cnn_from_keras
23
23
real , allocatable :: training_images(:,:), training_labels(:)
24
24
real , allocatable :: validation_images(:,:), validation_labels(:)
25
25
real , allocatable :: testing_images(:,:), testing_labels(:)
26
+ real , allocatable :: input_reshaped(:,:,:,:)
26
27
real :: acc
27
28
28
29
call load_mnist(training_images, training_labels, &
29
30
validation_images, validation_labels, &
30
31
testing_images, testing_labels)
31
32
32
- acc = accuracy(net, reshape (testing_images, shape = [ 1 , 28 , 28 , 10000 ]), label_digits(testing_labels))
33
- print * , acc
33
+ ! Use only the first 1000 images to make the test short
34
+ input_reshaped = reshape (testing_images(:,: 1000 ), shape = [ 1 , 28 , 28 , 1000 ])
34
35
35
- if (acc < 0.94 ) then
36
+ acc = accuracy(net, input_reshaped, label_digits(testing_labels(:1000 )))
37
+
38
+ if (acc < 0.97 ) then
36
39
write (stderr, ' (a)' ) &
37
- ' Pre-trained network accuracy should be > 0.94 .. failed'
40
+ ' Pre-trained network accuracy should be > 0.97 .. failed'
38
41
ok = .false.
39
42
end if
40
43
@@ -55,12 +58,12 @@ real function accuracy(net, x, y)
55
58
real , intent (in ) :: x(:,:,:,:), y(:,:)
56
59
integer :: i, good
57
60
good = 0
58
- do i = 1 , size (x, dim= 2 )
61
+ do i = 1 , size (x, dim= 4 )
59
62
if (all (maxloc (net % output(x(:,:,:,i))) == maxloc (y(:,i)))) then
60
63
good = good + 1
61
64
end if
62
65
end do
63
- accuracy = real (good) / size (x, dim= 2 )
66
+ accuracy = real (good) / size (x, dim= 4 )
64
67
end function accuracy
65
68
66
69
end program test_cnn_from_keras
0 commit comments