Beispiel #1
0
    def forward(self, xr, xi):
        # xr = x[:, :, :, :, 0]
        # # imaginary part to zero
        # xi = x[:, :, :, :, 1]
        xr, xi = self.conv1(xr, xi)
        xr, xi = complex_relu(xr, xi)
        # xr, xi = complex_max_pool2d(xr, xi, 2, 2)

        xr, xi = self.bn1(xr, xi)
        xr, xi = self.conv2(xr, xi)
        xr, xi = complex_relu(xr, xi)
        # xr, xi = complex_max_pool2d(xr, xi, 2, 2)

        xr, xi = self.bn2(xr, xi)
        xr, xi = self.conv3(xr, xi)
        xr, xi = complex_relu(xr, xi)
        # xr, xi = complex_max_pool2d(xr, xi, 2, 2)

        xr = xr.view(-1, 2 * 2 * self.c3)
        xi = xi.view(-1, 2 * 2 * self.c3)
        xr, xi = self.fc1(xr, xi)
        xr, xi = complex_relu(xr, xi)
        xr, xi = self.fc2(xr, xi)
        # take the absolute value as output
        # x = torch.sqrt(torch.pow(xr, 2) + torch.pow(xi, 2))
        return xr, xi
Beispiel #2
0
 def forward(self, xr, xi):
     # inputs shaped (batch_size, 100)
     xr, xi = self.dense1(xr, xi)
     xr, xi = self.batchnorm1(xr, xi)
     xr, xi = complex_relu(xr, xi)
     xr, xi = self.dense2(xr, xi)
     xr, xi = self.batchnorm2(xr, xi)
     xr, xi = complex_relu(xr, xi)
     xr, xi = self.dense3(xr, xi)
     xr, xi = self.batchnorm3(xr, xi)
     xr, xi = complex_relu(xr, xi)
     xr, xi = self.dense4(xr, xi)
     xr, xi = complex_tanh(xr, xi)
     xr, xi = xr.view(-1, 1, 128, 128), xi.view(-1, 1, 128, 128)
     return xr, xi
 def forward(self, xr, xi):
     xr, xi = self.conv1(xr, xi)
     xr, xi = complex_relu(xr, xi)
     # xr, xi = complex_max_pool2d(xr, xi, 2, 2)
     xr, xi = self.bn(xr, xi)
     xr, xi = self.conv2(xr, xi)
     xr, xi = complex_relu(xr, xi)
     # xr, xi = complex_max_pool2d(xr, xi, 2, 2)
     xr = xr.view(-1, 2 * 2 * self.c2)
     xi = xi.view(-1, 2 * 2 * self.c2)
     xr, xi = self.fc1(xr, xi)
     xr, xi = complex_relu(xr, xi)
     xr, xi = self.fc2(xr, xi)
     # take the absolute value as output
     x = torch.sqrt(torch.pow(xr, 2) + torch.pow(xi, 2))
     return x
Beispiel #4
0
 def forward(self, xr, xi):
     # inputs shaped (batch_size, 100)
     xr, xi = self.dense(xr, xi)
     xr = xr.view(xr.size(0), 1024, 4, 4)
     xi = xi.view(xi.size(0), 1024, 4, 4)
     xr, xi = complex_relu(xr, xi)  # (batch_size, 1024, 4, 4)
     xr, xi = self.deconv1(xr, xi)  # (batch_size, 512, 8, 8)
     xr, xi = complex_relu(xr, xi)
     xr, xi = self.deconv2(xr, xi)  # (batch_size, 256, 16, 16)
     xr, xi = complex_relu(xr, xi)
     xr, xi = self.deconv3(xr, xi)  # (batch_size, 128 ,32, 32)
     xr, xi = complex_relu(xr, xi)
     xr, xi = self.deconv4(xr, xi)  # (batch_size, 64, 64, 64)
     xr, xi = complex_relu(xr, xi)
     xr, xi = self.deconv5(xr, xi)  # (batch_size, 1, 128, 128)
     return xr, xi  # (batch_size, 1, 128, 128)
    def forward(self, xr, xi):
        # imaginary part to zero
        xr, xi = self.fc2(xr, xi)
        xr, xi = complex_relu(xr, xi)

        # xr, xi = complex_max_pool2d(xr, xi, 2, 2)
        xr, xi = self.fc1(xr, xi)
        xr = xr.view(-1, self.c2, 2, 2)
        xi = xi.view(-1, self.c2, 2, 2)
        xr, xi = complex_relu(xr, xi)
        xr, xi = self.convt2(xr, xi)
        xr, xi = self.bn(xr, xi)
        # xr, xi = complex_max_pool2d(xr, xi, 2, 2)
        xr, xi = complex_relu(xr, xi)
        xr, xi = self.convt1(xr, xi)

        return xr, xi
Beispiel #6
0
    def forward(self, x):
        xr = x
        # imaginary part to zero
        xi = torch.zeros(xr.shape, dtype=xr.dtype, device=xr.device)
        xr, xi = self.conv1(xr, xi)
        xr, xi = complex_relu(xr, xi)
        xr, xi = complex_max_pool2d(xr, xi, 2, 2)

        xr, xi = self.bn(xr, xi)
        xr, xi = self.conv2(xr, xi)
        xr, xi = complex_relu(xr, xi)
        xr, xi = complex_max_pool2d(xr, xi, 2, 2)

        xr = xr.view(-1, 4 * 4 * 50)
        xi = xi.view(-1, 4 * 4 * 50)
        xr, xi = self.fc1(xr, xi)
        xr, xi = complex_relu(xr, xi)
        xr, xi = self.fc2(xr, xi)
        # take the absolute value as output
        x = torch.sqrt(torch.pow(xr, 2) + torch.pow(xi, 2))
        return F.log_softmax(x, dim=1)
Beispiel #7
0
    def forward(self, x):
        xr1 = x[:, :, :, 0::2]  # 4维 从第一维每隔2个取一维
        # imaginary part to zero
        xi1 = x[:, :, :, 1::2]  # 4维 从第二维每隔2个取一维
        xr, xi = self.conv1(xr1, xi1)
        x_br = xr.detach().cpu()
        x_bi = xi.detach().cpu()
        xr, xi = self.conv2(xr.to(device), xi.to(device))
        BN = cl.ComplexBatchNorm2d(1)
        xr, xi = BN(xr, xi)
        xr, xi = cf.complex_relu(xr, xi)
        xr, xi = self.conv3(xr.to(device), xi.to(device))
        xr, xi = BN(xr, xi)
        xr = xr.detach().cpu()
        xi = xi.detach().cpu()
        xr = xr + x_br
        xi = xi + x_bi
        xr, xi = cf.complex_relu(xr.to(device), xi.to(device))

        xr, xi = self.conv2(xr.to(device), xi.to(device))
        xr = xr.detach().cpu().numpy()
        # 修改数据类型  CUDA tensor在这里应该是指变量而不是张量格式的数据改成numpy
        xi = xi.detach().cpu().numpy()

        xr = xr.reshape(40000)  # 变成一个一维 400*100

        xi = xi.reshape(40000)
        x = np.zeros(80000)  # 100个sample,每个sample800个点
        for i in range(40000):
            x[2 * i] = xr[i]  # 按行out输入到一行的out_oneline中
            x[2 * i + 1] = xi[i]
        x = x.reshape(100, 800)
        x = torch.FloatTensor(x).to(device)
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        # x = self.dropout(x)
        x = F.sigmoid(self.fc4(x))

        return x
Beispiel #8
0
 def forward(self, input_r, input_i):
     return complex_relu(input_r, input_i)