Exemplo n.º 1
0
    def __init__(self):
        super(NetworkR, self).__init__()

        self.layers = nn.Sequential(
            nn.ReplicationPad3d((1, 1, 1, 1, 1, 1)),
            TempConv(1,
                     64,
                     kernel_size=(3, 3, 3),
                     stride=(1, 2, 2),
                     padding=(0, 0, 0)),
            TempConv(64, 128, kernel_size=(3, 3, 3), padding=(1, 1, 1)),
            TempConv(128, 128, kernel_size=(3, 3, 3), padding=(1, 1, 1)),
            TempConv(128,
                     256,
                     kernel_size=(3, 3, 3),
                     stride=(1, 2, 2),
                     padding=(1, 1, 1)),
            TempConv(256, 256, kernel_size=(3, 3, 3), padding=(1, 1, 1)),
            TempConv(256, 256, kernel_size=(3, 3, 3), padding=(1, 1, 1)),
            TempConv(256, 256, kernel_size=(3, 3, 3), padding=(1, 1, 1)),
            TempConv(256, 256, kernel_size=(3, 3, 3), padding=(1, 1, 1)),
            Upsample(256, 128),
            TempConv(128, 64, kernel_size=(3, 3, 3), padding=(1, 1, 1)),
            TempConv(64, 64, kernel_size=(3, 3, 3), padding=(1, 1, 1)),
            Upsample(64, 16),
            nn.Conv3d(16,
                      1,
                      kernel_size=(3, 3, 3),
                      stride=(1, 1, 1),
                      padding=(1, 1, 1)))
Exemplo n.º 2
0
    def test_class(self):
        paddle.disable_static()
        for place in self.places:
            input_shape = (3, 4, 5, 6, 7)
            pad = [1, 2, 2, 1, 1, 0]
            value = 100
            input_data = np.random.rand(*input_shape).astype(np.float32)

            pad_replication = nn.ReplicationPad3d(padding=pad)
            pad_constant = nn.ConstantPad3d(padding=pad, value=value)

            data = paddle.to_tensor(input_data)

            output = pad_replication(data)
            np_out = self._get_numpy_out(input_data,
                                         pad,
                                         "replicate",
                                         data_format="NCDHW")
            self.assertTrue(np.allclose(output.numpy(), np_out))

            output = pad_constant(data)
            np_out = self._get_numpy_out(input_data,
                                         pad,
                                         "constant",
                                         value=value,
                                         data_format="NCDHW")
            self.assertTrue(np.allclose(output.numpy(), np_out))
Exemplo n.º 3
0
    def __init__(self):
        super(NetworkC, self).__init__()

        self.down1 = nn.Sequential(
            nn.ReplicationPad3d((1, 1, 1, 1, 0, 0)),
            TempConv(1, 64, stride=(1, 2, 2), padding=(0, 0, 0)),
            TempConv(64, 128), TempConv(128, 128),
            TempConv(128, 256, stride=(1, 2, 2)), TempConv(256, 256),
            TempConv(256, 256), TempConv(256, 512, stride=(1, 2, 2)),
            TempConv(512, 512), TempConv(512, 512))
        self.flat = nn.Sequential(TempConv(512, 512), TempConv(512, 512))
        self.down2 = nn.Sequential(
            TempConv(512, 512, stride=(1, 2, 2)),
            TempConv(512, 512),
        )
        self.stattn1 = SourceReferenceAttention(
            512, 512)  # Source-Reference Attention
        self.stattn2 = SourceReferenceAttention(
            512, 512)  # Source-Reference Attention
        self.selfattn1 = SourceReferenceAttention(512, 512)  # Self Attention
        self.conv1 = TempConv(512, 512)
        self.up1 = UpsampleConcat(512, 512, 512)  # 1/8
        self.selfattn2 = SourceReferenceAttention(512, 512)  # Self Attention
        self.conv2 = TempConv(512,
                              256,
                              kernel_size=(3, 3, 3),
                              stride=(1, 1, 1),
                              padding=(1, 1, 1))
        self.up2 = nn.Sequential(
            Upsample(256, 128),  # 1/4
            TempConv(128,
                     64,
                     kernel_size=(3, 3, 3),
                     stride=(1, 1, 1),
                     padding=(1, 1, 1)))
        self.up3 = nn.Sequential(
            Upsample(64, 32),  # 1/2
            TempConv(32,
                     16,
                     kernel_size=(3, 3, 3),
                     stride=(1, 1, 1),
                     padding=(1, 1, 1)))
        self.up4 = nn.Sequential(
            Upsample(16, 8),  # 1/1
            nn.Conv3d(8,
                      2,
                      kernel_size=(3, 3, 3),
                      stride=(1, 1, 1),
                      padding=(1, 1, 1)))
        self.reffeatnet1 = nn.Sequential(
            TempConv(3, 64, stride=(1, 2, 2)),
            TempConv(64, 128),
            TempConv(128, 128),
            TempConv(128, 256, stride=(1, 2, 2)),
            TempConv(256, 256),
            TempConv(256, 256),
            TempConv(256, 512, stride=(1, 2, 2)),
            TempConv(512, 512),
            TempConv(512, 512),
        )
        self.reffeatnet2 = nn.Sequential(
            TempConv(512, 512, stride=(1, 2, 2)),
            TempConv(512, 512),
            TempConv(512, 512),
        )