Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
lshiwjx committed May 23, 2019
1 parent 15c3232 commit 9666750
Show file tree
Hide file tree
Showing 6 changed files with 484 additions and 691 deletions.
1,073 changes: 399 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,64 @@
# 2s-AGCN
Two-Stream Adaptive Graph Convolutional Networks for Skeleton-Based Action Recognition in CVPR19

# Data Preparation

- Download the raw data from [NTU-RGB+D][https://github.com/shahroudy/NTURGB-D] and [Skeleton-Kinetics][https://github.com/yysijie/st-gcn]. Then put them under the data directory:

-data\
-kinetics_raw\
-kinetics_train\
...
-kinetics_val\
...
-kinetics_train_label.json
-keintics_val_label.json
-nturgbd_raw\
-nturgb+d_skeletons\
...
-samples_with_missing_skeletons.txt

[https://github.com/shahroudy/NTURGB-D]: NTU-RGB+D
[https://github.com/yysijie/st-gcn]: Skeleton-Kinetics

- Preprocess the data with

`python data_gen/ntu_gendata.py`

`python data_gen/kinetics-gendata.py.`

- Generate the bone data with:

`python data_gen/gen_bone_data.py`

# Training & Testing

Change the config file depending on what you want.


`python main.py --config ./config/nturgbd-cross-view/train_joint.yaml`

`python main.py --config ./config/nturgbd-cross-view/train_bone.yaml`
To ensemble the results of joints and bones, run test firstly to generate the scores of the softmax layer.

`python main.py --config ./config/nturgbd-cross-view/test_joint.yaml`

`python main.py --config ./config/nturgbd-cross-view/test_bone.yaml`

Then combine the generated scores with:

`python ensemble.py` --datasets ntu/xview
# Citation
Please cite the following paper if you use this repository in your reseach.

@inproceedings{2sagcn2019cvpr,
title = {Two-Stream Adaptive Graph Convolutional Networks for Skeleton-Based Action Recognition},
author = {Lei Shi and Yifan Zhang and Jian Cheng and Hanqing Lu},
booktitle = {CVPR},
year = {2019},
}

# Contact
For any questions, feel free to contact: `lei.shi@nlpr.ia.ac.cn`
6 changes: 3 additions & 3 deletions config/nturgbd-cross-subject/test_bone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ model_args:

# test
phase: test
device: [0,1,2,3]
device: [4,5,6,7]
test_batch_size: 256
weights: ./pre_train/ntu_cs_agcn_bone-49-31300.pt
weights: ./runs/ntu_cs_agcn_bone-49-31300.pt

work_dir: ./runs/ntu/xsub/agcn_test_bone
work_dir: ./work_dir/ntu/xsub/agcn_test_bone
model_saved_name: ./runs/ntu_cs_agcn_test_bone
save_score: True
2 changes: 1 addition & 1 deletion config/nturgbd-cross-subject/train_bone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ base_lr: 0.1
step: [30, 40]

# training
device: [0, 1 ,2, 3]
device: [4, 5, 6, 7]
batch_size: 64
test_batch_size: 64
num_epoch: 50
Expand Down
25 changes: 15 additions & 10 deletions ensemble.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import argparse
import pickle

import numpy as np
from tqdm import tqdm

# datasets = {'kinetics', 'ntu/xsub', 'ntu/xview'}
datasets = {'ntu/xview'}
parser = argparse.ArgumentParser()
parser.add_argument('--datasets', default='ntu/xsub', choices={'kinetics', 'ntu/xsub', 'ntu/xview'},
help='the work folder for storing results')
parser.add_argument('--alpha', default=1, help='weighted summation')
arg = parser.parse_args()

for dataset in datasets:
label = open('./data/' + dataset + '/val_label.pkl', 'rb')
label = np.array(pickle.load(label))
r1 = open('./work_dir/' + dataset + '/agcn_test_joint/epoch1_test_score.pkl', 'rb')
r1 = list(pickle.load(r1).items())
r2 = open('./work_dir/' + dataset + '/agcn_test_bone/epoch1_test_score.pkl', 'rb')
r2 = list(pickle.load(r2).items())
dataset = arg.datasets
label = open('./data/' + dataset + '/val_label.pkl', 'rb')
label = np.array(pickle.load(label))
r1 = open('./work_dir/' + dataset + '/agcn_test_joint/epoch1_test_score.pkl', 'rb')
r1 = list(pickle.load(r1).items())
r2 = open('./work_dir/' + dataset + '/agcn_test_bone/epoch1_test_score.pkl', 'rb')
r2 = list(pickle.load(r2).items())
right_num = total_num = right_num_5 = 0
for i in tqdm(range(len(label[0]))):
_, l = label[:, i]
_, r11 = r1[i]
_, r22 = r2[i]
r = r11 + r22
r = r11 + r22 * arg.alpha
rank_5 = r.argsort()[-5:]
right_num_5 += int(int(l) in rank_5)
r = np.argmax(r)
Expand Down
7 changes: 4 additions & 3 deletions feeders/tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import random

import numpy as np


def downsample(data_numpy, step, random_sample=True):
# input: C,T,V,M
Expand Down Expand Up @@ -50,7 +51,7 @@ def random_choose(data_numpy, size, auto_pad=True):
else:
return data_numpy
else:
begin = random.randint(0, T - size) # TODO
begin = random.randint(0, T - size)
return data_numpy[:, begin:begin + size, :, :]


Expand All @@ -62,7 +63,7 @@ def random_move(data_numpy,
# input: C,T,V,M
C, T, V, M = data_numpy.shape
move_time = random.choice(move_time_candidate)
node = np.arange(0, T, T * 1.0 / move_time).round().astype(int) # TODO
node = np.arange(0, T, T * 1.0 / move_time).round().astype(int)
node = np.append(node, T)
num_node = len(node)

Expand Down

0 comments on commit 9666750

Please sign in to comment.