-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVC_perclip.py
71 lines (55 loc) · 1.75 KB
/
VC_perclip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import numpy as np
import os
from PIL import Image
#from utils import Evaluator
import sys
def get_common(list_,predlist,clip_num,h,w):
accs = []
for i in range(len(list_)-clip_num):
global_common = np.ones((h,w))
predglobal_common = np.ones((h,w))
for j in range(1,clip_num):
common = (list_[i] == list_[i+j])
global_common = np.logical_and(global_common,common)
pred_common = (predlist[i]==predlist[i+j])
predglobal_common = np.logical_and(predglobal_common,pred_common)
pred = (predglobal_common*global_common)
acc = pred.sum()/global_common.sum()
accs.append(acc)
return accs
DIR='/your/path/to/VSPW_480p'
Pred='./predicts'
split = 'val.txt'
with open(os.path.join(DIR,split),'r') as f:
lines = f.readlines()
for line in lines:
videolist = [line[:-1] for line in lines]
total_acc=[]
clip_num=16
for video in videolist:
if video[0]=='.':
continue
imglist = []
predlist = []
images = sorted(os.listdir(os.path.join(DIR,'data',video,'mask')))
if len(images)<=clip_num:
continue
for imgname in images:
if imgname[0]=='.':
continue
img = Image.open(os.path.join(DIR,'data',video,'mask',imgname))
w,h = img.size
img = np.array(img)
imglist.append(img)
pred = Image.open(os.path.join(Pred,video,imgname))
pred = np.array(pred)
predlist.append(pred)
accs = get_common(imglist,predlist,clip_num,h,w)
print(sum(accs)/len(accs))
total_acc.extend(accs)
Acc = np.array(total_acc)
Acc = np.nanmean(Acc)
print(Pred)
print('*'*10)
print('VC{} score: {} on {} set'.format(clip_num,Acc,split))
print('*'*10)