forked from eriklindernoren/Fast-Neural-Style-Transfer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorScript.py
More file actions
67 lines (58 loc) · 2.24 KB
/
Copy patherrorScript.py
File metadata and controls
67 lines (58 loc) · 2.24 KB
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
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--groundtruth", type=str, required=True, dest="groundtruth",
help="Directory path to batch of ground truth images")
parser.add_argument("--stylizedmodel", action="store", dest="stylizedmodel",
help="Directory path to batch of stylized images")
args = parser.parse_args()
def readPaths(groundtruth, model):
groundtruthFrames = []
modelFrames = []
for i in [groundtruth, model]:
sortedFiles = sorted(glob.glob(i + "/*.png"))
for im_path in sortedFiles:
im = imageio.imread(im_path)
if i is groundtruth:
groundtruthFrames.append(im)
else:
modelFrames.append(im)
return groundtruthFrames, modelFrames
def temporalError(groundtruthFrames, modelFrames):
H, W, C = groundtruthFrames[0].shape
D = H * W * C
T = len(groundtruthFrames)
errorAvg = 0
errorList = []
eps = 0.01
for img in range(T - 1):
gtDiff = groundtruthFrames[img] - groundtruthFrames[img + 1]
modelFrames_r1 = np.resize(modelFrames[img], (H, W, C))
modelFrames_r2 = np.resize(modelFrames[img + 1], (H, W, C))
modelDiff = modelFrames_r1 - modelFrames_r2
frac = abs(np.square(gtDiff - modelDiff) / (gtDiff + eps)).mean()
#frac = abs(np.square(baselineDiff - modelDiff)).mean()
errorAvg += frac
errorList.append(frac)
errorAvg /= (T - 1)
return errorAvg, errorList
def SSIM(groundtruthFrames, modelFrames):
ssimTotal = 0;
ssimList = []
H, W, C = groundtruthFrames[0].shape
for i in range(len(groundtruthFrames)):
frame1 = groundtruthFrames[i]
frame2 = modelFrames[i]
frame2 = np.resize(frame2, (H, W, C))
value = ssim(frame1, frame2, multichannel = True)
ssimTotal += value
ssimList.append(value)
ssimAvg = ssimTotal / len(groundtruthFrames)
return ssimAvg, ssimList
def
if __name__ == "__main__":
groundtruthFrames, modelFrames = readPaths(args.groundtruth, args.stylizedmodel)
errorAvg, errorList = temporalError(groundtruthFrames, modelFrames)
ssimAvg, ssimList = SSIM(groundtruthFrames, modelFrames)
print(groundtruthFrames)
print(errorAvg)
print(ssimAvg)