Commit
·
9f580f1
1
Parent(s):
561a837
Saving attempts at optimizing
Browse files
Data_Generation/Dataset_Generation_Functions.py
CHANGED
@@ -1,5 +1,13 @@
|
|
1 |
import numpy as np
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
########################################################################################################################
|
5 |
# Make the data using all the code in Shape_Generation_Functions.py
|
@@ -11,28 +19,102 @@ def make_boxes(image_size, densities, shapes):
|
|
11 |
:return: [list[tuple]] - [Array, Density, Thickness, Shape]
|
12 |
"""
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
matrix = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
return matrix
|
34 |
|
35 |
|
36 |
########################################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
|
|
|
|
|
|
|
|
38 |
|
|
|
|
|
|
|
|
1 |
import numpy as np
|
2 |
|
3 |
+
from Data_Generation.Shape_Generation_Functions import basic_box, diagonal_box_split, horizontal_vertical_box_split, \
|
4 |
+
back_slash_box, forward_slash_box, back_slash_plus_box, forward_slash_plus_box, hot_dog_box, hamburger_box, \
|
5 |
+
x_hamburger_box, x_hot_dog_box, x_plus_box
|
6 |
+
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
|
9 |
+
from Data_Generation.Piecewise_Box_Functions import add_pixels
|
10 |
+
|
11 |
|
12 |
########################################################################################################################
|
13 |
# Make the data using all the code in Shape_Generation_Functions.py
|
|
|
19 |
:return: [list[tuple]] - [Array, Density, Thickness, Shape]
|
20 |
"""
|
21 |
|
22 |
+
# matrix = []
|
23 |
+
#
|
24 |
+
# for function in shapes: # Adds different types of shapes
|
25 |
+
#
|
26 |
+
# # Adds different density values
|
27 |
+
# for i in range(len(densities)):
|
28 |
+
# # Loops through the possible thickness values
|
29 |
+
# for j in range(image_size): # Adds additional Pixels
|
30 |
+
# thickness = j
|
31 |
+
# Array = (function(thickness, densities[i], image_size))
|
32 |
+
#
|
33 |
+
# # Checks if there are any 0's left in the array to append
|
34 |
+
# if (np.where((Array == float(0)))[0] > 0).any():
|
35 |
+
# the_tuple = (Array, str(function.__name__), densities[i], thickness)
|
36 |
+
# matrix.append(the_tuple)
|
37 |
+
#
|
38 |
+
# # Prevents solids shapes from being appended to the array
|
39 |
+
# else:
|
40 |
+
# break
|
41 |
matrix = []
|
42 |
+
base_shapes = []
|
43 |
+
density_1 = []
|
44 |
+
for function in shapes: # Create an array of the base shapes
|
45 |
+
thickness = 0
|
46 |
+
Array = function(thickness, 1, image_size)
|
47 |
+
# density_1_tuple = np.array([Array, str(function.__name__), 1, thickness]) # Array, Shape, Density, Thickness
|
48 |
+
# base_shapes.append(density_1_tuple)
|
49 |
|
50 |
+
density_1 = np.append(density_1,(np.array([Array, str(function.__name__), 1, thickness])), axis=1) # Array, Shape, Density, Thickness
|
51 |
+
# Add one to the thickness of the previous array
|
52 |
+
# for j in range(image_size):
|
53 |
+
while (np.where((Array == float(0)))[0] > 0).any():
|
54 |
+
# Checks if there are any 0's left in the array to append
|
55 |
+
# if (np.where((Array == float(0)))[0] > 0).any():
|
56 |
+
# density_1.append(density_1_tuple, axis=0)
|
57 |
+
thickness += 1
|
58 |
+
if np.shape(density_1) == (4,):
|
59 |
+
Array = add_pixels(density_1[0], 1) # will add 1 pixel to each previous array, rather than adding multiple and having to loop
|
60 |
|
61 |
+
else:
|
62 |
+
print(np.shape(density_1))
|
63 |
+
print(density_1[-1][0])
|
64 |
+
Array = add_pixels(density_1[-1][0], 1)
|
65 |
+
# print(np.shape(Array))
|
66 |
+
density_1_tuple = np.array([Array, str(function.__name__), 1, thickness])
|
67 |
+
# else: # Prevents solids shapes from being appended to the array
|
68 |
+
# break
|
69 |
+
density_1 = np.vstack((density_1, density_1_tuple))
|
70 |
|
71 |
+
matrix = []
|
72 |
+
# print(np.shape(density_1[0]))
|
73 |
+
# print(density_1[:][0])
|
74 |
+
for i in range(len(densities)):
|
75 |
+
some = np.multiply(density_1[:][0],densities[i]) #,density_1[:1])
|
76 |
+
# print(np.shape(some))
|
77 |
+
matrix.append(tuple(some))
|
78 |
|
79 |
+
|
80 |
+
# # Adds different density values
|
81 |
+
# for i in range(len(densities)):
|
82 |
+
# # Loops through the possible thickness values
|
83 |
+
# for j in range(image_size): # Adds additional Pixels
|
84 |
+
# thickness = j
|
85 |
+
# Array = (function(thickness, densities[i], image_size))
|
86 |
+
#
|
87 |
+
# # Checks if there are any 0's left in the array to append
|
88 |
+
# if (np.where((Array == float(0)))[0] > 0).any():
|
89 |
+
# the_tuple = (Array, str(function.__name__), densities[i], thickness)
|
90 |
+
# matrix.append(the_tuple)
|
91 |
+
#
|
92 |
+
# # Prevents solids shapes from being appended to the array
|
93 |
+
# else:
|
94 |
+
# break
|
95 |
return matrix
|
96 |
|
97 |
|
98 |
########################################################################################################################
|
99 |
+
# Testing
|
100 |
+
image_size = 9
|
101 |
+
densities = [1]
|
102 |
+
shapes = [basic_box, diagonal_box_split, horizontal_vertical_box_split, back_slash_box, forward_slash_box,
|
103 |
+
back_slash_plus_box, forward_slash_plus_box, hot_dog_box, hamburger_box, x_hamburger_box,
|
104 |
+
x_hot_dog_box, x_plus_box]
|
105 |
+
|
106 |
+
boxes = make_boxes(image_size, densities, shapes)
|
107 |
+
|
108 |
+
# print(np.shape(boxes))
|
109 |
+
desired_label = 'basic_box'
|
110 |
+
desired_density = 1
|
111 |
+
desired_thickness = 0
|
112 |
|
113 |
+
box_arrays, box_shape, box_density, box_thickness, = list(zip(*boxes))[0], list(zip(*boxes))[1], list(zip(*boxes))[2], list(zip(*boxes))[3]
|
114 |
+
# print(np.shape(box_arrays))
|
115 |
+
# print(np.shape(box_shape))
|
116 |
+
# print(np.shape(box_density))
|
117 |
|
118 |
+
indices = [i for i in range(len(box_arrays)) if box_shape[i] == desired_label and box_density[i] == desired_density and box_thickness[i] == desired_thickness]
|
119 |
+
plt.imshow(box_arrays[indices[0]])
|
120 |
+
plt.show()
|