[Docs] Custom Dataset Training with PoseC3D
mohammed-alaa40123 opened this issue · comments
The doc issue
The tutorial needs to be updated because it says
ann_file_train = 'data/posec3d/custom_dataset_train.pkl' # Your annotation for training
ann_file_val = 'data/posec3d/custom_dataset_val.pkl' # Your annotation for validation
and there is only one ann_file in the config file then in the train/test/val data loaders do the splitting.
Another issue I encountered while using the ntu_pose_extraction I get only the annotations stored in the pkl file based on the old documentation in the website https://mmaction2.readthedocs.io/en/0.x/supported_datasets.html#the-format-of-posec3d-annotations
But the new format of the pose3d annotations suggests this https://github.com/open-mmlab/mmaction2/blob/main/tools/data/skeleton/README.md#the-format-of-annotations
I need some explanation if possible as I get this error
File "/content/drive/MyDrive/mmaction/mmaction2/mmaction/datasets/pose_dataset.py", line 66, in load_data_list
split, annos = data_list['split'], data_list['annotations']
TypeError: list indices must be integers or slices, not str
because my annotations.pkl file doesn't match the new pose_dataset format
dict_keys(['keypoint', 'keypoint_score', 'frame_dir', 'img_shape', 'original_shape', 'total_frames', 'label'])
This is the keys I find in the annotations pickle file There is no split nor annotations
import os
import random
import pickle
Path to the folder containing the pickle files (relative to the current working directory)
pkl_folder = ''
List to store paths of all pickle files
pkl_files = []
Iterate over each file in the folder
for file_name in os.listdir(pkl_folder):
if file_name.endswith('.pkl'):
pkl_files.append(os.path.join(pkl_folder, file_name))
Shuffle the list of pickle files
random.shuffle(pkl_files)
Calculate the split index for training and validation
split_index = int(0.8 * len(pkl_files))
Split the list of pickle files into training and validation sets
train_files = pkl_files[:split_index]
val_files = pkl_files[split_index:]
Function to merge pickle files
def merge_pickles(pickle_files, output_file):
split = {'xsub_train': [], 'xsub_val': [], 'xview_train': [], 'xview_val': []}
annotations = []
for pkl_file in pickle_files:
with open(pkl_file, 'rb') as f:
data = pickle.load(f)
# Update split dictionary and combine annotations
annotations.append(data)
# Assign videos to splits based on their indices
if pkl_file in train_files:
split['xsub_train'].append(data['frame_dir'])
else:
split['xsub_val'].append(data['frame_dir'])
# Save merged data into a single pickle file
merged_data = {'split': split, 'annotations': annotations}
with open(output_file, 'wb') as f:
pickle.dump(merged_data, f)
Merge pickle files for training and validation
merge_pickles(train_files + val_files, 'merged_data.pkl')
print("Merge completed!")
This should solve the problem in the annotations.pkl file :)