DIM=256,
                                  classes=opt.n_classes)

    # HCN pre-trained model
    if opt.temporal_length == 25:
        fc7_dim = 2048
    elif opt.temporal_length == 60:
        fc7_dim = 4096
    if opt.num_per == 1:
        hcn_model = HCN4(in_channel=3,
                         num_person=1,
                         num_class=49,
                         fc7_dim=fc7_dim).cuda()
    elif opt.num_per == 2:
        hcn_model = HCN(in_channel=3,
                        num_person=2,
                        num_class=49,
                        fc7_dim=fc7_dim).cuda()

    if opt.act_pretrain == 1:
        #hcn_model_path = '/fast-stripe/workspaces/deval/synthetic-data/hcn/CCC_models/clall_len60_per1/model_state.pth'
        if opt.real_per == 100:
            hcn_model_path = '/fast-stripe/workspaces/deval/synthetic-data/hcn/int_act_val_split_len60_per1/model_state.pth'
        if opt.real_per == 25:
            hcn_model_path = '/fast-stripe/workspaces/deval/synthetic-data/hcn/clall_len60_per1_realper25/model_state.pth'
        hcn_model.load_state_dict(
            torch.load(hcn_model_path)['best_test_model'], strict=False)
        print("Loaded action model", hcn_model_path, "| Best test per",
              torch.load(hcn_model_path)['best_test_perf'],
              "| Best test epoch",
              torch.load(hcn_model_path)['best_test_epoch'])
    else:
示例#2
0
        images_dir = os.path.join('/fast-stripe/workspaces/deval/synthetic-data/wgan_gp_action_class',str(class_num),opt.expt,'images')
        videos_dir = os.path.join('/fast-stripe/workspaces/deval/synthetic-data/wgan_gp_action_class',str(class_num),opt.expt,'videos')
        models_dir = os.path.join('/fast-stripe/workspaces/deval/synthetic-data/wgan_gp_action_class',str(class_num),opt.expt,'models')
        os.makedirs(images_dir, exist_ok=True)
        os.makedirs(ckpt_dir, exist_ok=True)
        os.makedirs(videos_dir,exist_ok=True)

        #HCN Pre-trained model
        if opt.temporal_length == 25:
            fc7_dim = 2048
        elif opt.temporal_length == 60:
            fc7_dim = 4096
        if opt.num_per == 1:
            hcn_model = HCN1per_feat_1(in_channel=3,num_person=1,num_class=49,fc7_dim=fc7_dim).cuda()
        elif opt.num_per == 2:
            hcn_model = HCN(in_channel=3,num_person=2,num_class=49,fc7_dim=fc7_dim).cuda() 
        hcn_model_path = '/fast-stripe/workspaces/deval/synthetic-data/hcn/CCC_models/clall_len60_per1/model_state.pth'
        hcn_model.load_state_dict(torch.load(hcn_model_path)['best_test_model'], strict=False)
        print ("Loaded model",hcn_model_path,"| Best test per",torch.load(hcn_model_path)['best_test_perf'],"| Best test epoch",torch.load(hcn_model_path)['best_test_epoch'])

        # Loss weight for gradient penalty
        lambda_gp = opt.lambda_gp

        # Initialize generator and discriminator
        if opt.arch == 'mlp':
            if opt.feat_concat == 0:
                generator = Generator(latent_dim=opt.latent_dim,img_shape=img_shape)
            elif opt.feat_concat == 512:
                generator = Generator_concat512(latent_dim=opt.latent_dim,img_shape=img_shape)
            discriminator = Discriminator(img_shape=img_shape)
        elif opt.arch == 'cnn':
    # Initialize generator and discriminator
    if opt.arch == 'mlp':
        generator = Generator(latent_dim = opt.latent_dim, img_shape=img_shape, n_classes=opt.n_classes)
        discriminator = Discriminator(img_shape = img_shape, n_classes=opt.n_classes)
    elif opt.arch == 'cnn':
        generator = Generator_cnn(latent_dim=opt.latent_dim,DIM=256,classes=opt.n_classes)

    # HCN pre-trained model
    if opt.temporal_length == 25:
        fc7_dim = 2048
    elif opt.temporal_length == 60:
        fc7_dim = 4096
    if opt.num_per == 1:
        hcn_model = HCN4(in_channel=3,num_person=1,num_class=49,fc7_dim=fc7_dim).cuda()
    elif opt.num_per == 2:
        hcn_model = HCN(in_channel=3,num_person=2,num_class=49,fc7_dim=fc7_dim).cuda() 
    
    if opt.act_pretrain == 1:
        #hcn_model_path = '/fast-stripe/workspaces/deval/synthetic-data/hcn/CCC_models/clall_len60_per1/model_state.pth'        
        hcn_model_path = '/fast-stripe/workspaces/deval/synthetic-data/hcn/int_act_val_split_len60_per1/model_state.pth'
        hcn_model.load_state_dict(torch.load(hcn_model_path)['best_test_model'], strict=False)
        print ("Loaded action model",hcn_model_path,"| Best test per",torch.load(hcn_model_path)['best_test_perf'],"| Best test epoch",torch.load(hcn_model_path)['best_test_epoch'])
    else:
        print ("Not using any pretrained action classifer, training from scratch")
    if opt.gen_pretrain == 1:
        gen_model_path = '/fast-stripe/workspaces/deval/synthetic-data/cgan/img25_changelabels_per1_ep5k/models/3000/model_state_100.pth'
        generator.load_state_dict(torch.load(gen_model_path)['last_state_dict_G'], strict=True)
        print ("Loaded generator model",gen_model_path)
    else:
        print ("Not using any pretrained generator, training from scratch")
    os.makedirs(videos_dir, exist_ok=True)
    os.makedirs(models_dir, exist_ok=True)

    #HCN Pre-trained model
    if opt.temporal_length == 25:
        fc7_dim = 2048
    elif opt.temporal_length == 60:
        fc7_dim = 4096
    if opt.num_per == 1:
        hcn_model = HCN1per_feat_1(in_channel=3,
                                   num_person=1,
                                   num_class=49,
                                   fc7_dim=fc7_dim).cuda()
    elif opt.num_per == 2:
        hcn_model = HCN(in_channel=3,
                        num_person=2,
                        num_class=49,
                        fc7_dim=fc7_dim).cuda()
    hcn_model_path = '/fast-stripe/workspaces/deval/synthetic-data/hcn/CCC_models/clall_len60_per1/model_state.pth'
    hcn_model.load_state_dict(torch.load(hcn_model_path)['best_test_model'],
                              strict=False)
    print("Loaded model", hcn_model_path, "| Best test per",
          torch.load(hcn_model_path)['best_test_perf'], "| Best test epoch",
          torch.load(hcn_model_path)['best_test_epoch'])

    # Loss functions
    adversarial_loss = torch.nn.MSELoss()
    triplet_loss_torch = torch.nn.TripletMarginLoss(
        margin=opt.margin)  #2.0 default
    cosine_embedding_loss = torch.nn.CosineEmbeddingLoss(
        margin=opt.margin)  #0.5 default
    #adversarial_loss = torch.nn.BCEWithLogitsLoss()
示例#5
0
    if args.temporal_length == 25:
        fc7_dim = 2048
    elif args.temporal_length == 60:
        fc7_dim = 4096

    if args.feat_map == 0:
        if args.arch == 'hcn':
            if args.num_person == 1:
                net = HCN4(
                    in_channel=3, num_person=1, num_class=49, fc7_dim=fc7_dim
                ).to(
                    device
                )  # HCN4 - FC8 HCN with 512 as fc; HCN1per_256_fc9 - FC9 with 256&512 as FCs
            elif args.num_person == 2:
                net = HCN(in_channel=3,
                          num_person=2,
                          num_class=49,
                          fc7_dim=fc7_dim).to(device)
        elif args.arch == 'hcn_ensemble':
            net = ensemble_model(arch=args.arch,
                                 num_person=args.num_person,
                                 num_classes=49,
                                 fc7_dim=fc7_dim,
                                 device=device)
    elif args.feat_map == 1 or args.feat_map == 2:
        if args.arch == 'hcn':
            if args.num_person == 1:
                net = HCN1per_feat256_fc9(
                    in_channel=3, num_person=1, num_class=49, fc7_dim=fc7_dim
                ).to(
                    device
                )  # HCN1per_feat_1 - FC8 with 512 feat maps; HCN1per_feat256_fc9 - 256 feature maps