NTU RGB+D 120 Divide the training set and test set, and generate label files.

NTU RGB+D 120 has a total of 120 classes and 114,480 samples. The size is about 262G. Includes
RGB video resolution of 1920x1080,

Both the depth map and the IR (infrared) video have a resolution of 512x424,

The 3D skeleton data contains 3D coordinates of 25 human joints per frame.

Each dataset was captured simultaneously by three Kinect V2 cameras.

original name

NTU RGB+D 120: A Large-Scale Benchmark for 3D Human Activity Understanding

The effect after processing is shown in the figure below

 Two methods of division in the original text

Before running the code, you need to understand the code yourself and modify the directory of the corresponding file. Otherwise it will be troublesome to mess up your own files.

 Cross-Subject Evaluation divides training set and test set

import os
import shutil  
# 我的开始目录为data/ntu_rgb_d/nturgbd_rgb_s001/nturgb+d_rgb
#data/ntu_rgb_d/nturgbd_rgb_s002/nturgb+d_rgb
#...
#data/ntu_rgb_d/nturgbd_rgb_s032/nturgb+d_rgb


dataset = 'test' #此处为划分出test数据集。划分出train数据集,只需修改为train再一次运行。
path = "data/ntu_rgb_d/" # 总的文件路径
nturgb = 'nturgb+d_rgb' 
dirs = os.listdir(path)
for file in dirs: #循环每一个目录中的每一个文件
    file_path = path + file + '/' + nturgb #到达具有视频的文件目录之下
    file = os.listdir(file_path)
    for video_id in file: #循环每一个每一个文件中的每一个视频名字
        person_id = int(video_id.split('P')[1][:3])
        # 以扩展名为名称的子文件夹
        person_id_training = [1, 2, 4, 5, 8, 9, 13, 14, 15, 16, 17, 18, 19, 25, 27, 28, 31, 34, 35, 38, 45, 46, 47, 49, 50, 52, 53, 54, 55, 56, 57, 58, 59, 70, 74, 78, 80, 81, 82, 83, 84, 85, 86, 89, 91, 92, 93, 94, 95, 97, 98, 100, 103]
        if dataset == 'train':
            person_id_to_keep = person_id_training
        else:
            person_id_to_keep = list(range(1, 107))
            person_id_to_keep = [p for p in person_id_to_keep if p not in person_id_training]
        
        if person_id in person_id_to_keep :
            folder_name = "data/NTU_RGB/" + dataset
            f = file_path + '/' + video_id
            # 如果不存在该目录,先创建,再移动文件
            if not os.path.exists(folder_name):
                os.makedirs(folder_name)
                shutil.move(f, folder_name)
            else:
                shutil.move(f, folder_name)

Cross-Subject Evaluation generates label files

import os
import shutil 
path = "data/NTU_RGB/test/"
dirs = os.listdir(path)
train_videos = "data/NTU_RGB/test_videos.txt"
for video_id in dirs:   
    with open(train_videos, 'a+') as f:
        f.writelines(video_id + ' ')
    action_id = int(video_id.split('A')[1][:3]) - 1
    action_id = str(action_id)
    with open(train_videos, 'a+') as f:
        f.writelines(action_id + '\n')

Cross-Setup Evaluation divides training set and test set

import os
import shutil   
#划分为训练集和测试集
dataset = 'test'
path = "data/NTU_RGB_CS2/"
nturgb = 'nturgb+d_rgb'
dirs = os.listdir(path)
for file in dirs:
    file_path = path + file + '/' + nturgb
    file = os.listdir(file_path)
    for video_id in file:
        S_id = int(video_id.split('P')[1][:3])
        # 以扩展名为名称的子文件夹
        S_id_testing = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105]
        if dataset == 'test':
            S_id_to_keep = S_id_testing
        else:
            S_id_to_keep = list(range(1, 107))
            S_id_to_keep = [p for p in S_id_to_keep if p not in S_id_testing]
        
        if S_id in S_id_to_keep :
            folder_name = "data/NTU_RGB2/" + dataset
            f = file_path + '/' + video_id
            # 如果不存在该目录,先创建,再移动文件
            if not os.path.exists(folder_name):
                os.makedirs(folder_name)
            # 举例:这里的f为 1.png 等同于 ./1.png (因为是相对路径)
                shutil.move(f, folder_name)
            # 直接移动文件
            else:
                shutil.move(f, folder_name)

Cross-Setup Evaluation and generate label files

#生成标签文件  
path = "data/NTU_RGB2/train/"
dirs = os.listdir(path)
train_videos = "data/NTU_RGB2/train_videos.txt"
for video_id in dirs:   
    with open(train_videos, 'a+') as f:
        f.writelines(video_id + ' ')
    action_id = int(video_id.split('A')[1][:3]) - 1
    action_id = str(action_id)
    with open(train_videos, 'a+') as f:
        f.writelines(action_id + '\n')

Guess you like

Origin blog.csdn.net/qq_42845932/article/details/126401452