-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize.py
More file actions
83 lines (66 loc) · 2.44 KB
/
visualize.py
File metadata and controls
83 lines (66 loc) · 2.44 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
import matplotlib.pyplot as plt
import argparse
import numpy as np
import sys
from pathlib import Path
print("external:api=5")
WORKDIR = Path(__file__).parent
TYPES = {
"int8": np.int8,
"int16": np.int16,
"int32": np.int32,
"int64": np.int64,
"uint8": np.uint8,
"uint16": np.uint16,
"uint32": np.uint32,
"uint64": np.uint64,
"float": np.float32,
"double": np.float64
}
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--api", type=float)
parser.add_argument("--config_name")
parser.add_argument("--input", type=Path)
parser.add_argument("--decompressed", type=Path)
parser.add_argument("--dim", type=int, action="append", default=[])
parser.add_argument("--type", type=lambda name: TYPES[name], choices=TYPES.values())
return parser.parse_known_args()[0]
def select_slice(arr: np.ndarray) -> np.ndarray:
if len(arr.shape) == 2:
return arr
elif len(arr.shape) == 3:
x, y, z = arr.shape
return arr[x//2, :, :]
def plot_data(args):
print(args, file=sys.stderr)
# load the data
uncompressed = np.fromfile(args.input, dtype=args.type)
decompressed = np.fromfile(args.decompressed, dtype=args.type)
error_max = uncompressed.max() - uncompressed.min()
vmin = uncompressed.min() - .1*error_max
vmax = uncompressed.max() + .1*error_max
uncompressed = select_slice(uncompressed)
decompressed = select_slice(decompressed)
errors = uncompressed - decompressed
fig, ax = plt.subplots()
ax.hist(errors.ravel(), range=(-.008*error_max, .008*error_max), bins=100)
ax.set_title(args.config_name)
fig.savefig(WORKDIR / "figures" / (args.config_name + "-hist.png"))
# plot the error in place
fig, ax = plt.subplots()
ax.set_title(args.config_name)
ax.imshow(np.abs(errors), vmin=0, vmax=error_max*.01)
fig.savefig(WORKDIR / "figures" / (args.config_name + "-err.png"))
# plot a side-by-side visualization
fig, ax = plt.subplots(1, 2)
ax[0].set_title(args.config_name + " uncompressed")
ax[0].imshow(uncompressed, vmax=vmax, vmin=vmin)
ax[1].set_title(args.config_name + " decompressed")
ax[1].imshow(decompressed, vmax=vmax, vmin=vmin)
fig.savefig(WORKDIR / "figures" / (args.config_name + "-compare.png"))
if __name__ == "__main__":
args = parse_args()
if args.input:
plot_data(args)