import os import init_path import misc.config as cfg from misc.utils import concat_feat, get_dataloader, make_cuda, make_variable from misc.writer import RecordWriter from models import PCAWrapper, inception_v3 if __name__ == '__main__': # init Inception v3 model model = make_cuda( inception_v3(pretrained=True, transform_input=True, extract_feat=True)) model.eval() # init PCA model pca = PCAWrapper(n_components=cfg.n_components, batch_size=cfg.pca_batch_size) pca.load_params(filepath=cfg.pca_model) # data loader for frames in ingle video data_loader = get_dataloader(dataset="VideoFrame", path=cfg.video_file, num_frames=cfg.num_frames, batch_size=cfg.batch_size) # init writer writer = RecordWriter(filepath="data/test.tfrecord", level="frame") # extract features by inception_v3 feats = None for step, frames in enumerate(data_loader): print("extracting feature [{}/{}]".format(step + 1, len(data_loader)))
"""Main script for Youtube-8M feature extractor.""" import misc.config as cfg from misc.utils import concat_feat, get_dataloader, make_cuda, make_variable from models import PCAWrapper, inception_v3 if __name__ == '__main__': # init models and data loader model = make_cuda( inception_v3(pretrained=True, transform_input=True, extract_feat=True)) pca = PCAWrapper(n_components=cfg.n_components) model.eval() # data loader for frames in ingle video # data_loader = get_dataloader(dataset="VideoFrame", # path=cfg.video_file, # num_frames=cfg.num_frames, # batch_size=cfg.batch_size) # data loader for frames decoded from several videos data_loader = get_dataloader(dataset="FrameImage", path=cfg.frame_root, batch_size=cfg.batch_size) # extract features by inception_v3 feats = None for step, frames in enumerate(data_loader): print("extracting feature [{}/{}]".format(step + 1, len(data_loader))) feat = model(make_variable(frames)) feats = concat_feat(feats, feat.data.cpu()) # recude dimensions by PCA
"""Train PCA for Youtube-8M feature extractor.""" import os import torch import init_path import misc.config as cfg from misc.utils import concat_feat_var from models import PCAWrapper if __name__ == '__main__': # init models and data loader pca = PCAWrapper(n_components=cfg.n_components, batch_size=cfg.pca_batch_size) if os.path.exists(cfg.inception_v3_feats_path.format("total")): inception_v3_feats = torch.load( cfg.inception_v3_feats_path.format("total")) else: # get inception_v3 feats list feats_list = os.listdir(cfg.inception_v3_feats_root) feats_list = [ v for v in feats_list if os.path.splitext(v)[1] in cfg.inception_v3_feats_ext ] # load inception_v3 feats inception_v3_feats = None for step, feat_file in enumerate(feats_list):