Skip to content
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

SC-Conv Implementation on Keras #21

Open
omerkolcak opened this issue Dec 12, 2022 · 0 comments
Open

SC-Conv Implementation on Keras #21

omerkolcak opened this issue Dec 12, 2022 · 0 comments

Comments

@omerkolcak
Copy link

Hello to you all, thank you for the implementation. I dont have much experience on the deep learning area. I tried to implement the self calibrated conv layer on Keras 2, but i dont know if it is correct or not. Also, i added relu activation after the concatenation, i wonder if it is good practice or should i add relu activation after every conv2d layers. Any feedback is appreciated, thanks.

def build_selfcalibrated_conv_graph(depth,layer_name,split_ratio=0.5,filters=64):
    
    input_layer = KL.Input(shape=[None,None,depth])
    
    split_idx = int(depth * split_ratio)
    
    x1 = KL.Lambda(lambda x: x[:,:,:,:split_idx])(input_layer)
    x2 = KL.Lambda(lambda x: x[:,:,:,split_idx:])(input_layer)

    # x1 path
    identity = x1 

    output_x1_a = KL.Conv2D(filters,(3,3),padding="same",name=f"{layer_name}_k3_conv")(x1)
    output_x1_a = KL.BatchNormalization(name=f"{layer_name}_k3_bn")(output_x1_a)
    
    output_x1_b = KL.AveragePooling2D(pool_size=(4, 4), strides=4,name=f"{layer_name}_k2_avg")(x1)
    output_x1_b = KL.Conv2D(filters,(3,3),padding="same",name=f"{layer_name}_k2_conv")(output_x1_b)
    output_x1_b = KL.BatchNormalization(name=f"{layer_name}_k2_bn")(output_x1_b)
    output_x1_b = KL.UpSampling2D(size=(4,4))(output_x1_b)
    output_x1_b = KL.Activation('sigmoid')(KL.add([output_x1_b,identity]))
    
    output_x1_ab = KL.Multiply()([output_x1_a,output_x1_b])

    output_x1_ab = KL.Conv2D(filters,(3,3),padding="same",name=f"{layer_name}_k4_conv")(output_x1_ab)
    y1 = KL.BatchNormalization(name=f"{layer_name}_k4_bn")(output_x1_ab)

    # x2 path
    y2 = KL.Conv2D(filters,(3,3),padding="same",name=f"{layer_name}_k1_conv")(x2)
    y2 = KL.BatchNormalization(name=f"{layer_name}_k1_bn")(y2)

    # concatenate y1 and y2
    output = KL.Concatenate(axis=-1)([y1,y2])
    output = KL.Activation('relu')(output)

    return KM.Model(inputs=input_layer, outputs=output, name=layer_name) ```     
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant