Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skeleton based action recognition #50

Merged
merged 108 commits into from Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
b282f35
baseline method ST-GCN and TAGCN method are implemented.
negarhdr Apr 1, 2021
5e8139a
ST-BLN model is implemented.
negarhdr Apr 1, 2021
774e5f5
STGCN_Learner is updated.
negarhdr Apr 1, 2021
b304bb7
tests for stbln and tagcn are added.
negarhdr Apr 1, 2021
72e06c7
PST-GCN model and learner are added.
negarhdr Apr 1, 2021
684fbc3
PST-GCN model and learner are added.
negarhdr Apr 1, 2021
4e33f5d
pstgcn_learner.py and test_pstgcn.py are modified!
negarhdr Apr 2, 2021
8b106b6
pstgcn_learner.py and test_pstgcn.py are modified!
negarhdr Apr 2, 2021
8b6ba43
pstgcn_learner.py and test_pstgcn.py are modified!
negarhdr Apr 2, 2021
6f0dffe
pstgcn_learner.py and test_pstgcn.py are modified!
negarhdr Apr 2, 2021
0de9d71
multi-stream-evaluation is added to the learners and tests.
negarhdr Apr 2, 2021
e7f4624
Documentations of engine.data and engine.target are added.
negarhdr Apr 2, 2021
40d7881
learners and models are modified after unittest.
negarhdr Apr 3, 2021
31f743a
learners and models are modified after unittest.
negarhdr Apr 3, 2021
9bda5e4
learners and models are modified after unittest.
negarhdr Apr 3, 2021
2f27416
Documentation is added.
negarhdr Apr 3, 2021
d776938
Documentation is added.
negarhdr Apr 3, 2021
a111e4e
stbln.py is modified.
negarhdr Apr 3, 2021
b92576b
tests are updated.
negarhdr Apr 4, 2021
240505b
tests are updated.
negarhdr Apr 6, 2021
d605279
tests are updated.
negarhdr Apr 6, 2021
4604807
download function is updated.
negarhdr Apr 6, 2021
3b080ea
test_tagcn.py is modified!
negarhdr Apr 6, 2021
49cf1b4
tests are modified to save the files of each model in a separate folder.
negarhdr Apr 6, 2021
9beaf2d
tests are modified to save the files of each model in a separate folder.
negarhdr Apr 6, 2021
dff23a5
tests are modified to save the files of each model in a separate folder.
negarhdr Apr 6, 2021
352efa0
tests are modified to save the files of each model in a separate folder.
negarhdr Apr 6, 2021
70f6dd2
tests are modified to save the files of each model in a separate folder.
negarhdr Apr 6, 2021
40d40c5
Doc is added.
negarhdr Apr 14, 2021
3604314
data generation functions are added.
negarhdr Apr 23, 2021
6103313
Documents are added for STGCNLearner and PSTGCNLearner.
negarhdr Apr 25, 2021
645b4b0
Documents are added for STGCNLearner and PSTGCNLearner.
negarhdr Apr 25, 2021
6cc9033
learners are updated.
negarhdr Apr 25, 2021
6b0c155
learners are updated.
negarhdr Apr 25, 2021
e3587e6
test_license is updated.
negarhdr Apr 25, 2021
acc8424
document is updated.
negarhdr Apr 26, 2021
e290057
document is updated.
negarhdr Apr 26, 2021
4f385fe
stgcn_learner.py is updated
negarhdr Apr 26, 2021
51b66cc
pstgcn_learner.py is updated
negarhdr Apr 26, 2021
c87a91d
tests are updated
negarhdr Apr 26, 2021
87e12cf
learners are updated
negarhdr Apr 26, 2021
d1fa07f
learners are updated
negarhdr Apr 26, 2021
808ae45
In order to pass API tests, I need to merge this branch to mine.
negarhdr Apr 26, 2021
08f34cb
Test files are modified by printing the test name.
negarhdr May 3, 2021
5052e64
Skeleton-based-action-recognition files are moved to src/opendr
negarhdr May 3, 2021
8de11e9
Skeleton-based-action-recognition files are moved to src/opendr
negarhdr May 5, 2021
76255b4
a few bugs are fixed in feeder.py and learners.
negarhdr May 17, 2021
58ef9bb
updates are fetched from master to the branch.
negarhdr May 17, 2021
393e71b
fit and eval functions are modified to return a dictionary.
negarhdr May 17, 2021
229eea1
a bug in data preparation is fixed (feeder and learners are modified).
negarhdr May 19, 2021
6da0784
test-tagcn.py is modified
negarhdr May 19, 2021
96bc8db
test-stgcn.py is modified
negarhdr May 19, 2021
e60fdb0
test_lisence is updated
negarhdr May 19, 2021
d7b6b4f
updates are fetched from the master
negarhdr May 19, 2021
551587c
updates are fetched from the master
negarhdr May 19, 2021
b797d8c
tests are updated.
negarhdr May 20, 2021
bdc175c
tests are updated.
negarhdr May 20, 2021
b7b0a4a
Document are updated.
negarhdr May 20, 2021
79d2547
tests are updated
negarhdr May 21, 2021
9b41375
Verbose default is set to False
negarhdr May 26, 2021
9306afe
updates are fetched from master
negarhdr May 26, 2021
2e0b4ee
batch_size is increased in tests.
negarhdr May 26, 2021
53ce19c
val_batch_size is increased in tests.
negarhdr May 27, 2021
33f100d
tests are updated
negarhdr May 27, 2021
12c7a80
tests are updated
negarhdr May 28, 2021
eb853d3
verbose is set to True in tests and learners.
negarhdr Jun 1, 2021
8b64ee9
document is updated
negarhdr Jun 28, 2021
9b7c2a7
Merge branch 'master' into skeleton_based_action_recognition
negarhdr Jun 28, 2021
1ce7e29
verbose is off in optimize
negarhdr Jun 29, 2021
8bd9569
Merge remote-tracking branch 'origin/skeleton_based_action_recognitio…
negarhdr Jun 29, 2021
5e5c7a8
test_stgcn test status printed
negarhdr Jul 2, 2021
7fb84b9
tests modified
negarhdr Jul 2, 2021
17a7757
tests modified
negarhdr Jul 2, 2021
c2b6c9e
tests modified
negarhdr Jul 2, 2021
a08e266
Merge branch 'master' into skeleton_based_action_recognition
negarhdr Jul 2, 2021
08cd319
tests modified
negarhdr Jul 2, 2021
32c8e1e
Merge remote-tracking branch 'origin/skeleton_based_action_recognitio…
negarhdr Jul 2, 2021
bef1b42
Merge branch 'master' into skeleton_based_action_recognition
stefaniapedrazzi Jul 12, 2021
fa262c0
tests and learners modified
negarhdr Jul 27, 2021
7a9a654
Merge remote-tracking branch 'origin/skeleton_based_action_recognitio…
negarhdr Jul 27, 2021
e6b054c
Merge branch 'master' into skeleton_based_action_recognition
negarhdr Aug 11, 2021
b00deae
Disable broken test
stefaniapedrazzi Aug 12, 2021
e5a7c22
Debug skeleton based action recognition test
stefaniapedrazzi Aug 12, 2021
5f3537f
Revert debug change
stefaniapedrazzi Aug 12, 2021
673e764
all other tests are disabled to debug branch tests.
negarhdr Aug 13, 2021
e947d21
Merge remote-tracking branch 'origin/skeleton_based_action_recognitio…
negarhdr Aug 13, 2021
9696502
debug test
negarhdr Aug 13, 2021
94810f1
debug test
negarhdr Aug 13, 2021
9eb3232
debug test
negarhdr Aug 15, 2021
2663abb
debug test
negarhdr Aug 15, 2021
0d70ee2
debug test
negarhdr Aug 15, 2021
265b97f
disable other modules' tests
negarhdr Aug 16, 2021
349c635
disable other modules' tests
negarhdr Aug 16, 2021
e496b5f
enable all tests
negarhdr Sep 12, 2021
230dec0
updated test_sources
negarhdr Sep 12, 2021
ece5d4a
Revert "updated test_sources"
negarhdr Sep 12, 2021
51e2f88
resolve conflicts
negarhdr Sep 12, 2021
957c73e
resolve conflicts
negarhdr Sep 12, 2021
7d028e1
Merge branch 'master' into skeleton_based_action_recognition
negarhdr Sep 12, 2021
dcf2de6
resolve conflicts
negarhdr Sep 12, 2021
ea20d39
test_sources is updated
negarhdr Sep 12, 2021
103b371
Revert "test_sources is updated"
negarhdr Sep 12, 2021
0dc367c
graph properties are added to models' input
negarhdr Sep 12, 2021
5830245
test_sources is modified
negarhdr Sep 15, 2021
c2f9b17
document is updated.
negarhdr Sep 16, 2021
1693128
Merge branch 'master' into skeleton_based_action_recognition
negarhdr Sep 16, 2021
0706a3c
Merge branch 'master' into skeleton_based_action_recognition
negarhdr Sep 21, 2021
a57db62
Merge branch 'master' into skeleton_based_action_recognition
negarhdr Sep 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/reference/engine-data.md
Expand Up @@ -140,3 +140,27 @@ The [PointCloudWithCalibration](#class_engine.data.PointCloudWithCalibration) cl
#### numpy()
Return a [NumPy](https://numpy.org)-compatible representation of data.
Given that *data* argument is already internally stored in [NumPy](https://numpy.org)-compatible format, this method is equivalent to `data()`.


### class engine.data.SkeletonSequence
Bases: `engine.data.Data`

A class used for representing a sequence of body skeletons in a video.

The [SkeletonSequence](#class_engine.data.SkeletonSequence) class has the following public methods:
#### SkeletonSequence(data=None)
Construct a new [SkeletonSequence](#class_engine.data.SkeletonSequence) object based on *data*.
*data* is expected to be a 5-D array that can be casted into a 5-D [NumPy](https://numpy.org) array.
negarhdr marked this conversation as resolved.
Show resolved Hide resolved

#### data()
Return *data* argument.
Return type is uint8 [NumPy](https://numpy.org) array.
negarhdr marked this conversation as resolved.
Show resolved Hide resolved

#### data(data)
Set the internal *data* argument.
*data* is expected to be a 5-D array that can be casted into a 5-D [NumPy](https://numpy.org) array, where the
dimensions can be organized as e.g. (num_samples, channels, frames, joints, persons).

#### numpy()
Return a [NumPy](https://numpy.org)-compatible representation of data.
Given that *data* argument is already internally stored in [NumPy](https://numpy.org)-compatible format, this method is equivalent to `data()`.
28 changes: 27 additions & 1 deletion docs/reference/engine-target.md
Expand Up @@ -102,4 +102,30 @@ and optionally the prediction confidence.
The [SpeechCommand](#class_engine.target.SpeechCommand) class has the following public methods:
#### SpeechCommand(prediction, confidence=None)
Construct a new [SpeechCommand](#class_engine.target.SpeechCommand) object based from *prediction*.
*prediction* is expected to be an integer designating the class and optional *confidence* a float between 0 and 1.
*prediction* is expected to be an integer designating the class and optional *confidence* a float between 0 and 1.


### class engine.target.ActionCategory
Bases: `engine.target.Target`

This target is used for skeleton-based action recognition.


The [ActionCategory](#class_engine.target.ActionCategory) class has the following public methods:
#### ActionCategory(actioncategory, confidence=None)
negarhdr marked this conversation as resolved.
Show resolved Hide resolved
Construct a new [ActionCategory](#class_engine.target.ActionCategory) object based from *actioncategory*.
*actioncategory* is expected to be an integer number which shows the action class number.
Confidence indicates the confidence score of the classification.


### class engine.target.Pose
Bases: `engine.target.Target`

This target is used for pose estimation. It contains a list of Keypoints.
Refer to kpt_names for keypoint naming.

The [Pose](#class_engine.target.Pose) class has the following public methods:
#### Pose(keypoints, confidence)
Construct a new [Pose](#class_engine.target.Pose) object based on *keypoints*.
*keypoints* is expected to be a list of [Keypoint](#class_engine.target.Keypoint) objects.
negarhdr marked this conversation as resolved.
Show resolved Hide resolved

66 changes: 66 additions & 0 deletions src/engine/data.py
Expand Up @@ -401,3 +401,69 @@ def __str__(self):
:rtype: str
"""
return "Points: " + str(self.data) + "\nCalib:" + str(self.calib)


class SkeletonSequence(Data):
"""
A class used for representing a sequence of body skeletons in a video.

This class provides abstract methods for:
- returning a NumPy compatible representation of data (numpy())
"""

def __init__(self, data=None):
super().__init__(data)

if data is not None:
self.data = data

@property
def data(self):
"""
Getter of data. SkeletonSequence class returns a float32 NumPy array.

:return: the actual data held by the object
:rtype: A float32 NumPy array
negarhdr marked this conversation as resolved.
Show resolved Hide resolved
"""
if self._data is None:
raise ValueError("SkeletonSequence is empty")

return self._data

@data.setter
def data(self, data):
"""
Setter for data.

:param: data to be used for creating a skeleton sequence
"""
# Convert input data to a NumPy array
# Note that will also fail for non-numeric data (which is expected)
data = np.asarray(data, dtype=np.float32)

# Check if the supplied vector is 5D, e.g. (num_samples, channels, frames, joints, persons)
if len(data.shape) != 5:
raise ValueError(
"Only 5-D arrays are supported by SkeletonSequence. Please supply a data object that can be casted "
"into a 5-D NumPy array.")

self._data = data

def numpy(self):
"""
Returns a NumPy-compatible representation of data.

:return: a NumPy-compatible representation of data
:rtype: numpy.ndarray
"""
# Since this class stores the data as NumPy arrays, we can directly return the data
return self.data

def __str__(self):
"""
Returns a human-friendly string-based representation of the data.

:return: a human-friendly string-based representation of the data
:rtype: str
"""
return str(self.data)
13 changes: 13 additions & 0 deletions src/engine/target.py
Expand Up @@ -257,3 +257,16 @@ def __str__(self):
return f"Class {self.data} speech command with confidence {self.confidence}"
else:
return f"Class {self.data} speech command"


class ActionCategory(Target):
"""
This target is used for skeleton-based action detection.
"""
def __init__(self, actioncategory, confidence=None):
super().__init__()
self.data = actioncategory
self.confidence = confidence

def __str__(self):
return str(self.data)
57 changes: 57 additions & 0 deletions src/perception/skeleton_based_action_recognition/README.md
@@ -0,0 +1,57 @@
# Skeleton-based Human Action Recognition
Python implementation of baseline method, ST-GCN [[1]](#1), and the proposed methods
TA-GCN [[2]](#2), ST-BLN [[3]](#3) and PST-GCN [[4]](#4) for Skeleton-based Human
Action Recognition.
The ST-GCN, TA-GCN and ST-BLN methods can be run and evaluated using stgcn_learner by specifying the model name.
The PST-GCN method can be run and evaluated using pstgcn_learner.

This implementation is adapted from the [OpenMMLAB toolbox](
https://github.com/open-mmlab/mmskeleton/tree/b4c076baa9e02e69b5876c49fa7c509866d902c7).

## Datasets
### NTU-RGB+D-60
The NTU-RGB+D [[5]](#5) is the largest indoor-captured action recognition dataset which contains different data modalities
including the $3$D skeletons captured by Kinect-v2 camera. It contains 56,000 action clips from $60$ different action
classes and each action clip is captured by 3 cameras with 3 different views, and provides two different benchmarks,
cross-view (CV) and cross-subject (CS).
In this dataset, the number of joints in each skeleton is 25 and each sample has a sequence of 300 skeletons with 3
different channels each.
### Kinetics-400
The Kinetics-Skeleton [[6]](#6) dataset is a widely used action recognition dataset which contains the skeleton data of
300,000 video clips of 400 different actions collected from YouTube. In this dataset each skeleton in a sequence has 18
joints which are estimated by the OpenPose toolbox [[7]](#7) and each joint is featured by its 2D coordinates and
confidence score. We used the preprocessed data provided by [[1]](#1) and it can be downloaded from [here](
https://drive.google.com/file/d/103NOL9YYZSW1hLoWmYnv5Fs8mK-Ij7qb/view).

## References

<a id="1">[1]</a>
[Yan, S., Xiong, Y., & Lin, D. (2018, April). Spatial temporal graph convolutional networks for skeleton-based action
recognition. In Proceedings of the AAAI conference on artificial intelligence (Vol. 32, No. 1).](
https://arxiv.org/abs/1609.02907)

<a id="2">[2]</a>
[Heidari, N., & Iosifidis, A. (2020). Temporal Attention-Augmented Graph Convolutional Network for Efficient Skeleton-
Based Human Action Recognition. arXiv preprint arXiv: 2010.12221.](https://arxiv.org/abs/2010.12221)

<a id="3">[3]</a>
[Heidari, N., & Iosifidis, A. (2020). On the spatial attention in Spatio-Temporal Graph Convolutional Networks for
skeleton-based human action recognition. arXiv preprint arXiv: 2011.03833.](https://arxiv.org/abs/2011.03833)

<a id="4">[4]</a>
[Heidari, N., & Iosifidis, A. (2020). Progressive Spatio-Temporal Graph Convolutional Network for Skeleton-Based Human
Action Recognition. arXiv preprint arXiv:2011.05668.](https://arxiv.org/pdf/2011.05668.pdf)

<a id="5">[5]</a>
[Shahroudy, A., Liu, J., Ng, T. T., & Wang, G. (2016). Ntu rgb+ d: A large scale dataset for 3d human activity analysis.
In Proceedings of the IEEE conference on computer vision and pattern recognition (pp. 1010-1019).](
https://openaccess.thecvf.com/content_cvpr_2016/html/Shahroudy_NTU_RGBD_A_CVPR_2016_paper.html)

<a id="6">[6]</a>
[Kay, W., Carreira, J., Simonyan, K., Zhang, B., Hillier, C., Vijayanarasimhan, S., ... & Zisserman, A. (2017).
The kinetics human action video dataset. arXiv preprint arXiv:1705.06950.](https://arxiv.org/pdf/1705.06950.pdf)

<a id="7">[7]</a>
[Cao, Z., Simon, T., Wei, S. E., & Sheikh, Y. (2017). Realtime multi-person 2d pose estimation using part affinity
fields. In Proceedings of the IEEE conference on computer vision and pattern recognition (pp. 7291-7299).](
https://openaccess.thecvf.com/content_cvpr_2017/html/Cao_Realtime_Multi-Person_2D_CVPR_2017_paper.html)