@ptrblck  Sorry, I don’t know where to correct the code and where I misunderstanding, I delete self statement but still failed.
import torch
import torch.nn as nn
from torchsummary import summary

class ConvBlock(nn.Module):
    def __init__(self, in_channels, repeat_conv_num=2, transpose=False, **kwargs):
        super(ConvBlock, self).__init__()
        self.repeat_conv_num = repeat_conv_num
        conv1 = nn.Conv2d(in_channels, in_channels, **kwargs) \
            if not transpose else nn.ConvTranspose2d(in_channels, in_channels, **kwargs)
        conv2 = nn.Conv2d(in_channels, in_channels * 2, kernel_size=4, stride=2, padding=1) \
            if not transpose else nn.ConvTranspose2d(in_channels, int(in_channels / 2), kernel_size=4, stride=2, padding=1)
        bn1 = nn.BatchNorm2d(in_channels)
        bn2 = nn.BatchNorm2d(in_channels*2) if not transpose else nn.BatchNorm2d(int(in_channels/2))
        relu = nn.ReLU(inplace=True)
        self.block = nn.ModuleList([])
        for _ in range(repeat_conv_num):
            self.block.extend([conv1, bn1, relu])
        self.block.extend([conv2, bn2, relu])
        self.conv_block = nn.Sequential(*self.block)
        # print(self.conv_block)
        # for _ in self.block:
        #     print(_)

    def forward(self, x):
        print(self.conv_block)
        return self.conv_block(x)



class AutoEncoder(nn.Module):
    def __init__(self, in_channels=1, out_channels=1, features=32, **kwargs):
        super(AutoEncoder, self).__init__()
        self.init_layer = nn.Conv2d(in_channels, features, kernel_size=3, stride=1, padding=1)
        self.last_layer = nn.Conv2d(features, out_channels, kernel_size=3, stride=1, padding=1)
        self.model = nn.Sequential(
            self.init_layer,
            nn.BatchNorm2d(features),
            nn.ReLU(inplace=True),
            ConvBlock(in_channels=features, **kwargs),
            ConvBlock(in_channels=features*2, **kwargs),
            ConvBlock(in_channels=features*4, **kwargs),
            ConvBlock(in_channels=features*8, **kwargs),
            ConvBlock(in_channels=features*16, transpose=True, **kwargs),
            ConvBlock(in_channels=features * 8, transpose=True, **kwargs),
            ConvBlock(in_channels=features * 4, transpose=True, **kwargs),
            ConvBlock(in_channels=features * 2, transpose=True, **kwargs),
            self.last_layer,
            nn.Sigmoid()
        )


    def forward(self, x):
        return self.model(x)


if __name__ == "__main__":
    model = AutoEncoder(in_channels=1, out_channels=1, features=32, kernel_size=3, stride=1, padding=1, repeat_conv_num=2).to('cuda')
    x = torch.randn((2, 1, 64, 64)).to('cuda')
    summary(model, input_size=(1, 64, 64))
    print(model(x).shape)

    cblock = ConvBlock(in_channels=32, repeat_conv_num=2, transpose=False, kernel_size=3, stride=1, padding=1).to('cuda')
    x = torch.randn((2, 32, 64, 64)).to('cuda')
    summary(cblock, input_size=(32, 64, 64))
    print(cblock(x).shape)