Skip to content

Commit 8eb960b

Browse files
committed
2 parents c7f4b5d + 668f1c5 commit 8eb960b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+2845
-169
lines changed

data/image/no/image1.jpeg

53.2 KB

data/image/no/image10.jpg

3.76 KB

data/image/no/image11.jpg

3.39 KB

data/image/no/image12.jpg

4.04 KB

data/image/no/image13.jpg

4.46 KB

data/image/no/image14.jpg

5.9 KB

data/image/no/image15.jpg

6.76 KB

data/image/no/image16.jpg

5.27 KB

data/image/no/image17.jpg

5.73 KB

data/image/no/image18.jpg

5.71 KB

data/image/no/image19.jpg

7.63 KB

data/image/no/image2.jpeg

77.8 KB

data/image/no/image20.jpg

5.68 KB

data/image/no/image21.jpg

7 KB

data/image/no/image22.jpg

8.69 KB

data/image/no/image23.jpg

5.74 KB

data/image/no/image24.jpg

7.7 KB

data/image/no/image25.jpg

7.14 KB

data/image/no/image26.jpg

5.27 KB

data/image/no/image27.jpg

5.97 KB

data/image/no/image28.jpg

6.25 KB

data/image/no/image29.jpg

9.12 KB

data/image/no/image3.jpg

5.79 KB

data/image/no/image30.jpg

6.95 KB

data/image/no/image31.jpg

5.82 KB

data/image/no/image32.jpg

5.01 KB

data/image/no/image33.jpg

4.28 KB

data/image/no/image34.jpg

5.88 KB

data/image/no/image35.jpg

4.99 KB

data/image/no/image36.jpg

6.61 KB

data/image/no/image37.jpg

7.2 KB

data/image/no/image38.jpg

6.91 KB

data/image/no/image39.jpg

5.62 KB

data/image/no/image4.jpg

6.25 KB

data/image/no/image40.jpg

5.62 KB

data/image/no/image41.jpg

4.46 KB

data/image/no/image42.jpg

5.66 KB

data/image/no/image43.jpg

18.8 KB

data/image/no/image44.jpg

24.2 KB

data/image/no/image45.jpg

58.4 KB

data/image/no/image46.jpg

4.33 KB

data/image/no/image47.jpeg

34.1 KB

data/image/no/image48.jpg

5.07 KB

data/image/no/image49.jpg

6 KB

data/image/no/image5.jpg

6.37 KB

data/image/no/image50.JPG

23.5 KB

data/image/no/image51.JPG

16.5 KB

data/image/no/image52.jpg

14.2 KB

data/image/no/image53.jpg

6.25 KB

data/image/no/image54.jpg

7.68 KB

data/image/no/image55.jpg

31.1 KB

data/image/no/image56.jpg

11.2 KB

data/image/no/image57.jpg

6.55 KB

data/image/no/image58.jpg

31.8 KB

data/image/no/image59.JPG

24.1 KB

data/image/no/image6.jpg

3.59 KB

data/image/no/image60.JPG

16.7 KB

data/image/no/image61.jpg

95.4 KB

data/image/no/image62.JPG

19.3 KB

data/image/no/image63.JPG

17.8 KB

data/image/no/image64.jpg

5.07 KB

data/image/no/image65.jpg

5.26 KB

data/image/no/image66.jpg

6.08 KB

data/image/no/image67.jpg

14.2 KB

data/image/no/image68.jpeg

27.8 KB

data/image/no/image69.jpg

7.77 KB

data/image/no/image7.jpg

74.6 KB

data/image/no/image70.jpeg

80.4 KB

data/image/no/image71.jpg

26.1 KB

data/image/no/image72.png

711 KB

data/image/no/image73.jpg

42.3 KB

data/image/no/image74.jpg

37.5 KB

data/image/no/image75.jpg

14.7 KB

data/image/no/image76.jpeg

54.1 KB

data/image/no/image77.jpg

4.92 KB

data/image/no/image78.jpg

53.2 KB

data/image/no/image79.jpg

39.3 KB

data/image/no/image8.jpg

7.2 KB

data/image/no/image80.jpg

299 KB

data/image/no/image81.jpg

27.7 KB

data/image/no/image82.jpg

154 KB

data/image/no/image83.jpg

40.6 KB

data/image/no/image84.jpg

4.16 KB

data/image/no/image85.jpg

5.05 KB

data/image/no/image86.jpg

184 KB

data/image/no/image87.jpg

80.4 KB

data/image/no/image88.jpg

38 KB

data/image/no/image89.jpg

21.6 KB

data/image/no/image9.jpg

3.76 KB

data/image/no/image90.jpg

14.9 KB

data/image/no/image91.jpg

116 KB

data/image/no/image92.jpg

7.07 KB

data/image/no/image93.jpg

116 KB

data/image/no/image94.jpg

156 KB

data/image/no/image95.jpg

196 KB

data/image/no/image96.jpg

27.6 KB

data/image/no/image97.jpg

34.5 KB

data/image/no/image98.jpg

35.9 KB

numpy/image.py

+198-55
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,14 @@
33
import os
44
import pytest
55
import matplotlib.pyplot as plt
6+
import sparse
7+
from util import ImagePydataSparseTensorLoader, safeCastPydataTensorToInts
68

7-
images_path = "./numpy/images"
8-
9-
def load_dataset(image_folder):
10-
files = sorted(os.listdir(image_folder))
11-
images = []
12-
for f in files:
13-
path = os.path.join(image_folder, f)
14-
img = cv2.imread(path)
15-
img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
16-
images.append(img)
17-
18-
images = np.stack(images, axis=0)
19-
return images
20-
21-
def thresh(images, t=85):
22-
if len(images.shape) < 3:
23-
images = np.expand_dims(images, axis=0)
24-
thresh_imgs = []
25-
for i in range(images.shape[0]):
26-
img = images[i]
27-
ret, thresh_img = cv2.threshold(img, t, 255, cv2.THRESH_BINARY)
28-
thresh_imgs.append(thresh_img)
29-
30-
thresh_imgs = np.stack(thresh_imgs, axis=0)
31-
return thresh_imgs
32-
33-
def plot_image(img, img1, img2, xor_img, t1, t2):
34-
f, ax = plt.subplots(2, 2)
9+
10+
# plot_image plots the given original, binned, xor, and sparse xor images
11+
# for the numpy/image.py. Used for debugging only with the --plot flag
12+
def plot_image(img, img1, img2, xor_img, sparse_xor_img, t1, t2, window=None):
13+
f, ax = plt.subplots(2, 3)
3514
ax[0, 0].imshow(img1, 'gray')
3615
ax[0, 0].title.set_text("Binned Image 1. t1 = " + str(t1))
3716

@@ -43,36 +22,200 @@ def plot_image(img, img1, img2, xor_img, t1, t2):
4322

4423
ax[1, 1].imshow(xor_img, 'gray')
4524
ax[1, 1].title.set_text("XOR Image")
46-
25+
26+
ax[1, 2].imshow(sparse_xor_img, 'gray')
27+
ax[1, 2].title.set_text("Sparse XOR Image")
28+
29+
if window is not None:
30+
ax[0, 2].imshow(window, 'gray')
31+
ax[0, 2].title.set_text("Fused Window Image")
32+
4733
f.tight_layout()
4834
plt.show()
4935

50-
@pytest.mark.parametrize("t1", [100, 150, 200, 250])
51-
def bench_edge_detection(tacoBench, t1, plot):
52-
images = load_dataset(images_path)
53-
54-
sat_images = images[:,:,:,1]
55-
56-
img = sat_images[0]
57-
58-
t2 = t1 - 50
59-
60-
bin_img1 = thresh(img, t1)
61-
bin_img2 = thresh(img, t2)
62-
num_elements = float(np.prod(bin_img1.shape))
63-
64-
def bench():
65-
xor_img = np.logical_xor(bin_img1[0], bin_img2[0]).astype('int')
66-
return xor_img
67-
ret = tacoBench(bench)
68-
xor_img = bench()
69-
if plot:
70-
plot_image(img, bin_img1[0], bin_img2[0], xor_img, t1, t2)
71-
72-
print("Sparsity img 1 ", np.sum(bin_img1 != 0) / num_elements)
73-
print("Sparsity img 2 ", np.sum(bin_img2 != 0) / num_elements)
74-
print("Sparsity xor ", np.sum(xor_img != 0) / num_elements)
75-
36+
37+
@pytest.mark.parametrize("num", list(range(1, 99)))
38+
@pytest.mark.parametrize("pt1", [0.5])
39+
def bench_edge_detection_pydata(tacoBench, num, pt1, plot):
40+
loader = ImagePydataSparseTensorLoader()
41+
sparse_bin_img1 = safeCastPydataTensorToInts(loader.sparse_image(num, pt1, 1))
42+
sparse_bin_img2 = safeCastPydataTensorToInts(loader.sparse_image(num, pt1+0.05, 2))
43+
bin_img1 = loader.dense_image(num, pt1, 1)
44+
bin_img2 = loader.dense_image(num, pt1 + 0.05, 2)
45+
if plot:
46+
print(sparse_bin_img1.shape)
47+
print(sparse_bin_img2.shape)
48+
49+
def sparse_bench():
50+
sparse_xor_img = np.logical_xor(sparse_bin_img1, sparse_bin_img2).astype('int')
51+
return sparse_xor_img
52+
53+
def dense_bench():
54+
xor_img = np.logical_xor(bin_img1, bin_img2).astype('int')
55+
return xor_img
56+
ret = tacoBench(sparse_bench)
57+
sparse_xor_img = sparse_bench()
58+
xor_img = dense_bench()
59+
60+
assert(sparse_xor_img.nnz == np.sum(xor_img != 0))
61+
62+
if plot:
63+
num_elements = float(np.prod(bin_img1.shape))
64+
print("Sparse xor NNZ = ", sparse_xor_img.nnz, "\t", "Dense xor NNZ = ", np.sum(xor_img != 0))
65+
print("Sparsity img 1 ", np.sum(bin_img1 != 0) / num_elements)
66+
print("Sparsity img 2 ", np.sum(bin_img2 != 0) / num_elements)
67+
print("Sparsity xor ", np.sum(xor_img != 0) / num_elements)
68+
sparse_xor_img = sparse_xor_img.todense()
69+
t1 = round(loader.max[num]*pt1, 2)
70+
t2 = round(loader.max[num]*(pt1 + 0.05), 2)
71+
plot_image(loader.img[num], bin_img1, bin_img2, xor_img, sparse_xor_img, t1, t2)
72+
73+
@pytest.mark.parametrize("num", list(range(1, 99)))
74+
@pytest.mark.parametrize("pt1", [0.5])
75+
def bench_edge_detection_dense(tacoBench, num, pt1):
76+
loader = ImagePydataSparseTensorLoader()
77+
bin_img1 = loader.dense_image(num, pt1, 1)
78+
bin_img2 = loader.dense_image(num, pt1 + 0.05, 2)
79+
80+
def dense_bench():
81+
xor_img = np.logical_xor(bin_img1, bin_img2).astype('int')
82+
return xor_img
83+
tacoBench(dense_bench)
84+
85+
@pytest.mark.parametrize("num", list(range(1, 99)))
86+
@pytest.mark.parametrize("pt1", [0.5])
87+
def bench_edge_detection_fused_pydata(tacoBench, num, pt1, plot):
88+
loader = ImagePydataSparseTensorLoader()
89+
sparse_bin_img1 = safeCastPydataTensorToInts(loader.sparse_image(num, pt1, 1))
90+
sparse_bin_img2 = safeCastPydataTensorToInts(loader.sparse_image(num, pt1+0.05, 2))
91+
sparse_bin_window = loader.sparse_window(num, 3)
92+
bin_img1 = loader.dense_image(num, pt1, 1)
93+
bin_img2 = loader.dense_image(num, pt1 + 0.05, 2)
94+
bin_window = loader.dense_window(num)
95+
96+
if plot:
97+
print(sparse_bin_img1.shape)
98+
print(sparse_bin_img2.shape)
99+
100+
def sparse_bench():
101+
sbi1 = np.logical_and(sparse_bin_img1, sparse_bin_window)
102+
sbi2 = np.logical_and(sparse_bin_img2, sparse_bin_window)
103+
sparse_xor_img = np.logical_xor(sbi1, sbi2).astype('int')
104+
return sparse_xor_img
105+
106+
def dense_bench():
107+
bi1 = np.logical_and(bin_img1, bin_window).astype('int')
108+
bi2 = np.logical_and(bin_img2, bin_window).astype('int')
109+
xor_img = np.logical_xor(bi1, bi2).astype('int')
110+
return xor_img
111+
ret = tacoBench(sparse_bench)
112+
sparse_xor_img = sparse_bench()
113+
xor_img = dense_bench()
114+
115+
if plot:
116+
num_elements = float(np.prod(bin_img1.shape))
117+
print("Sparse xor NNZ = ", sparse_xor_img.nnz, "\t", "Dense xor NNZ = ", np.sum(xor_img != 0))
118+
print("Sparsity img 1 ", np.sum(bin_img1 != 0) / num_elements)
119+
print("Sparsity img 2 ", np.sum(bin_img2 != 0) / num_elements)
120+
print("Sparsity xor ", np.sum(xor_img != 0) / num_elements)
121+
sparse_xor_img = sparse_xor_img.todense()
122+
t1 = round(loader.max[num]*pt1, 2)
123+
t2 = round(loader.max[num]*(pt1 + 0.05), 2)
124+
plot_image(loader.img[num], bin_img1, bin_img2, xor_img, sparse_xor_img, t1, t2, bin_window)
125+
126+
assert(sparse_xor_img.nnz == np.sum(xor_img != 0))
127+
128+
@pytest.mark.parametrize("num", list(range(1, 99)))
129+
@pytest.mark.parametrize("pt1", [0.5])
130+
def bench_edge_detection_fused_dense(tacoBench, num, pt1):
131+
loader = ImagePydataSparseTensorLoader()
132+
bin_img1 = loader.dense_image(num, pt1, 1)
133+
bin_img2 = loader.dense_image(num, pt1 + 0.05, 2)
134+
bin_window = loader.dense_window(num)
135+
136+
def dense_bench():
137+
bi1 = np.logical_and(bin_img1, bin_window).astype('int')
138+
bi2 = np.logical_and(bin_img2, bin_window).astype('int')
139+
xor_img = np.logical_xor(bin_img1, bin_img2).astype('int')
140+
return xor_img
141+
tacoBench(dense_bench)
142+
143+
#TODO: Add in a benchmark that uses windowing for medical imaging as well.
144+
@pytest.mark.parametrize("num", list(range(1, 99)))
145+
@pytest.mark.parametrize("pt1", [0.5])
146+
@pytest.mark.parametrize("window_size", [0.25, 0.2, 0.15, 0.1])
147+
def bench_edge_detection_window_pydata(tacoBench, num, pt1, window_size, plot):
148+
loader = ImagePydataSparseTensorLoader()
149+
sparse_bin_img1 = safeCastPydataTensorToInts(loader.sparse_image(num, pt1, 1))
150+
sparse_bin_img2 = safeCastPydataTensorToInts(loader.sparse_image(num, pt1+0.05, 2))
151+
bin_img1 = loader.dense_image(num, pt1, 1)
152+
bin_img2 = loader.dense_image(num, pt1 + 0.05, 2)
153+
154+
mid0 = int(bin_img1.shape[0]/2)
155+
mid1 = int(bin_img1.shape[1]/2)
156+
157+
win_len0 = int(window_size * bin_img1.shape[0])
158+
win_len1 = int(window_size * bin_img1.shape[1])
159+
160+
if plot:
161+
print(sparse_bin_img1.shape)
162+
print(sparse_bin_img2.shape)
163+
164+
def sparse_bench():
165+
swin1 = sparse_bin_img1[mid0 - win_len0:mid0 + win_len0, mid1 - win_len1:mid1 + win_len1]
166+
swin2 = sparse_bin_img2[mid0 - win_len0:mid0 + win_len0, mid1 - win_len1:mid1 + win_len1]
167+
sparse_xor_img = np.logical_xor(swin1, swin2).astype('int')
168+
return sparse_xor_img
169+
170+
def dense_bench():
171+
win1 = bin_img1[mid0 - win_len0:mid0 + win_len0, mid1 - win_len1:mid1 + win_len1]
172+
win2 = bin_img2[mid0 - win_len0:mid0 + win_len0, mid1 - win_len1:mid1 + win_len1]
173+
xor_img = np.logical_xor(win1, win2).astype('int')
174+
return xor_img
175+
176+
ret = tacoBench(sparse_bench)
177+
sparse_xor_img = sparse_bench()
178+
xor_img = dense_bench()
179+
180+
if plot:
181+
print(sparse_xor_img)
182+
print("sparse img1 nnz =", sparse_bin_img1.nnz, " ", np.sum(bin_img1 != 0))
183+
print("sparse img2 nnz =", sparse_bin_img2.nnz, " ", np.sum(bin_img2 != 0))
184+
num_elements = float(np.prod(bin_img1.shape))
185+
print("Sparse xor NNZ = ", sparse_xor_img.nnz, "\t", "Dense xor NNZ = ", np.sum(xor_img != 0))
186+
print("Sparsity img 1 ", np.sum(bin_img1 != 0) / num_elements)
187+
print("Sparsity img 2 ", np.sum(bin_img2 != 0) / num_elements)
188+
print("Sparsity xor ", np.sum(xor_img != 0) / num_elements)
189+
sparse_xor_img = sparse_xor_img.todense()
190+
t1 = round(loader.max[num]*pt1, 2)
191+
t2 = round(loader.max[num]*(pt1 + 0.05), 2)
192+
print(xor_img)
193+
plot_image(loader.img[num], bin_img1, bin_img2, xor_img, sparse_xor_img, t1, t2)
194+
195+
assert(sparse_xor_img.nnz == np.sum(xor_img != 0))
196+
197+
@pytest.mark.parametrize("num", list(range(1, 99)))
198+
@pytest.mark.parametrize("pt1", [0.5])
199+
@pytest.mark.parametrize("window_size", [0.25, 0.2, 0.15, 0.1])
200+
def bench_edge_detection_window_dense(tacoBench, num, pt1, window_size):
201+
loader = ImagePydataSparseTensorLoader()
202+
bin_img1 = loader.dense_image(num, pt1, 1)
203+
bin_img2 = loader.dense_image(num, pt1 + 0.05, 2)
204+
205+
mid0 = int(bin_img1.shape[0]/2)
206+
mid1 = int(bin_img1.shape[1]/2)
207+
208+
win_len0 = int(window_size * bin_img1.shape[0])
209+
win_len1 = int(window_size * bin_img1.shape[1])
210+
211+
def dense_bench():
212+
win1 = bin_img1[mid0 - win_len0:mid0 + win_len0, mid1 - win_len1:mid1 + win_len1]
213+
win2 = bin_img2[mid0 - win_len0:mid0 + win_len0, mid1 - win_len1:mid1 + win_len1]
214+
xor_img = np.logical_xor(win1, win2).astype('int')
215+
return xor_img
216+
217+
tacoBench(dense_bench)
218+
76219
if __name__=="__main__":
77220
main()
78221

numpy/minmax.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import numpy as np
2+
from scipy.sparse import random, csr_matrix
3+
import sparse
4+
import pytest
5+
import os
6+
from util import TensorCollectionFROSTT, PydataTensorShifter, TensorCollectionSuiteSparse, ScipyTensorShifter, PydataMatrixMarketTensorLoader, ScipyMatrixMarketTensorLoader, VALIDATION_OUTPUT_PATH, PydataSparseTensorDumper, SuiteSparseTensor, safeCastPydataTensorToInts, RandomPydataSparseTensorLoader
7+
8+
@pytest.mark.parametrize("dims", [3, 5, 7])
9+
def bench_pydata_minmax(tacoBench, dims):
10+
loader = RandomPydataSparseTensorLoader()
11+
dims_list = [20] + [20] + [43 for ele in range(dims)]
12+
#FIXME: loader.random is always between 0 and 1, need to be larger. multiply by some value and then store to tns file
13+
#TODO: matrix shouldn't be completely random. it should have blocks of dense values (to simulate pruning)
14+
# and not just sparse uniform sampling
15+
16+
matrix = safeCastPydataTensorToInts(20*loader.random(dims_list, 0.10))
17+
print(matrix)
18+
def bench():
19+
reduced = matrix
20+
for m in range(len(dims_list)):
21+
if m % 2 == 0:
22+
reduced = np.max(reduced, -1)
23+
else:
24+
reduced = np.min(reduced, -1)
25+
print(reduced)
26+
print(np.max(reduced))
27+
print(reduced)
28+
return reduced
29+
tacoBench(bench)

0 commit comments

Comments
 (0)