Package: keras-octave-conv
Keras Octave ConvUnofficial implementation ofDrop an Octave: Reducing Spatial Redundancy in
Convolutional Neural Networks with Octave Convolution.Installpipinstallkeras-octave-convUsageTheOctaveConv2Dlayer could be used just like theConv2Dlayer, except thepaddingargument is forced to be'same'.First OctaveUse a single input for the first octave layer:fromkeras.layersimportInputfromkeras_octave_convimportOctaveConv2Dinputs=Input(shape=(32,32,3))high,low=OctaveConv2D(filters=16,kernel_size=3,octave=2,ratio_out=0.125)(inputs)The two outputs represent the results in higher and lower spatial resolutions.Special arguments:octave: default is2. The division of the spatial dimensions.ratio_out: default is0.5. The ratio of filters for lower spatial resolution.Intermediate OctaveThe intermediate octave layers takes two inputs and produce two outputs:fromkeras.layersimportInput,MaxPool2Dfromkeras_octave_convimportOctaveConv2Dinputs=Input(shape=(32,32,3))high,low=OctaveConv2D(filters=16,kernel_size=3)(inputs)high,low=MaxPool2D()(high),MaxPool2D()(low)high,low=OctaveConv2D(filters=8,kernel_size=3)([high,low])Note that the sameoctavevalue should be used throughout the whole model.Last OctaveSetratio_outto0.0to get a single output for further processing:fromkeras.layersimportInput,MaxPool2D,Flatten,Densefromkeras.modelsimportModelfromkeras_octave_convimportOctaveConv2Dinputs=Input(shape=(32,32,3))high,low=OctaveConv2D(filters=16,kernel_size=3)(inputs)high,low=MaxPool2D()(high),MaxPool2D()(low)high,low=OctaveConv2D(filters=8,kernel_size=3)([high,low])high,low=MaxPool2D()(high),MaxPool2D()(low)conv=OctaveConv2D(filters=4,kernel_size=3,ratio_out=0.0)([high,low])flatten=Flatten()(conv)outputs=Dense(units=10,activation='softmax')(flatten)model=Model(inputs=inputs,outputs=outputs)model.summary()Utilityoctave_dualhelps to create dual layers for processing the outputs of octave convolutions:fromkeras.layersimportInput,MaxPool2D,Flatten,Densefromkeras.modelsimportModelfromkeras_octave_convimportOctaveConv2D,octave_dualinputs=Input(shape=(32,32,3))conv=OctaveConv2D(filters=16,kernel_size=3)(inputs)pool=octave_dual(conv,MaxPool2D())conv=OctaveConv2D(filters=8,kernel_size=3)(pool)pool=octave_dual(conv,MaxPool2D())conv=OctaveConv2D(filters=4,kernel_size=3,ratio_out=0.0)(pool)flatten=Flatten()(conv)outputs=Dense(units=10,activation='softmax')(flatten)model=Model(inputs=inputs,outputs=outputs)model.summary()octave_conv_2dcreates the octave structure with built-in Keras layers:fromkeras.layersimportInput,MaxPool2D,Flatten,Densefromkeras.modelsimportModelfromkeras.utilsimportplot_modelfromkeras_octave_convimportoctave_conv_2d,octave_dualinputs=Input(shape=(32,32,3),name='Input')conv=octave_conv_2d(inputs,filters=16,kernel_size=3,name='Octave-First')pool=octave_dual(conv,MaxPool2D(name='Pool-1'))conv=octave_conv_2d(pool,filters=8,kernel_size=3,name='Octave-Mid')pool=octave_dual(conv,MaxPool2D(name='Pool-2'))conv=octave_conv_2d(pool,filters=4,kernel_size=3,ratio_out=0.0,name='Octave-Last')flatten=Flatten(name='Flatten')(conv)outputs=Dense(units=10,activation='softmax',name='Output')(flatten)model=Model(inputs=inputs,outputs=outputs)model.summary()plot_model(model,to_file='octave_model.png')