Exemplo n.º 1
0
    def __init__(self,
                 in_channel=3,
                 num_joint=25,
                 num_person=2,
                 out_channel=64,
                 window_size=64,
                 num_class = 60,
                 ):
        super(HCN, self).__init__()
        self.num_person = num_person
        self.num_class = num_class
        # position
        self.conv1 = nn.Sequential(
            nn.Conv2d(in_channels=in_channel,out_channels=out_channel,kernel_size=1,stride=1,padding=0),
            nn.PReLU(),
        )
        self.conv2 = nn.Conv2d(in_channels=out_channel, out_channels=window_size, kernel_size=(3,1), stride=1, padding=(1,0))

        self.conv3 = nn.Sequential(
            nn.Conv2d(in_channels=num_joint, out_channels=out_channel//2, kernel_size=3, stride=1, padding=1),
            nn.MaxPool2d(2))
        self.conv4 = nn.Sequential(
            nn.Conv2d(in_channels=out_channel//2, out_channels=out_channel, kernel_size=3, stride=1, padding=1),
            nn.Dropout2d(p=0.5),
            nn.MaxPool2d(2))
        # motion
        self.conv1m = nn.Sequential(
            nn.Conv2d(in_channels=in_channel,out_channels=out_channel,kernel_size=1,stride=1,padding=0),
            nn.PReLU(),
        )
        self.conv2m = nn.Conv2d(in_channels=out_channel, out_channels=window_size, kernel_size=(3,1), stride=1, padding=(1,0))

        self.conv3m = nn.Sequential(
            nn.Conv2d(in_channels=num_joint, out_channels=out_channel//2, kernel_size=3, stride=1, padding=1),
            nn.MaxPool2d(2))
        self.conv4m = nn.Sequential(
            nn.Conv2d(in_channels=out_channel//2, out_channels=out_channel, kernel_size=3, stride=1, padding=1),
            nn.Dropout2d(p=0.5),
            nn.MaxPool2d(2))

        # concatenate motion & position
        self.conv5 = nn.Sequential(
            nn.Conv2d(in_channels=out_channel*2, out_channels=out_channel*2, kernel_size=3, stride=1, padding=1),
            nn.PReLU(),
            nn.Dropout2d(p=0.5),
            nn.MaxPool2d(2)
        )
        self.conv6 = nn.Sequential(
            nn.Conv2d(in_channels=out_channel*2, out_channels=out_channel*4, kernel_size=3, stride=1, padding=1),
            nn.PReLU(),
            nn.Dropout2d(p=0.5),
            nn.MaxPool2d(2)
        )

        self.fc7= nn.Sequential(
            nn.Linear((out_channel * 4)*(window_size//16)*(window_size//16),256*2), # 4*4 for window=64; 8*8 for window=128
            nn.PReLU(),
            nn.Dropout2d(p=0.5))
        self.fc8 = nn.Linear(256*2,num_class)

        # initial weight
        utils.initial_model_weight(layers = list(self.children()))
        print('weight initial finished!')
Exemplo n.º 2
0
    def __init__(
        self,
        in_channel=3,
        num_joint=25,
        num_person=2,
        out_channel=64,
        window_size=300,
        num_class=60,
    ):
        super(AIF_CNN, self).__init__()
        self.num_person = num_person
        self.num_class = num_class
        self.num_joint = num_joint
        self.out_channel = out_channel
        # position
        # metric1_numpy = np.eye(self.num_joint, 26).astype('float32') + 0.01 * np.random.randn(
        #     self.num_joint, 26).astype('float32')
        # self.adat_metrices1 = nn.Parameter(torch.from_numpy(metric1_numpy))

        self.adat_metrices1 = nn.Parameter(torch.from_numpy(ntu_metrics))
        self.relu1 = nn.ReLU()
        self.conv1 = nn.Sequential(
            nn.Conv2d(in_channels=in_channel * 2,
                      out_channels=out_channel // 2,
                      kernel_size=1,
                      stride=1,
                      padding=0),
            nn.ReLU(),
        )
        self.conv2 = nn.Sequential(
            nn.Conv2d(in_channels=out_channel // 2,
                      out_channels=out_channel // 2,
                      kernel_size=(3, 1),
                      stride=1,
                      padding=(1, 0)))

        metric_r1_numpy = np.eye(25).astype(
            'float32') + 0.01 * np.random.randn(25).astype('float32')
        self.adat_metrices_r1 = nn.Parameter(torch.from_numpy(metric_r1_numpy))
        self.conv_resize1 = nn.Sequential(
            nn.Conv2d(in_channels=out_channel // 2,
                      out_channels=out_channel // 2,
                      kernel_size=(3, 1),
                      stride=1,
                      padding=(1, 0)), nn.MaxPool2d((2, 1)))

        metric_r2_numpy = np.eye(25).astype(
            'float32') + 0.01 * np.random.randn(25).astype('float32')
        self.adat_metrices_r2 = nn.Parameter(torch.from_numpy(metric_r2_numpy))
        self.conv_resize2 = nn.Sequential(
            nn.Conv2d(in_channels=out_channel // 2,
                      out_channels=out_channel // 2,
                      kernel_size=(3, 1),
                      stride=1,
                      padding=(1, 0)))

        metric3_numpy = np.eye(25, 26).astype(
            'float32') + 0.01 * np.random.randn(25, 26).astype('float32')
        self.adat_metrices3 = nn.Parameter(torch.from_numpy(metric3_numpy))
        # self.adat_metrices3_O = torch.from_numpy(metric3_numpy).cuda()
        self.conv3 = nn.Sequential(
            nn.Conv2d(in_channels=out_channel // 2,
                      out_channels=out_channel // 2,
                      kernel_size=3,
                      stride=1,
                      padding=1), nn.MaxPool2d(2))

        metric4_numpy = np.eye(13, 14).astype(
            'float32') + 0.01 * np.random.randn(13, 14).astype('float32')
        self.adat_metrices4 = nn.Parameter(torch.from_numpy(metric4_numpy))
        # self.adat_metrices4_O = torch.from_numpy(metric4_numpy).cuda()

        self.conv4 = nn.Sequential(
            nn.Conv2d(in_channels=out_channel // 2,
                      out_channels=out_channel,
                      kernel_size=3,
                      stride=1,
                      padding=1), nn.Dropout2d(p=0.5), nn.MaxPool2d(2))

        # motion
        # metric1_numpy_m = np.eye(self.num_joint, 26).astype('float32') + 0.01 * np.random.randn(
        #     self.num_joint, 26).astype('float32')
        # self.adat_metrices1_m = nn.Parameter(torch.from_numpy(metric1_numpy_m))

        self.adat_metrices1_m = nn.Parameter(torch.from_numpy(ntu_metrics))
        self.relu1_m = nn.ReLU()

        self.conv1_m = nn.Sequential(
            nn.Conv2d(in_channels=in_channel * 2,
                      out_channels=out_channel // 2,
                      kernel_size=1,
                      stride=1,
                      padding=0),
            nn.ReLU(),
        )
        self.conv2_m = nn.Sequential(
            nn.Conv2d(in_channels=out_channel // 2,
                      out_channels=out_channel // 2,
                      kernel_size=(3, 1),
                      stride=1,
                      padding=(1, 0)))

        metric_r1m_numpy = np.eye(25).astype(
            'float32') + 0.01 * np.random.randn(25).astype('float32')
        self.adat_metrices_r1m = nn.Parameter(
            torch.from_numpy(metric_r1m_numpy))
        self.conv_resize1_m = nn.Sequential(
            nn.Conv2d(in_channels=out_channel // 2,
                      out_channels=out_channel // 2,
                      kernel_size=(3, 1),
                      stride=1,
                      padding=(1, 0)), nn.MaxPool2d((2, 1)))

        metric_r2m_numpy = np.eye(25).astype(
            'float32') + 0.01 * np.random.randn(25).astype('float32')
        self.adat_metrices_r2m = nn.Parameter(
            torch.from_numpy(metric_r2m_numpy))
        self.conv_resize2_m = nn.Sequential(
            nn.Conv2d(in_channels=out_channel // 2,
                      out_channels=out_channel // 2,
                      kernel_size=(3, 1),
                      stride=1,
                      padding=(1, 0)))

        metric3_numpy_m = np.eye(25, 26).astype(
            'float32') + 0.01 * np.random.randn(25, 26).astype('float32')
        self.adat_metrices3_m = nn.Parameter(torch.from_numpy(metric3_numpy_m))
        # self.adat_metrices3_m_O = torch.from_numpy(metric3_numpy_m).cuda()
        self.conv3_m = nn.Sequential(
            nn.Conv2d(in_channels=out_channel // 2,
                      out_channels=out_channel // 2,
                      kernel_size=3,
                      stride=1,
                      padding=1), nn.MaxPool2d(2))

        metric4_numpy_m = np.eye(13, 14).astype(
            'float32') + 0.01 * np.random.randn(13, 14).astype('float32')
        self.adat_metrices4_m = nn.Parameter(torch.from_numpy(metric4_numpy_m))
        # self.adat_metrices4_m_o = torch.from_numpy(metric4_numpy_m).cuda()
        self.conv4_m = nn.Sequential(
            nn.Conv2d(in_channels=out_channel // 2,
                      out_channels=out_channel,
                      kernel_size=3,
                      stride=1,
                      padding=1), nn.Dropout2d(p=0.5), nn.MaxPool2d(2))

        # concatenate motion & position
        metric5_numpy = np.eye(7, 8).astype(
            'float32') + 0.01 * np.random.randn(7, 8).astype('float32')
        self.adat_metrices5 = nn.Parameter(torch.from_numpy(metric5_numpy))
        # self.adat_metrices5_o = torch.from_numpy(metric5_numpy).cuda()
        self.conv5 = nn.Sequential(
            nn.Conv2d(in_channels=out_channel * 2,
                      out_channels=out_channel * 4,
                      kernel_size=3,
                      stride=1,
                      padding=1), nn.ReLU(), nn.Dropout2d(p=0.5),
            nn.MaxPool2d(2))

        metric6_numpy = np.eye(
            out_channel // 16).astype('float32') + 0.01 * np.random.randn(
                out_channel // 16).astype('float32')
        self.adat_metrices6 = nn.Parameter(torch.from_numpy(metric6_numpy))
        # self.adat_metrices6_o = torch.from_numpy(metric6_numpy).cuda()
        self.conv6 = nn.Sequential(
            nn.Conv2d(in_channels=out_channel * 4,
                      out_channels=out_channel * 8,
                      kernel_size=3,
                      stride=1,
                      padding=1), nn.ReLU(), nn.Dropout2d(p=0.5),
            nn.MaxPool2d(2))

        self.fc7 = nn.Sequential(
            nn.Linear((out_channel * 8) * 2 * (out_channel // 32), 512),
            # 4*4 for window=64; 8*8 for window=128
            nn.ReLU(),
            nn.Dropout2d(p=0.5))
        self.fc8 = nn.Linear(512, num_class)
        utils.initial_model_weight(layers=list(self.children()))
        print('weight initial finished!')