Print a summary of the network architecture
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(network_type), | intent(in) | :: | this |
Instance of network |
module subroutine print_summary(this) !! Print a summary of the network architecture implicit none ! Arguments class(network_type), intent(in) :: this !! Instance of network ! Local variables integer :: i, vertex_idx !! Loop index and vertex index integer :: total_params !! Parameter counts integer :: layer_params !! Parameters in current layer character(len=80) :: line !! Line separator character(len=40) :: layer_name !! Layer name character(len=30) :: output_shape_str !! Output shape string character(len=20) :: param_str !! Parameter count string character(len=100) :: fmt !! Format string line = repeat('_', 80) ! Print header write(*,*) write(*,'(A)') line write(*,'(A)') 'Model Summary' write(*,'(A)') line write(*,'(A35, A25, A15)') 'Layer (type)', 'Output Shape', 'Param #' write(*,'(A)') repeat('=', 80) ! Initialise parameter count total_params = 0 ! Print each layer do i = 1, this%num_layers vertex_idx = this%vertex_order(i) associate(layer => this%model(vertex_idx)%layer) ! Get layer name if(allocated(layer%name))then write(layer_name, '(A," (",A,")")') & trim(layer%name), trim(layer%subtype) else write(layer_name, '(A,I0," (",A,")")') & 'layer_', i, trim(layer%subtype) end if ! Get output shape string if(allocated(layer%output_shape))then ! write the general format for output shape write(fmt,'("(""(""",A,"I0,"")"")")') & repeat('I0,", "', size(layer%output_shape)-1) write(output_shape_str, fmt) layer%output_shape else output_shape_str = '(Not set)' end if ! Get parameter count layer_params = layer%get_num_params() total_params = total_params + layer_params if(layer_params .gt. 0)then write(param_str, '(I0)') layer_params else param_str = '0' end if ! Print layer information write(*,'(A35, A25, A15)') adjustl(trim(layer_name)), & adjustl(trim(output_shape_str)), adjustl(trim(param_str)) end associate end do ! Print footer write(*,'(A)') repeat('=', 80) write(*,'(A,I0)') 'Number of input vertices: ', size(this%root_vertices) write(*,'(A,I0)') 'Number of output vertices: ', size(this%leaf_vertices) write(*,'(A,I0)') 'Total trainable params: ', total_params write(*,'(A)') line write(*,*) end subroutine print_summary