<jupyter_start><jupyter_text>Rewriting KazuNet<jupyter_code># Imports
import math<jupyter_output><empty_output><jupyter_text>KazuNet for the IWCD images of input size 16 x 40 with 38 channels :<jupyter_code>def print_output_shape(input_size, output_channels, kernel_size, stride,
                       padding, dilation):
    
    print("Input size : num_channels {0}, height {1}, width {2}".format(input_size[0],
                                                                        input_size[1],
                                                                        input_size[2]))
    
    output_height = math.floor(((input_size[1] + 2*padding[0] - 
                               dilation[0]*(kernel_size[0] - 1) - 1)/stride[0]) + 1)
    
    output_width = math.floor(((input_size[2] + 2*padding[1] - 
                               dilation[1]*(kernel_size[1] - 1) - 1)/stride[1]) + 1)
    
    
    
    print("Output size : num_channels {0}, height {1}, width {2}".format(output_channels,
                                                                         output_height,
                                                                         output_width))
    
    return (output_channels, output_height, output_width)
def print_output_shape_2(input_size, output_channels, kernel_size, stride,
                       padding, dilation):
    
    print("Input size : num_channels {0}, height {1}, width {2}".format(input_size[0],
                                                                        input_size[1],
                                                                        input_size[2]))
    
    output_height = math.floor(((input_size[1] + 2*padding[0] - kernel_size[0])/stride[0]) + 1)
    
    output_width = math.floor(((input_size[2] + 2*padding[1] - kernel_size[1])/stride[1]) + 1)
    
    
    
    print("Output size : num_channels {0}, height {1}, width {2}".format(output_channels,
                                                                         output_height,
                                                                         output_width))
    
    return (output_channels, output_height, output_width)
# Layer 1
iwcd_curr_size = (38, 16, 40)

print("Layer 2")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=16,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(0,0),
                                         dilation=(1,1))

print("Layer 3")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=16,
                                         kernel_size=(2,2),
                                         stride=(2,2),
                                         padding=(0,0),
                                         dilation=(1,1))

print("Layer 4a.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=32,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(0,0),
                                         dilation=(1,1))

print("Layer 4b.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=32,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(0,0),
                                         dilation=(1,1))

print("Layer 5")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=32,
                                         kernel_size=(2,2),
                                         stride=(2,2),
                                         padding=(0,0),
                                         dilation=(1,1))



print("Layer 6a.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=64,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(0,0),
                                         dilation=(1,1))

print("Layer 6b.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=64,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(0,0),
                                         dilation=(1,1))


print("Layer 7")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=64,
                                         kernel_size=(2,2),
                                         stride=(2,2),
                                         padding=(0,0),
                                         dilation=(1,1))

print("Layer 8a.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=128,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(0,0),
                                         dilation=(1,1))

print("Layer 8b.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=128,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(0,0),
                                         dilation=(1,1))
# Layer 1
iwcd_curr_size = (38, 16, 40)

print("Layer 2")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=64,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(1,1),
                                         dilation=(1,1))

print("Layer 3")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=64,
                                         kernel_size=(2,2),
                                         stride=(2,2),
                                         padding=(0,0),
                                         dilation=(1,1))

print("Layer 4a.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=64,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(1,1),
                                         dilation=(1,1))

print("Layer 4b.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=64,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(1,1),
                                         dilation=(1,1))

print("Layer 5")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=64,
                                         kernel_size=(2,2),
                                         stride=(2,2),
                                         padding=(0,0),
                                         dilation=(1,1))


print("Layer 6a.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=128,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(1,1),
                                         dilation=(1,1))

print("Layer 6b.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=128,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(1,1),
                                         dilation=(1,1))


print("Layer 7")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=128,
                                         kernel_size=(2,2),
                                         stride=(2,2),
                                         padding=(1,1),
                                         dilation=(1,1))

print("Layer 8a.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=128,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(1,1),
                                         dilation=(1,1))
"""

Removed layers : Preserved to be put back if needed

print("Layer 8b.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=128,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(0,0),
                                         dilation=(1,1))
print("Layer 6b.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=64,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(0,0),
                                         dilation=(1,1))

print("Layer 4b.")
iwcd_curr_size = print_output_shape(input_size=iwcd_curr_size,
                                         output_channels=32,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(0,0),
                                         dilation=(1,1))


                                         



"""
def print_deconv_output_shape(input_size, output_channels, kernel_size, stride, 
                              padding, output_padding, dilation):
    print("Input size : num_channels {0}, height {1}, width {2}".format(input_size[0],
                                                                        input_size[1],
                                                                        input_size[2]))
    
    output_height = (input_size[1]-1)*stride[0] - 2*padding[0] + dilation[0] * (kernel_size[0]-1) + output_padding[0] + 1
    
    output_width = (input_size[2]-1)*stride[1] - 2*padding[1] + dilation[1] * (kernel_size[1]-1) + output_padding[1] + 1
    
    
    
    print("Output size : num_channels {0}, height {1}, width {2}".format(output_channels,
                                                                         output_height,
                                                                         output_width))
    
    return (output_channels, output_height, output_width)
def print_maxunpool_output_shape(input_size, output_channels, kernel_size, stride, 
                                 padding, dilation):
    
    print("Input size : num_channels {0}, height {1}, width {2}".format(input_size[0],
                                                                        input_size[1],
                                                                        input_size[2]))
    
    output_height = (input_size[1]-1)*stride[0] - 2*padding[0] + kernel_size[0]
    
    output_width = (input_size[2]-1)*stride[1] - 2*padding[1] + kernel_size[1]
    
    
    
    print("Output size : num_channels {0}, height {1}, width {2}".format(output_channels,
                                                                         output_height,
                                                                         output_width))
    
    return (output_channels, output_height, output_width)
# Layer 1
iwcd_curr_size = (128, 5, 11)

print("Deconvolutional layer 1")
iwcd_curr_size = print_deconv_output_shape(input_size=iwcd_curr_size,
                                         output_channels=64,
                                         kernel_size=(3,3),
                                         stride=(1,1),
                                         padding=(1,1),
                                         output_padding=(0,0),
                                         dilation=(1,1))

print("Un layer 2")
iwcd_curr_size = print_maxunpool_output_shape(input_size=iwcd_curr_size,
                                         output_channels=64,
                                         kernel_size=(2,2),
                                         stride=(2,2),
                                         padding=(1,1),
                                         dilation=(1,1))
def print_avgpool_output_shape(input_size, output_channels, kernel_size, stride, 
                                 padding):
    
    print("Input size : num_channels {0}, height {1}, width {2}".format(input_size[0],
                                                                        input_size[1],
                                                                        input_size[2]))
    
    output_height = math.floor((input_size[1] + 2*padding[0] - kernel_size[0])/stride[0] + 1)
    
    output_width = math.floor((input_size[2] + 2*padding[1] - kernel_size[1])/stride[1] + 1)
    
    
    
    print("Output size : num_channels {0}, height {1}, width {2}".format(output_channels,
                                                                         output_height,
                                                                         output_width))
    
    return (output_channels, output_height, output_width)
in_shape = (128, 5, 11)

print("AvgPool layer :")
out_shape = print_avgpool_output_shape(in_shape, in_shape[0], in_shape[1:],
                                       in_shape[1:], (0,0))
print("MaxPool layer :")
out_shape = print_output_shape(input_size=in_shape,
                                         output_channels=in_shape[0],
                                         kernel_size=in_shape[1:],
                                         stride=in_shape[1:],
                                         padding=(0,0),
                                         dilation=(1,1))
print(out_shape)
print("Unmaxpool layer :")
out_shape = print_maxunpool_output_shape(input_size=out_shape,
                                         output_channels=out_shape[0],
                                         kernel_size=in_shape[1:],
                                         stride=in_shape[1:],
                                         padding=(0,0),
                                         dilation=(1,1))<jupyter_output>Unmaxpool layer :
Input size : num_channels 128, height 1, width 1
Output size : num_channels 128, height 5, width 11
{'fraction_non_alphanumeric': 0.08927412024412414, 'fraction_numerical': 0.029606544604596805, 'mean_word_length': 0.9030145787002718, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 326, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '644079', 'license': 'CNRI-Python', 'n_tokens_mistral': 3431, 'n_tokens_neox': 3253, 'n_words': 523, 'path': 'notebooks/notebooks_archive/June 05 - Rewriting KazuNet.ipynb', 'repo_name': 'WatChMaL/CNN', 'size': '15402'}