Spaces:
Sleeping
Sleeping
marta-marta
commited on
Commit
·
558fff7
1
Parent(s):
132cf03
test
Browse files- .idea/.gitignore +3 -0
- .idea/Plot_Interps.iml +8 -0
- .idea/inspectionProfiles/Project_Default.xml +16 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +4 -0
- .idea/modules.xml +8 -0
- app.py +131 -0
.idea/.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
.idea/Plot_Interps.iml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$" />
|
5 |
+
<orderEntry type="inheritedJdk" />
|
6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
7 |
+
</component>
|
8 |
+
</module>
|
.idea/inspectionProfiles/Project_Default.xml
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<profile version="1.0">
|
3 |
+
<option name="myName" value="Project Default" />
|
4 |
+
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
5 |
+
<option name="ignoredPackages">
|
6 |
+
<value>
|
7 |
+
<list size="3">
|
8 |
+
<item index="0" class="java.lang.String" itemvalue="scipy" />
|
9 |
+
<item index="1" class="java.lang.String" itemvalue="pytictoc" />
|
10 |
+
<item index="2" class="java.lang.String" itemvalue="pickle" />
|
11 |
+
</list>
|
12 |
+
</value>
|
13 |
+
</option>
|
14 |
+
</inspection_tool>
|
15 |
+
</profile>
|
16 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (AutoEncoders) (2)" project-jdk-type="Python SDK" />
|
4 |
+
</project>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/Plot_Interps.iml" filepath="$PROJECT_DIR$/.idea/Plot_Interps.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
app.py
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from scipy import signal
|
3 |
+
import huggingface_hub # for loading model
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
|
7 |
+
def basic_box_array(image_size: int, thickness: int) -> np.ndarray:
|
8 |
+
"""
|
9 |
+
:param image_size: [int] - the size of the image that will be produced
|
10 |
+
:param thickness: [int] - the number of pixels to be activated surrounding the base shape
|
11 |
+
:return: [ndarray] - the output is a unit cell with outer pixels activated based on the desired thickness.
|
12 |
+
The activated pixels are 1 (white) and the deactivated pixels are 0 (black)
|
13 |
+
"""
|
14 |
+
A = np.ones((int(image_size), int(image_size))) # Initializes A matrix with 0 values
|
15 |
+
A[1:-1, 1:-1] = 0 # replaces all internal rows/columns with 0's
|
16 |
+
A = add_thickness(A, thickness)
|
17 |
+
return A
|
18 |
+
|
19 |
+
|
20 |
+
def back_slash_array(image_size: int, thickness: int) -> np.ndarray:
|
21 |
+
"""
|
22 |
+
:param image_size: [int] - the size of the image that will be produced
|
23 |
+
:param thickness: [int] - the number of pixels to be activated surrounding the base shape
|
24 |
+
:return: [ndarray] - the output is a unit cell with pixels activated along the downward diagonal based
|
25 |
+
on the desired thickness. The activated pixels are 1 (white) and the deactivated pixels are 0 (black)
|
26 |
+
"""
|
27 |
+
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
|
28 |
+
np.fill_diagonal(A, 1) # fills the diagonal with 1 values
|
29 |
+
A = add_thickness(A, thickness)
|
30 |
+
return A
|
31 |
+
|
32 |
+
|
33 |
+
def forward_slash_array(image_size: int, thickness: int) -> np.ndarray:
|
34 |
+
"""
|
35 |
+
:param image_size: [int] - the size of the image that will be produced
|
36 |
+
:param thickness: [int] - the number of pixels to be activated surrounding the base shape
|
37 |
+
:return: [ndarray] - the output is a unit cell with pixels activated along the upward diagonal based on the desired
|
38 |
+
thickness. The activated pixels are 1 (white) and the deactivated pixels are 0 (black)
|
39 |
+
"""
|
40 |
+
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
|
41 |
+
np.fill_diagonal(np.fliplr(A), 1) # Flips the array to then fill the diagonal the opposite direction
|
42 |
+
A = add_thickness(A, thickness)
|
43 |
+
return A
|
44 |
+
|
45 |
+
|
46 |
+
def hot_dog_array(image_size: int, thickness: int) -> np.ndarray:
|
47 |
+
"""
|
48 |
+
:param image_size: [int] - the size of the image that will be produced
|
49 |
+
:param thickness: [int] - the number of pixels to be activated surrounding the base shape
|
50 |
+
:return: [ndarray] - the output is a unit cell with outer pixel activated from the vertical center based on the
|
51 |
+
desired thickness. The activated pixels are 1 (white) and the deactivated pixels are 0 (black)
|
52 |
+
"""
|
53 |
+
# Places pixels down the vertical axis to split the box
|
54 |
+
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
|
55 |
+
A[:, np.floor((image_size - 1) / 2).astype(int)] = 1 # accounts for even and odd values of image_size
|
56 |
+
A[:, np.ceil((image_size - 1) / 2).astype(int)] = 1
|
57 |
+
A = add_thickness(A, thickness)
|
58 |
+
return A
|
59 |
+
|
60 |
+
|
61 |
+
def hamburger_array(image_size: int, thickness: int) -> np.ndarray:
|
62 |
+
"""
|
63 |
+
:param image_size: [int] - the size of the image that will be produced
|
64 |
+
:param thickness: [int] - the number of pixels to be activated surrounding the base shape
|
65 |
+
:return: [ndarray] - the output is a unit cell with outer pixel activated from the horizontal center based on the
|
66 |
+
desired thickness. The activated pixels are 1 (white) and the deactivated pixels are 0 (black)
|
67 |
+
"""
|
68 |
+
# Places pixels across the horizontal axis to split the box
|
69 |
+
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
|
70 |
+
A[np.floor((image_size - 1) / 2).astype(int), :] = 1 # accounts for even and odd values of image_size
|
71 |
+
A[np.ceil((image_size - 1) / 2).astype(int), :] = 1
|
72 |
+
A = add_thickness(A, thickness)
|
73 |
+
return A
|
74 |
+
|
75 |
+
|
76 |
+
########################################################################################################################
|
77 |
+
# The function to add thickness to struts in an array
|
78 |
+
def add_thickness(array_original, thickness: int) -> np.ndarray:
|
79 |
+
"""
|
80 |
+
:param array_original: [ndarray] - an array with thickness 1 of any shape type
|
81 |
+
:param thickness: [int] - the number of pixels to be activated surrounding the base shape
|
82 |
+
:return: [ndarray] - the output is a unit cell that has been convolved to expand the number of pixels activated
|
83 |
+
based on the desired thickness. The activated pixels are 1 (white) and the deactivated pixels are 0 (black)
|
84 |
+
"""
|
85 |
+
A = array_original
|
86 |
+
if thickness == 0: # want an array of all 0's for thickness = 0
|
87 |
+
A[A > 0] = 0
|
88 |
+
else:
|
89 |
+
filter_size = 2*thickness - 1 # the size of the filter needs to extend far enough to reach the base shape
|
90 |
+
filter = np.zeros((filter_size, filter_size))
|
91 |
+
filter[np.floor((filter_size - 1) / 2).astype(int), :] = filter[:, np.floor((filter_size - 1) / 2).astype(int)] =1
|
92 |
+
filter[np.ceil((filter_size - 1) / 2).astype(int), :] = filter[:, np.ceil((filter_size - 1) / 2).astype(int)] = 1
|
93 |
+
# The filter is made into a '+' shape using these functions
|
94 |
+
convolution = signal.convolve2d(A, filter, mode='same')
|
95 |
+
A = np.where(convolution <= 1, convolution, 1)
|
96 |
+
return A
|
97 |
+
|
98 |
+
|
99 |
+
# The function to efficiently combine arrays in a list
|
100 |
+
def combine_arrays(arrays):
|
101 |
+
output_array = np.sum(arrays, axis=0) # Add the list of arrays
|
102 |
+
output_array = np.array(output_array > 0, dtype=int) # Convert all values in array to 1
|
103 |
+
return output_array
|
104 |
+
|
105 |
+
|
106 |
+
########################################################################################################################
|
107 |
+
# Provide the Options for users to select from
|
108 |
+
shape_options = ("basic_box", "diagonal_box_split", "horizontal_vertical_box_split", "back_slash_box", "forward_slash_box",
|
109 |
+
"back_slash_plus_box", "forward_slash_plus_box", "hot_dog_box", "hamburger_box", "x_hamburger_box",
|
110 |
+
"x_hot_dog_box", "x_plus_box")
|
111 |
+
density_options = ["{:.2f}".format(x) for x in np.linspace(0.1, 1, 10)]
|
112 |
+
thickness_options = [str(int(x)) for x in np.linspace(0, 10, 11)]
|
113 |
+
interpolation_options = [str(int(x)) for x in [3, 5, 10, 20]]
|
114 |
+
|
115 |
+
# Select the Options
|
116 |
+
shape_1 = st.selectbox("Please select a shape", shape_options)
|
117 |
+
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
+
# Load the models from existing huggingface model
|
125 |
+
# Load the encoder model
|
126 |
+
encoder_model_boxes = huggingface_hub.from_pretrained_keras("cmudrc/2d-lattice-encoder")
|
127 |
+
# Load the decoder model
|
128 |
+
decoder_model_boxes = huggingface_hub.from_pretrained_keras("cmudrc/2d-lattice-decoder")
|
129 |
+
|
130 |
+
|
131 |
+
|