- 
                Notifications
    You must be signed in to change notification settings 
- Fork 100
Locally connected layer #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            milancurcic
  merged 30 commits into
  modern-fortran:main
from
Riccardo231:locally_connected_layer
  
      
      
   
  Mar 14, 2025 
      
    
  
     Merged
                    Changes from 21 commits
      Commits
    
    
            Show all changes
          
          
            30 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      b5e7f74
              
                changing reshape layer
              
              
                Riccardo231 cf2caf6
              
                added tests; to note that they don't work
              
              
                Riccardo231 a4d5cc8
              
                Merge remote-tracking branch 'upstream/main'
              
              
                Riccardo231 eb4079d
              
                Now reshape2d works, maxpool still not
              
              
                Riccardo231 6842f3a
              
                Saving changes before rebasing
              
              
                Riccardo231 c7e682b
              
                Merge remote-tracking branch 'upstream/main'
              
              
                Riccardo231 b942637
              
                Resolved merge conflicts
              
              
                Riccardo231 9a4f710
              
                Merging
              
              
                Riccardo231 5d62b13
              
                Bug fixed; Added conv1d; Conv1d and maxpool backward still not working
              
              
                Riccardo231 a08fba0
              
                Bug fixes; now everything works
              
              
                Riccardo231 52f958f
              
                Updated the comments
              
              
                Riccardo231 b64038a
              
                Implemented locally connected 1d
              
              
                Riccardo231 9082db8
              
                Bug fix
              
              
                Riccardo231 d1cffae
              
                Bug fix
              
              
                Riccardo231 a055b20
              
                New bugs
              
              
                Riccardo231 c6b4d87
              
                Bug fix
              
              
                Riccardo231 2e64151
              
                Definitive bug fixes
              
              
                Riccardo231 2b7c548
              
                Adding jvdp1's review
              
              
                Riccardo231 be5bb76
              
                Implemented OneAdder's suggestions
              
              
                Riccardo231 33a6549
              
                Deleting useless variables
              
              
                Riccardo231 b69ba9a
              
                again
              
              
                Riccardo231 d4a87e2
              
                Update src/nf/nf_conv1d_layer_submodule.f90
              
              
                Riccardo231 8e923a0
              
                Resolve conflicts with main
              
              
                milancurcic 95c4a2a
              
                locally_connected_1d -> locally_connected1d
              
              
                milancurcic f3daf43
              
                Update features table
              
              
                milancurcic 7819b55
              
                Fix CMakeLists
              
              
                milancurcic 5b46efb
              
                Fix CmakeListst
              
              
                milancurcic 473fcf3
              
                Another one
              
              
                milancurcic 174a421
              
                Tidy up
              
              
                milancurcic a486648
              
                Acknowledge contributors
              
              
                milancurcic File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| foreach(execid | ||
| cnn_mnist | ||
| cnn_mnist_1d | ||
| dense_mnist | ||
| get_set_network_params | ||
| network_parameters | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| program cnn_mnist_1d | ||
|  | ||
| use nf, only: network, sgd, & | ||
| input, conv1d, maxpool1d, flatten, dense, reshape, reshape2d, locally_connected_1d, & | ||
| load_mnist, label_digits, softmax, relu | ||
|  | ||
| implicit none | ||
|  | ||
| type(network) :: net | ||
|  | ||
| real, allocatable :: training_images(:,:), training_labels(:) | ||
| real, allocatable :: validation_images(:,:), validation_labels(:) | ||
| real, allocatable :: testing_images(:,:), testing_labels(:) | ||
| integer :: n | ||
| integer, parameter :: num_epochs = 250 | ||
|  | ||
| call load_mnist(training_images, training_labels, & | ||
| validation_images, validation_labels, & | ||
| testing_images, testing_labels) | ||
|  | ||
| net = network([ & | ||
| input(784), & | ||
| reshape2d([28,28]), & | ||
| locally_connected_1d(filters=8, kernel_size=3, activation=relu()), & | ||
| maxpool1d(pool_size=2), & | ||
| locally_connected_1d(filters=16, kernel_size=3, activation=relu()), & | ||
| maxpool1d(pool_size=2), & | ||
| dense(10, activation=softmax()) & | ||
| ]) | ||
|  | ||
| call net % print_info() | ||
|  | ||
| epochs: do n = 1, num_epochs | ||
|  | ||
| call net % train( & | ||
| training_images, & | ||
| label_digits(training_labels), & | ||
| batch_size=16, & | ||
| epochs=1, & | ||
| optimizer=sgd(learning_rate=0.01) & | ||
| ) | ||
|  | ||
| print '(a,i2,a,f5.2,a)', 'Epoch ', n, ' done, Accuracy: ', accuracy( & | ||
| net, validation_images, label_digits(validation_labels)) * 100, ' %' | ||
|  | ||
| end do epochs | ||
|  | ||
| print '(a,f5.2,a)', 'Testing accuracy: ', & | ||
| accuracy(net, testing_images, label_digits(testing_labels)) * 100, '%' | ||
|  | ||
| contains | ||
|  | ||
| real function accuracy(net, x, y) | ||
|         
                  Riccardo231 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| type(network), intent(in out) :: net | ||
| real, intent(in) :: x(:,:), y(:,:) | ||
| integer :: i, good | ||
| good = 0 | ||
| do i = 1, size(x, dim=2) | ||
| if (all(maxloc(net % predict(x(:,i))) == maxloc(y(:,i)))) then | ||
| good = good + 1 | ||
| end if | ||
| end do | ||
| accuracy = real(good) / size(x, dim=2) | ||
| end function accuracy | ||
|  | ||
| end program cnn_mnist_1d | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.