Ejemplo n.º 1
0
Archivo: train.py Proyecto: kdai/yqhkjw
def test():
    summary = defaultdict(float)
    f.eval()
    gt_dict = np.load(args.test_path + '/gt_dict.npy',
                      allow_pickle=True).tolist()
    category_dict = gt_dict[args.domain]
    videos = list(category_dict.keys())
    total_features = np.load(os.path.join(args.test_path, "feature",
                                          "{}_audio.npy".format(args.domain)),
                             allow_pickle=True).tolist()
    with torch.no_grad():
        for v in tqdm(videos):
            features = total_features[v]
            scores = []
            for feature in features:
                x = feature["features"]
                logging.info("size of input: {}".format(x.shape))
                if x.shape != (20, 23):
                    if np.size(x) < 20 * 23:
                        x = np.pad(x, ((0, 20 - x.shape[0]),
                                       (0, 23 - x.shape[1])),
                                   mode="constant")
                    else:
                        x = x[0:20, 0:23]
                x = torch.unsqueeze(torch.unsqueeze(torch.Tensor(x), dim=0),
                                    dim=0).to(device)
                scores.append(f(x).item())
            summary[v] = scores
    machine_summary = tools.clip2frame(summary)
    return evaluate(machine_summary, category_dict, args.topk_mAP)
Ejemplo n.º 2
0
Archivo: train.py Proyecto: kdai/yqhkjw
def test():

    summary = defaultdict(float)
    f.eval()
    gt_dict = np.load(args.test_path + '/gt_' + args.dataset + '.npy',
                      allow_pickle=True).tolist()
    category_dict = gt_dict[args.domain]
    videos = list(category_dict.keys())
    video_features = np.load(args.test_path + '/feature/' + args.domain +
                             '_1s.npy',
                             allow_pickle=True).tolist()
    audio_features = np.load(args.test_path + '/feature/' + args.domain +
                             '_audio_edited_nopost.npy',
                             allow_pickle=True).tolist()
    # pdb.set_trace()
    with torch.no_grad():
        for ve in tqdm(videos):
            label = category_dict[ve]
            prefix = ve.split('.')[0]
            vfs = video_features[prefix]
            afs = audio_features[prefix]
            scores = []
            for vf, af in zip(vfs, afs):
                vseg = vf['segment']
                aseg = af['segment']
                visual = torch.Tensor(vf['features']).to(device).view(
                    -1, args.feature_dim).contiguous()
                audio = torch.Tensor(af['features']).to(device).view(
                    -1, args.audio_dim).contiguous()
                scores.append(f(visual, audio)[0].item())
            summary[ve] = scores
    mechine_summary = clip2frame(summary)
    mAP, pre, recall = evaluate(mechine_summary, category_dict, args.topk_mAP)
    return mAP, pre, recall
Ejemplo n.º 3
0
Archivo: train.py Proyecto: kdai/yqhkjw
def TVsumOrCoSumtest():

    summary = defaultdict(float)
    f.eval()
    gt_dict = np.load(args.test_path + '/gt_' + args.dataset + '.npy',
                      allow_pickle=True).tolist()
    category_dict = gt_dict[args.domain]
    videos = list(category_dict.keys())
    total_features = np.load(args.test_path + '/feature/' + args.domain +
                             '.npy',
                             allow_pickle=True).tolist()
    with torch.no_grad():
        for ve in tqdm(videos):
            label = category_dict[ve]
            feature = total_features[ve]
            scores = []
            for feat in feature:
                segment = feat['segment']
                scores.append(
                    f(torch.Tensor(feat['features']).to(device).view(
                        1, -1)).item())
            summary[ve] = scores
    mechine_summary = clip2frame(summary)
    mAP, pre, recall = TVsumOrCoSumEvaluate(mechine_summary, category_dict,
                                            args.topk_mAP)
    return mAP, pre, recall
Ejemplo n.º 4
0
def test():

    summary = defaultdict(float)
    f.eval()
    gt_dict = np.load(args.test_path+'/gt_'+args.dataset+'.npy',allow_pickle=True).tolist()
    category_dict = gt_dict[args.domain]
    videos = list(category_dict.keys())
    video_features = np.load(args.test_path+'/feature/'+args.domain+'_1s.npy',allow_pickle=True ).tolist()
    audio_features = np.load(args.test_path+'/feature/'+args.domain+'_audio_edited_nopost.npy',allow_pickle=True ).tolist()
    # pdb.set_trace()
    with torch.no_grad():
        for ve in tqdm(videos):
            label = category_dict[ve]
            prefix = ve.split('.')[0]
            vfs = video_features[prefix]
            afs = audio_features[prefix]
            scores = []
            length = len(vfs) if len(vfs)<len(afs) else len(afs)
            alen = len(afs)
            vlen = len(vfs)
            for idx in range(length):
                vx = []
                if idx<int(args.temporalN/2):
                    vx+=([[0]*args.feature_dim for i in range(int(args.temporalN/2)-idx)])
                    vx+=([vfs[i]['features'] for i in range(idx+1)])
                else:
                    vx+=([vfs[i]['features'] for i in range(idx-int(args.temporalN/2),idx+1)])
                if idx>=vlen-int(args.temporalN/2):
                    vx+=([vfs[i]['features'] for i in range(idx+1,vlen)])
                    vx+=([[0]*args.feature_dim for i in range(idx - (vlen-int(args.temporalN/2))+1)])
                else:
                    vx+=([vfs[i]['features'] for i in range(idx+1,idx+int(args.temporalN/2)+1)])

                ax = []
                if idx<int(args.temporalN/2):
                    ax+=([[0]*args.audio_dim for i in range(int(args.temporalN/2)-idx)])
                    ax+=([afs[i]['features'] for i in range(idx+1)])
                else:
                    ax+=([afs[i]['features'] for i in range(idx-int(args.temporalN/2),idx+1)])

                if idx>=alen-int(args.temporalN/2):
                    ax+=([afs[i]['features'] for i in range(idx+1,alen)])
                    ax+=([[0]*args.audio_dim for i in range(idx - (alen-int(args.temporalN/2))+1)])
                else:
                    ax+=([afs[i]['features'] for i in range(idx+1,idx+int(args.temporalN/2)+1)])
                # pdb.set_trace()
                vx = torch.tensor(vx).to(device).unsqueeze(0).unsqueeze(0)
                ax = torch.tensor(ax).to(device).unsqueeze(0).unsqueeze(0)

                # vseg = vf['segment']
                # aseg = af['segment']
                # visual = torch.Tensor(vf['features']).to(device).view(-1,args.feature_dim).contiguous()
                # audio = torch.Tensor(af['features']).to(device).view(-1,args.audio_dim).contiguous()
                scores.append(f(vx,ax)[0].item())
            summary[ve] = scores
    mechine_summary = clip2frame(summary)
    mAP,pre,recall = evaluate(mechine_summary,category_dict,args.topk_mAP)
    return mAP,pre,recall
Ejemplo n.º 5
0
def test():

    summary = defaultdict(float)
    f.eval()
    gt_dict = np.load(args.test_path + '/gt_' + args.dataset + '.npy',
                      allow_pickle=True).tolist()
    category_dict = gt_dict[args.domain]
    videos = list(category_dict.keys())

    video_features = np.load(args.test_path + '/feature/' + args.domain +
                             '_1s.npy',
                             allow_pickle=True).tolist()
    audio_features = np.load(args.test_path + '/feature/' + args.domain +
                             '_audio_edited_nopost.npy',
                             allow_pickle=True).tolist()
    with torch.no_grad():
        for ve in tqdm(videos):
            label = category_dict[ve]
            prefix = ve.split('.')[0]
            vfs = video_features[prefix]
            afs = audio_features[prefix]
            scores = []
            vfeat = []
            afeat = []

            for vf, af in zip(vfs, afs):
                vfeat.append(vf['features'])
                afeat.append(af['features'])
            if (len(afeat) == 0):
                continue

            vfeat = torch.Tensor(vfeat).to(device).unsqueeze(0)
            afeat = torch.Tensor(afeat).to(device).unsqueeze(0)
            scores, logits = f(vfeat, afeat)
            # pdb.set_trace()
            summary[ve] = scores.cpu().numpy().reshape(-1).tolist()
    mechine_summary = clip2frame(summary)
    mAP, pre, recall = evaluate(mechine_summary, category_dict, args.topk_mAP)
    return mAP, pre, recall
Ejemplo n.º 6
0
Archivo: test.py Proyecto: kdai/yqhkjw
def test():
    summary = defaultdict(float)
    f.eval()
    # test_feature_path = args.test_path+'/feature/'+args.domain
    gt_dict = np.load(args.test_path+'/gt_dict.npy',allow_pickle=True).tolist()
    # pdb.set_trace()
    category_dict = gt_dict[args.domain]
    videos = list(category_dict.keys())
    total_features = np.load(args.test_path+'/feature/'+args.domain+'.npy',allow_pickle=True ).tolist()
    with torch.no_grad():
        for ve in tqdm(videos):
            label = category_dict[ve]
            # feature = np.load(test_feature_path+'/'+ve+'.npy').tolist()
            feature = total_features[ve]
            scores = []
            for feat in feature:
                segment = feat['segment']
                scores.append(f(torch.Tensor(feat['features']).to(device).view(1,-1)).item())
            summary[ve] = scores
    # gt_domain_dict = 
    mechine_summary = clip2frame(summary)
    ret = evaluate(mechine_summary,category_dict,args.topk_mAP)
    print(ret)
    print('aaaa')