wesley231
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Action Recognition based on OpenPose ###### tags: `AI DJ` `Teaching` [TOC] ## Installation Open `train.py` and change some code. ~~from keras.layers.normalization import BatchNormalization from keras.optimizers import Adam~~ *to* ```python from tensorflow.keras.optimizers import Adam from keras.layers import Dense, Dropout, BatchNormalization ``` Open `generate_dets.py` in `Tracking/` & `pose_visualizer.py` in `Pose/` ~~import tensorflow as tf~~ *to* ```=python import tensorflow.compat.v1 as tf tf.disable_v2_behavior() ``` And `open generate_dets.py` in `Tracking/` & `pose_visualizer.py` in `Pose/` ~~with tf.gfile.GFile(checkpoint_filename, "rb") as f:~~ *to* with tf.io.gfile.GFile(graph_path, 'rb') as f: ## Training with own dataset Prepare data(actions) by running `main.py`, remember to uncomment the code of data collecting, the origin data will be saved as a `.txt`. ```python=72 f = open('origin_data.txt', 'a+') #saved name joints_norm_per_frame = np.array(pose[-1]).astype(np.str) f.write(' '.join(joints_norm_per_frame)) f.write('\n') ``` The `.txt` file will look like this: ![](https://i.imgur.com/kHpNeQD.png) and then use Excel to covert the `.txt` to `.csv` file. ![](https://i.imgur.com/qHuIGX5.png) ![](https://i.imgur.com/66G3JHB.png) Make sure to use Space as the delimiter. ![](https://i.imgur.com/rSaUBPV.png) Finally, you will get the `.csv` file like this: ![](https://i.imgur.com/s2WbNmU.png) And put this to `data_under_scene.csv` using the template (class start from 0). And open the `train.py` in `Action/training/` and **change the action_enum.** please also change the `action_enum.py` in `Action/` ```python=20 class Actions(Enum): wave = 0 idle = 1 ``` The number is the total number of skeleton The other is the amount of skeleton contained in each action: > [Class]*Amount ```python=104 X = dataset[0:3328, 0:36].astype(float) Y = dataset[0:3328, 36] encoder_Y = [0]*1384 + [1]*1944 ``` Model **(The parameter units is the number of your data classes. So just changing it the last one units.)** ```python=120 # build keras model model = Sequential() model.add(Dense(units=128, activation='relu')) model.add(BatchNormalization()) model.add(Dense(units=64, activation='relu')) model.add(Dropout(0.2)) model.add(Dense(units=32, activation='relu')) model.add(Dropout(0.2)) model.add(Dense(units=16, activation='relu')) model.add(Dropout(0.2)) model.add(Dense(units=2, activation='softmax')) # units = nums of classes #softmax ``` ## Data pre-processing Data preprocessing is a data mining technique that involves transforming raw data into an understandable format. Real-world data is often incomplete, inconsistent, and/or lacking in certain behaviors or trends, and is likely to contain many errors. Data preprocessing is a proven method of resolving such issues. ### Raw Data ![](https://i.imgur.com/qycp5rq.png) ### Filtered Data Filtered data where incomplete poses are eliminated. ![](https://i.imgur.com/bIpwfED.png) ## Added two pretrain model Mobilenet_v2_small/large ### How does it compare to the first generation of MobileNets? Overall, the MobileNetV2 models are **faster for the same accuracy** across the entire latency spectrum. In particular, the new models use 2x fewer operations, need **30% fewer parameters** and are about **30-40% faster** on a Google Pixel phone than MobileNetV1 models, all while **achieving higher accuracy.** ![](https://i.imgur.com/jXtLpA1.png) Download the **mobilenet_v2_small** + **mobilenet_v2_large** from [here](https://drive.google.com/drive/folders/1PpMUauDBbT3I85_rMDP6rQhWLRTBJCdK?usp=sharing), and put those file to `Pose/graph_models` Change the code of `utils.py`, so you can use the pretrain model by changing the `main.py` ```python=39 def load_pretrain_model(model): dyn_graph_path = { 'VGG_origin': str(file_path / "Pose/graph_models/VGG_origin/graph_opt.pb"), 'mobilenet_thin': str(file_path / "Pose/graph_models/mobilenet_thin/graph_opt.pb"), 'mobilenet_v2_small': str(file_path / "Pose/graph_models/mobilenet_v2_small/graph_opt.pb"), 'mobilenet_v2_large': str(file_path / "Pose/graph_models/mobilenet_v2_large/graph_opt.pb") } graph_path = dyn_graph_path[model] if not os.path.isfile(graph_path): raise Exception('Graph file doesn\'t exist, path=%s' % graph_path) ``` ### Testing Result (1 Person) Mobilenet_thin (The fastest but the accuracy is lowest): ![](https://i.imgur.com/f6JDHMn.png) MobileNet_v2_small (The second fastest accuracy is not bad): ![](https://i.imgur.com/n2mgKle.png) MobileNet_v2_large: ![](https://i.imgur.com/RGbcPH9.png) VGG (Highest accuracy, but **slowest**) ![](https://i.imgur.com/prPIbri.png) I will use VGG for training and MobileNet_v2_small for realtime detection. ## Result ### Result with two classes (Idle/Wave) #### 09/02 Classes: Wave & Idle Batch Size:16 Epochs: 50 **Accuraccy: 91%** ![](https://i.imgur.com/tf2Fddx.png) **Loss Curves:** ![](https://i.imgur.com/rbHE0vk.png) **Confusion Matrix (Normalized):** ![](https://i.imgur.com/5vkdkfU.png) **Difference:** In addition to the improvement in accuracy (about 10%), the previous model had misjudgments on the waist, but after increasing the data set and pre-processing the data, it has been significantly improved. | The Old One (08/30)|The New One (09/02) | | -------- | -------- | |![](https://i.imgur.com/bPGZ68u.png)| ![](https://i.imgur.com/GLW0DVq.png) | **Video:** Tested the result by using [KTH human actions dataset.](https://www.csc.kth.se/cvap/actions/) ![](https://i.imgur.com/GmaYJ1Z.gif) #### 08/30 Classes: Wave & Idle Batch Size:16 Epochs: 50 **Accuraccy: 81%** ![](https://i.imgur.com/MVcctwM.png) **Loss Curves:** ![](https://i.imgur.com/cM7dURg.png) **Confusion Matrix:** ![](https://i.imgur.com/tO22wDs.png) **Video:** ![](https://i.imgur.com/aXmrubc.gif) ### Result with three classes (Idle/Wave/Jump) #### 9/3 Classes: Wave & Idle & Jump Batch Size:16 Epochs: 50 **Accuraccy: 86%** ![](https://i.imgur.com/R6X1oSC.png) **Loss Curves:** ![](https://i.imgur.com/Lp9flt0.png) **Confusion Matrix (Normalized):** ![](https://i.imgur.com/L17UUAG.png) #### 08/30 Classes: Wave & Idle & Jump Batch Size:16 Epochs: 50 **Accuraccy:** ![](https://i.imgur.com/kzuzvat.png) **Loss Curves:** ![](https://i.imgur.com/XteuxFW.png) **Confusion Matrix:** ![](https://i.imgur.com/JOlQwSB.png) **Video:** https://drive.google.com/file/d/1UIq02hmFxgBFxuqt_2FrWRBc5HEWiFkf/view?usp=sharing ## Classify actions with dynamic sequential joints data ### Discuss with Prof. Chiang for reference point on Crowd Detection :::info **Question:** Now I want to use the LSTM model to classify action recognition using time series. At present, our idea is to judge actions with 10 frames. The Jump part of the Dataset action is to jump from the ground to the air and back to the ground as a group (10 frames), then a large number of labels and training The recognition part is that every 10 frames input will get an action estimation result Because we detect once every 10 frames (1-10, 11-20, 21-30...), the beginning of the detection may not be people preparing to jump up from the ground, it may be people jumping from the air. Drop down (only jump 15-25) I'm not sure if this will lead to inaccurate results. ::: :::danger **Answer by Prof. Chiang:** The training data suggestion can be (1-10, 2-11, 3-12...) In this way, there is a method of overlapping, and the amount of data can be more, so that the detection of this category will jump from bottom to top and then drop any 10 frames in this process, that is, the detection of vertical displacement will be recognized as a jump. ::: --- ### Create the dataset with 10 frame I group different video clips into groups of 10 frames. Each action will have 500 frames in total. (50 groups) - [x] Idle - [x] Wave - [x] Jump csv: https://drive.google.com/file/d/10UvHP5ZPGAH4UDQdrhWQ-RlyoZRaDDXR/view?usp=sharing ![](https://i.imgur.com/TaFzHVQ.png) ### Train the dataset using LSTM/GRU First, we have to change the input 2D tensor to 3D tensor. ```python=103 df = pd.read_csv('se.csv') dataset = np.array([matrix.to_numpy() for _, matrix in df.groupby('group')]) X = dataset[:,:,0:36].astype(float) Y = dataset[:,:, 36][:,0].astype(int) ``` and ```python=126 # train test split X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.1, random_state=42) ``` ### Build the LSTM model ```python=146 # build LSTM model model = Sequential() model.add(LSTM(64, return_sequences=True, activation='relu', input_shape=(10,36))) #10frame with 36keypoints model.add(LSTM(128, return_sequences=True, activation='relu')) model.add(LSTM(64, return_sequences=False, activation='relu')) model.add(Dense(64, activation='relu')) model.add(Dense(32, activation='relu')) model.add(Dense(3, activation='softmax')) ``` #### Result Training Loss: ![](https://i.imgur.com/9suCWnQ.png) Accuracy: **93%** ![](https://i.imgur.com/4XJxxrd.png) ![](https://i.imgur.com/IHNibAn.png) #### Build the GRU model ```python=146 # build GRU model model = Sequential() model.add(GRU(256, return_sequences=True, activation='relu', input_shape=(10,36))) #10frame with 36keypoints model.add(Dropout(0.1)) model.add(GRU(128, return_sequences=True, activation='relu')) model.add(Dropout(0.1)) model.add(GRU(64, return_sequences=False, activation='relu')) model.add(Dense(64, activation='relu')) model.add(Dense(32, activation='relu')) model.add(Dense(3, activation='softmax')) ``` ##### Result Training Loss: ![](https://i.imgur.com/Md86TPS.png) Accuracy: **93%** ![](https://i.imgur.com/34CbwjG.png) ![](https://i.imgur.com/SySNa3F.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully