Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anyone own working multi_test_models.py file? #18

Open
Raazzta opened this issue Jun 18, 2022 · 4 comments
Open

Anyone own working multi_test_models.py file? #18

Raazzta opened this issue Jun 18, 2022 · 4 comments

Comments

@Raazzta
Copy link

Raazzta commented Jun 18, 2022

@Phoenix1327 , @all After getting 10 clips, generated by multi_test_tea_something_rgb_8f.sh, and run multi_test_models.py, I face error something like "cannot broadcast bla bla " line ~45 or 46 and dont know the solution. Anyone has fixed this error? Really appreciate if someone willing to share if have it. Thanks!

@jwli6
Copy link

jwli6 commented Oct 9, 2022

multi_test_tea_something_rgb_8f.sh

NetWeight="checkpoint/TEA_something_RGB_tea50_shift8_blockres_avg_segment8_e50/ckpt.best.pth.tar" &&\
Segments=8 &&\
Crops=3 &&\
Clips=10 &&\
Batch_size=64 &&\
GPUS="0 1 2 3" &&\
Works=6 &&\
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=0 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=1 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=2 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=3 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=4 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=5 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=6 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=7 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=8 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=9 --full_res &&\

python ./multi_test_models.py something --test_crops=$Crops --num_clips=$Clips

@jwli6
Copy link

jwli6 commented Oct 9, 2022

multi_test_models.py

# -*- coding: utf-8 -*-
# phoenixyli 李岩 @2020-04-02 21:15:33

import os
import argparse
import time

import torch.nn.parallel
import torch.optim
from sklearn.metrics import confusion_matrix
from ops.dataset import TSNDataSet
from ops.models import TSN
from ops.transforms import *
from ops import dataset_config
from torch.nn import functional as F
import pickle

def accuracy(output, target, topk=(1,)):
    """Computes the precision@k for the specified values of k"""
    maxk = max(topk)
    # import pdb; pdb.set_trace()
    batch_size = target.size(0)
    _, pred = output.topk(maxk, 1, True, True)
    pred = pred.t()
    correct = pred.eq(target.view(1, -1).expand_as(pred))
    res = []
    correct=correct.contiguous()
    for k in topk:
         correct_k = correct[:k].view(-1).float().sum(0)
         res.append(correct_k.mul_(100.0 / batch_size))
    return res


parser = argparse.ArgumentParser(description="TEA testing on the full validation set")
parser.add_argument('dataset', type=str)
parser.add_argument('--test_crops', type=int, default=1)
parser.add_argument('--num_clips', type=int, default=10)

args = parser.parse_args()

output_dir = './result_file'
output_filepath = os.path.join(output_dir, '0'+'_'+'crop'+str(args.test_crops)+'.pkl')
with open(output_filepath, 'rb') as f:
    # output_file[0].shape: (11520, 174) output_file[1].shape:(11520,)
    output_file = pickle.load(f)
    num_videos = output_file[0].shape[0]
    num_classes = output_file[0].shape[1]

num_clips = args.num_clips
ens_pred_numpy = np.zeros((num_videos, num_classes))
ens_label_numpy = np.zeros((num_videos,))

for clip_index in range(num_clips):
    output_filepath = os.path.join(output_dir, str(clip_index)+'_'+'crop'+str(args.test_crops)+'.pkl')
    with open(output_filepath, 'rb') as f:
        output_file = pickle.load(f)
        pred_numpy = output_file[0]
        ens_pred_numpy  = ens_pred_numpy + pred_numpy
        label_numpy = output_file[1]
        ens_label_numpy = ens_label_numpy + label_numpy

ens_pred_numpy = ens_pred_numpy / num_clips
ens_label_numpy = ens_label_numpy / int(num_clips)

prec1, prec5 = accuracy(torch.from_numpy(ens_pred_numpy), torch.from_numpy(ens_label_numpy).type(torch.LongTensor), topk=(1, 5))

# import pdb; pdb.set_trace()

video_pred = [np.argmax(x) for x in ens_pred_numpy]
video_labels = [x for x in ens_label_numpy]

cf = confusion_matrix(video_labels, video_pred).astype(float)

cls_cnt = cf.sum(axis=1)
cls_hit = np.diag(cf)

cls_acc = cls_hit / cls_cnt
# print(cls_acc)
upper = np.mean(np.max(cf, axis=1) / cls_cnt)
# print('upper bound: {}'.format(upper))

print('-----Evaluation is finished------')
print('Class Accuracy {:.02f}%'.format(np.mean(cls_acc) * 100))
print('Overall Prec@1 {:.02f}% Prec@5 {:.02f}%'.format(prec1, prec5))

@jwli6
Copy link

jwli6 commented Oct 9, 2022

然后把这里改成pickle.dump([all_results,all_labels], f, pickle.HIGHEST_PROTOCOL)

@fbing998
Copy link

multi_test_tea_something_rgb_8f.sh

NetWeight="checkpoint/TEA_something_RGB_tea50_shift8_blockres_avg_segment8_e50/ckpt.best.pth.tar" &&\
Segments=8 &&\
Crops=3 &&\
Clips=10 &&\
Batch_size=64 &&\
GPUS="0 1 2 3" &&\
Works=6 &&\
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=0 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=1 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=2 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=3 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=4 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=5 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=6 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=7 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=8 --full_res &&\

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python test_models.py something \
    --arch='tea50' \
    --weight=$NetWeight \
    --worker=$Works --gpus $GPUS \
    --test_segments=$Segments --test_crops=$Crops \
    --batch_size=$Batch_size --shift --multi_clip_test \
    --clip_index=9 --full_res &&\

python ./multi_test_models.py something --test_crops=$Crops --num_clips=$Clips

Do you have the pretraining files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants