from __future__ import division from __future__ import print_function import os import time from utils.utils import * from config import parse_opts from torch.utils.data import DataLoader import factory.model_factory as model_factory from transforms.target_transforms import ClassLabel from factory.data_factory import get_validation_set from transforms.temporal_transforms import TemporalCenterCrop from transforms.spatial_transforms import Compose, Normalize, ToTensor, CenterCrop os.environ["CUDA_VISIBLE_DEVICES"] = '1' # 运行环境 config = parse_opts() # 配置解析 config = prepare_output_dirs(config) # 输出文件夹初始化 config = init_cropping_scales(config) # 裁剪配置 config = set_lr_scheduling_policy(config) # 学习率配置 # 均值和方差设置 mean = [0.485, 0.456, 0.406] std = [0.229, 0.224, 0.225] # 设置转换函数 norm_method = Normalize(mean, std) validation_transforms = { 'spatial': Compose([CenterCrop(config.spatial_size), ToTensor(255), norm_method]), 'temporal': TemporalCenterCrop(config.sample_duration), 'target':
text_file.close() #################################################################### #################################################################### if __name__ == "__main__": count = 0 while count < len(song_list): print('=' * 60) print(song_list[count]) selected_music = song_list[count] count += 1 config = parse_opts() config = prepare_walter_dirs(config, selected_music) audio_url = os.path.join(config.walter_ip, selected_music, 'audio', 'input_audio.wav') video_url = os.path.join(config.walter_ip, selected_music, 'input_resize_480_360.mp4') audio_file = os.path.join(config.video_path, 'audio', 'input_audio.wav') input_video = os.path.join(config.video_path, 'input_resize_480_360.mp4') out_audio_dir = os.path.join(config.video_path, 'audio') out_gif_dir = os.path.join(config.video_path, 'gif') max_freq_csv = os.path.join(config.video_path, 'max_freq.csv')
logging.basicConfig(format = '%(message)s', datefmt = '%m/%d/%Y %H:%M:%S', level = logging.INFO) logger = logging.getLogger(__name__) device = torch.device("cuda" if torch.cuda.is_available() else "cpu") labels = ["A", "L", "H", "C", "R", "U", "P", "D", "F", "E", "N", "S", "G"] # labels = ["A", "L", "H", "C", "R", "U", "P", "D", "F", "E", "N", "T", "S", "G"] label2index = {} for label in labels: label2index[label] = len(label2index) opts = parse_opts() seed = opts.seed debugging = opts.debugging testing_phase = opts.testing use_embedding = opts.use_embedding reading_data = opts.reading_data use_lowercase = opts.use_lowercase unroll = opts.unroll replace_digits = opts.replace_digits predict_remote = opts.predict_remote logger.info("using seed %d" % seed) logger.info("is debugging: %s" % debugging) logger.info("testing: %s" % testing_phase) logger.info("predict remote edges: %s" % predict_remote)
import os import time import numpy as np from collections import defaultdict from sklearn.metrics import average_precision_score import torch from torch import nn, optim from torch.utils.data import DataLoader import torch.backends.cudnn as cudnn from lib.dataset import VideoDataset from lib import slowfastnet from tensorboardX import SummaryWriter from config import parse_opts # TODO: remove from being global params = parse_opts() class AverageMeter(object): """Computes and stores the average and current value""" def __init__(self): self.reset() def reset(self): self.val = 0 self.avg = 0 self.sum = 0 self.count = 0 def update(self, val, n=1): self.val = val
video_features.append(outputs.cpu().data) video_features = torch.cat(video_features) elif opt.feature_type == 'OF': # preprocess transforms = Compose([Scale(opt.sample_size), CenterCrop(opt.sample_size), ToTensor(), Normalize(opt.mean, [1, 1, 1])]) frames = [transforms(img) for img in frames] frames = torch.stack(frames, 0).permute(1, 0, 2, 3) video_feature = get_OF_feature(frames) feats.append(video_feature) return feats def get_OF_feature(frames, opt): video_features = [] return video_features if __name__ == "__main__": # test opt = parse_opts() opt.frame_root = "/home/qianyu/task_video/data/ucf/ucf101-frames/" opt.sample_size = 16 feats = feature_extract(opt) print(len(feats))