from models.i3d.extract_i3d import ExtractI3D from utils.utils import build_cfg_path from omegaconf import OmegaConf import torch import numpy as np import os device = 'cuda' if torch.cuda.is_available() else 'cpu' torch.cuda.get_device_name(0) dir_name = '/content/drive/MyDrive/ds_study/data/train' file_names = os.listdir(dir_name) # Select the feature type feature_type = 'i3d' # Load and patch the config args = OmegaConf.load(build_cfg_path(feature_type)) # args.show_pred = True # args.stack_size = 24 # args.step_size = 24 # args.extraction_fps = 25 args.flow_type = 'raft' # 'pwc' is not supported on Google Colab # args.streams = 'flow' # Load the model extractor = ExtractI3D(args) # Extract features for filename in file_names: video_paths = [] video_paths.append(os.path.join(dir_name, filename)) for path in video_paths: args.video_paths = path print(f'Extracting for {args.video_paths}') feature_dict = extractor.extract(args.video_paths) feat_file = '%s_feat.npy' % path.split('/')[7][:-4] save_path = '../drive/MyDrive/ds_study/data/train_feature/' np.save(os.path.join(save_path, feat_file), feature_dict['rgb'])
GLUON API를 이용했을 때 잘 되지 않아서 ExtractI3D 모듈을 사용하여 비디오의 특징을 추출했다. colab pro에서 gpu를 썼는데도 너무 오래걸렸다.
Reference: https://v-iashin.github.io/video_features/