marta-marta
commited on
Commit
•
60acf32
1
Parent(s):
1fcdcb6
First commit
Browse files- .gitignore +185 -0
- .idea/.gitignore +3 -0
- .idea/.name +1 -0
- .idea/2D_Data_Generator.iml +8 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +4 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- 2D_Data_Generator_Model.py +82 -0
- Data_Generation/Dataset_Generation_Functions.py +38 -0
- Data_Generation/Piecewise_Box_Functions.py +88 -0
- Data_Generation/Shape_Generation_Functions.py +111 -0
- requirements.txt +0 -0
.gitignore
ADDED
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Created by .ignore support plugin (hsz.mobi)
|
2 |
+
### Python template
|
3 |
+
# Byte-compiled / optimized / DLL files
|
4 |
+
__pycache__/
|
5 |
+
*.py[cod]
|
6 |
+
*$py.class
|
7 |
+
|
8 |
+
# C extensions
|
9 |
+
*.so
|
10 |
+
|
11 |
+
# Distribution / packaging
|
12 |
+
.Python
|
13 |
+
env/
|
14 |
+
build/
|
15 |
+
develop-eggs/
|
16 |
+
dist/
|
17 |
+
downloads/
|
18 |
+
eggs/
|
19 |
+
.eggs/
|
20 |
+
lib/
|
21 |
+
lib64/
|
22 |
+
parts/
|
23 |
+
sdist/
|
24 |
+
var/
|
25 |
+
*.egg-info/
|
26 |
+
.installed.cfg
|
27 |
+
*.egg
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.coverage
|
43 |
+
.coverage.*
|
44 |
+
.cache
|
45 |
+
nosetests.xml
|
46 |
+
coverage.xml
|
47 |
+
*,cover
|
48 |
+
.hypothesis/
|
49 |
+
|
50 |
+
# Translations
|
51 |
+
*.mo
|
52 |
+
*.pot
|
53 |
+
|
54 |
+
# Django stuff:
|
55 |
+
*.log
|
56 |
+
local_settings.py
|
57 |
+
|
58 |
+
# Flask stuff:
|
59 |
+
instance/
|
60 |
+
.webassets-cache
|
61 |
+
|
62 |
+
# Scrapy stuff:
|
63 |
+
.scrapy
|
64 |
+
|
65 |
+
# Sphinx documentation
|
66 |
+
docs/_build/
|
67 |
+
|
68 |
+
# PyBuilder
|
69 |
+
target/
|
70 |
+
|
71 |
+
# IPython Notebook
|
72 |
+
.ipynb_checkpoints
|
73 |
+
|
74 |
+
# pyenv
|
75 |
+
.python-version
|
76 |
+
|
77 |
+
# celery beat schedule file
|
78 |
+
celerybeat-schedule
|
79 |
+
|
80 |
+
# dotenv
|
81 |
+
.env
|
82 |
+
|
83 |
+
# virtualenv
|
84 |
+
venv/
|
85 |
+
ENV/
|
86 |
+
|
87 |
+
# Spyder project settings
|
88 |
+
.spyderproject
|
89 |
+
|
90 |
+
# Rope project settings
|
91 |
+
.ropeproject
|
92 |
+
### VirtualEnv template
|
93 |
+
# Virtualenv
|
94 |
+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
|
95 |
+
[Bb]in
|
96 |
+
[Ii]nclude
|
97 |
+
[Ll]ib
|
98 |
+
[Ll]ib64
|
99 |
+
[Ll]ocal
|
100 |
+
[Ss]cripts
|
101 |
+
pyvenv.cfg
|
102 |
+
.venv
|
103 |
+
pip-selfcheck.json
|
104 |
+
|
105 |
+
### JetBrains template
|
106 |
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
107 |
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
108 |
+
|
109 |
+
# User-specific stuff
|
110 |
+
.idea/**/workspace.xml
|
111 |
+
.idea/**/tasks.xml
|
112 |
+
.idea/**/usage.statistics.xml
|
113 |
+
.idea/**/dictionaries
|
114 |
+
.idea/**/shelf
|
115 |
+
|
116 |
+
# AWS User-specific
|
117 |
+
.idea/**/aws.xml
|
118 |
+
|
119 |
+
# Generated files
|
120 |
+
.idea/**/contentModel.xml
|
121 |
+
|
122 |
+
# Sensitive or high-churn files
|
123 |
+
.idea/**/dataSources/
|
124 |
+
.idea/**/dataSources.ids
|
125 |
+
.idea/**/dataSources.local.xml
|
126 |
+
.idea/**/sqlDataSources.xml
|
127 |
+
.idea/**/dynamic.xml
|
128 |
+
.idea/**/uiDesigner.xml
|
129 |
+
.idea/**/dbnavigator.xml
|
130 |
+
|
131 |
+
# Gradle
|
132 |
+
.idea/**/gradle.xml
|
133 |
+
.idea/**/libraries
|
134 |
+
|
135 |
+
# Gradle and Maven with auto-import
|
136 |
+
# When using Gradle or Maven with auto-import, you should exclude module files,
|
137 |
+
# since they will be recreated, and may cause churn. Uncomment if using
|
138 |
+
# auto-import.
|
139 |
+
# .idea/artifacts
|
140 |
+
# .idea/compiler.xml
|
141 |
+
# .idea/jarRepositories.xml
|
142 |
+
# .idea/modules.xml
|
143 |
+
# .idea/*.iml
|
144 |
+
# .idea/modules
|
145 |
+
# *.iml
|
146 |
+
# *.ipr
|
147 |
+
|
148 |
+
# CMake
|
149 |
+
cmake-build-*/
|
150 |
+
|
151 |
+
# Mongo Explorer plugin
|
152 |
+
.idea/**/mongoSettings.xml
|
153 |
+
|
154 |
+
# File-based project format
|
155 |
+
*.iws
|
156 |
+
|
157 |
+
# IntelliJ
|
158 |
+
out/
|
159 |
+
|
160 |
+
# mpeltonen/sbt-idea plugin
|
161 |
+
.idea_modules/
|
162 |
+
|
163 |
+
# JIRA plugin
|
164 |
+
atlassian-ide-plugin.xml
|
165 |
+
|
166 |
+
# Cursive Clojure plugin
|
167 |
+
.idea/replstate.xml
|
168 |
+
|
169 |
+
# SonarLint plugin
|
170 |
+
.idea/sonarlint/
|
171 |
+
|
172 |
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
173 |
+
com_crashlytics_export_strings.xml
|
174 |
+
crashlytics.properties
|
175 |
+
crashlytics-build.properties
|
176 |
+
fabric.properties
|
177 |
+
|
178 |
+
# Editor-based Rest Client
|
179 |
+
.idea/httpRequests
|
180 |
+
|
181 |
+
# Android studio 3.1+ serialized cache file
|
182 |
+
.idea/caches/build_file_checksums.ser
|
183 |
+
|
184 |
+
# idea folder, uncomment if you don't need it
|
185 |
+
# .idea
|
.idea/.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
.idea/.name
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
2D_Data_Generator_Model.py
|
.idea/2D_Data_Generator.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/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.10 (Transformer_Testing)" 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/2D_Data_Generator.iml" filepath="$PROJECT_DIR$/.idea/2D_Data_Generator.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
.idea/vcs.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="VcsDirectoryMappings">
|
4 |
+
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
5 |
+
</component>
|
6 |
+
</project>
|
2D_Data_Generator_Model.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import pandas as pd
|
5 |
+
from datasets import load_dataset, ClassLabel, Sequence
|
6 |
+
import json
|
7 |
+
import numpy
|
8 |
+
from transformers import AutoImageProcessor
|
9 |
+
from torchvision.transforms import RandomResizedCrop, Compose, Normalize, ToTensor
|
10 |
+
from transformers import DefaultDataCollator
|
11 |
+
# import evaluate
|
12 |
+
import numpy as np
|
13 |
+
from transformers import AutoModelForImageClassification, TrainingArguments, Trainer
|
14 |
+
from PIL import Image
|
15 |
+
from matplotlib import cm
|
16 |
+
from Data_Generation.Shape_Generation_Functions import basic_box, diagonal_box_split, horizontal_vertical_box_split, \
|
17 |
+
back_slash_box, forward_slash_box, back_slash_plus_box, forward_slash_plus_box, hot_dog_box, hamburger_box, \
|
18 |
+
x_hamburger_box, x_hot_dog_box, x_plus_box
|
19 |
+
|
20 |
+
from Data_Generation.Dataset_Generation_Functions import make_boxes
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
# food = load_dataset("cmudrc/2d-lattices", split="train[:15]") # Loads the training data samples
|
25 |
+
food = load_dataset("cmudrc/2d-lattices", split="train+test") # Loads all of the data, for use after training
|
26 |
+
|
27 |
+
# checks to see if the dataset has been assigned a class label
|
28 |
+
# if type(food.features["label"]) != 'datasets.features.features.ClassLabel': # Cast to ClassLabel
|
29 |
+
# food = food.class_encode_column('label')
|
30 |
+
print(food)
|
31 |
+
desired_label = 'x_hot_dog_box'
|
32 |
+
desired_thickness = 1
|
33 |
+
desired_density = 1
|
34 |
+
|
35 |
+
data_frame = pd.DataFrame(food)
|
36 |
+
# print(data_frame)
|
37 |
+
|
38 |
+
shape_rows = data_frame['Shape'] == desired_label
|
39 |
+
# print(shape_rows)
|
40 |
+
|
41 |
+
thickness_rows = data_frame['Thickness'] == desired_thickness
|
42 |
+
# print(thickness_rows)
|
43 |
+
|
44 |
+
density_rows = data_frame['Density'] == desired_density
|
45 |
+
# print(density_rows)
|
46 |
+
|
47 |
+
desired_output = data_frame.loc[shape_rows & thickness_rows & density_rows].iloc[0]['Array']
|
48 |
+
print(desired_output)
|
49 |
+
print(type(desired_output))
|
50 |
+
|
51 |
+
|
52 |
+
example_point = numpy.array(json.loads(desired_output))
|
53 |
+
|
54 |
+
plt.imshow(example_point)
|
55 |
+
plt.show()
|
56 |
+
|
57 |
+
|
58 |
+
all_shapes = [basic_box, diagonal_box_split, horizontal_vertical_box_split, back_slash_box, forward_slash_box,
|
59 |
+
back_slash_plus_box, forward_slash_plus_box, hot_dog_box, hamburger_box, x_hamburger_box,
|
60 |
+
x_hot_dog_box, x_plus_box]
|
61 |
+
|
62 |
+
base_shapes = [basic_box, back_slash_box, forward_slash_box, hot_dog_box, hamburger_box]
|
63 |
+
image_size = 11
|
64 |
+
density = [1]
|
65 |
+
|
66 |
+
boxes = make_boxes(image_size, density, all_shapes)
|
67 |
+
|
68 |
+
|
69 |
+
box_arrays, box_shape, box_density, box_thickness, = list(zip(*boxes))[0], list(zip(*boxes))[1], list(zip(*boxes))[2], list(zip(*boxes))[3]
|
70 |
+
|
71 |
+
# indices_1 = [i for i in range(len(boxes)) if boxes[1][i] == str(base_shapes[0]) and boxes[2][i] == density[0] and boxes[3][i] == desired_thickness]
|
72 |
+
indices_1 = [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]
|
73 |
+
print(indices_1)
|
74 |
+
# indices_1 = random.randint(0, len(box_arrays))
|
75 |
+
|
76 |
+
|
77 |
+
# plt.imshow(box_arrays[indices_1])
|
78 |
+
plt.imshow(box_arrays[indices_1[0]])
|
79 |
+
plt.show()
|
80 |
+
|
81 |
+
|
82 |
+
'''trainer.push_to_hub()''' # Need to figure out how to push the model to the hub
|
Data_Generation/Dataset_Generation_Functions.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
|
3 |
+
|
4 |
+
########################################################################################################################
|
5 |
+
# Make the data using all the code in Shape_Generation_Functions.py
|
6 |
+
def make_boxes(image_size, densities, shapes):
|
7 |
+
"""
|
8 |
+
:param image_size: [int] - the pixel height and width of the generated arrays
|
9 |
+
:param densities: [list] - of the values of each of the active pixels in each shape
|
10 |
+
:param shapes: [list] - of the various shapes desired for the dataset
|
11 |
+
:return: [list[tuple]] - [Array, Density, Thickness, Shape]
|
12 |
+
"""
|
13 |
+
|
14 |
+
matrix = []
|
15 |
+
|
16 |
+
for function in shapes: # Adds different types of shapes
|
17 |
+
|
18 |
+
# Adds different density values
|
19 |
+
for i in range(len(densities)):
|
20 |
+
# Loops through the possible thickness values
|
21 |
+
for j in range(image_size): # Adds additional Pixels
|
22 |
+
thickness = j
|
23 |
+
Array = (function(thickness, densities[i], image_size))
|
24 |
+
|
25 |
+
# Checks if there are any 0's left in the array to append
|
26 |
+
if (np.where((Array == float(0)))[0] > 0).any():
|
27 |
+
the_tuple = (Array, str(function.__name__), densities[i], thickness)
|
28 |
+
matrix.append(the_tuple)
|
29 |
+
|
30 |
+
# Prevents solids shapes from being appended to the array
|
31 |
+
else:
|
32 |
+
break
|
33 |
+
return matrix
|
34 |
+
|
35 |
+
|
36 |
+
########################################################################################################################
|
37 |
+
|
38 |
+
|
Data_Generation/Piecewise_Box_Functions.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import math
|
3 |
+
|
4 |
+
|
5 |
+
def basic_box_array(image_size):
|
6 |
+
A = np.ones((int(image_size), int(image_size))) # Initializes A matrix with 0 values
|
7 |
+
# Creates the outside edges of the box
|
8 |
+
# for i in range(image_size):
|
9 |
+
# for j in range(image_size):
|
10 |
+
# if i == 0 or j == 0 or i == image_size - 1 or j == image_size - 1:
|
11 |
+
# A[i][j] = 1
|
12 |
+
# A[1:-1, 1:-1] = 1
|
13 |
+
# np.pad(A[1:-1,1:-1], pad_width=((1, 1), (1, 1)), mode='constant', constant_values=1)
|
14 |
+
A[1:-1, 1:-1] = 0
|
15 |
+
return A
|
16 |
+
|
17 |
+
|
18 |
+
def back_slash_array(image_size):
|
19 |
+
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
|
20 |
+
# for i in range(image_size):
|
21 |
+
# for j in range(image_size):
|
22 |
+
# if i == j:
|
23 |
+
# A[i][j] = 1
|
24 |
+
np.fill_diagonal(A, 1)
|
25 |
+
|
26 |
+
return A
|
27 |
+
|
28 |
+
|
29 |
+
def forward_slash_array(image_size):
|
30 |
+
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
|
31 |
+
# for i in range(image_size):
|
32 |
+
# for j in range(image_size):
|
33 |
+
# if i == (image_size-1)-j:
|
34 |
+
# A[i][j] = 1
|
35 |
+
np.fill_diagonal(np.fliplr(A), 1)
|
36 |
+
return A
|
37 |
+
|
38 |
+
|
39 |
+
def hot_dog_array(image_size):
|
40 |
+
# Places pixels down the vertical axis to split the box
|
41 |
+
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
|
42 |
+
# for i in range(image_size):
|
43 |
+
# for j in range(image_size):
|
44 |
+
# if j == math.floor((image_size - 1) / 2) or j == math.ceil((image_size - 1) / 2):
|
45 |
+
# A[i][j] = 1
|
46 |
+
|
47 |
+
A[:, np.floor((image_size - 1) / 2).astype(int)] = 1
|
48 |
+
A[:, np.ceil((image_size - 1) / 2).astype(int)] = 1
|
49 |
+
return A
|
50 |
+
|
51 |
+
|
52 |
+
def hamburger_array(image_size):
|
53 |
+
# Places pixels across the horizontal axis to split the box
|
54 |
+
A = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
|
55 |
+
# for i in range(image_size):
|
56 |
+
# for j in range(image_size):
|
57 |
+
# if i == math.floor((image_size - 1) / 2) or i == math.ceil((image_size - 1) / 2):
|
58 |
+
# A[i][j] = 1
|
59 |
+
A[np.floor((image_size - 1) / 2).astype(int), :] = 1
|
60 |
+
A[np.ceil((image_size - 1) / 2).astype(int), :] = 1
|
61 |
+
return A
|
62 |
+
|
63 |
+
|
64 |
+
# def update_array(array_original, array_new, image_size):
|
65 |
+
# A = array_original
|
66 |
+
# for i in range(image_size):
|
67 |
+
# for j in range(image_size):
|
68 |
+
# if array_new[i][j] == 1:
|
69 |
+
# A[i][j] = 1
|
70 |
+
# return A
|
71 |
+
def update_array(array_original, array_new, image_size):
|
72 |
+
A = array_original
|
73 |
+
A[array_new == 1] = 1
|
74 |
+
return A
|
75 |
+
|
76 |
+
|
77 |
+
def add_pixels(array_original, additional_pixels, image_size):
|
78 |
+
# Adds pixels to the thickness of each component of the box
|
79 |
+
A = array_original
|
80 |
+
A_updated = np.zeros((int(image_size), int(image_size))) # Initializes A matrix with 0 values
|
81 |
+
for dens in range(additional_pixels):
|
82 |
+
for i in range(1, image_size - 1):
|
83 |
+
for j in range(1, image_size - 1):
|
84 |
+
if A[i - 1][j] + A[i + 1][j] + A[i][j - 1] + A[i][j + 1] > 0:
|
85 |
+
A_updated[i][j] = 1
|
86 |
+
A = update_array(A, A_updated,image_size)
|
87 |
+
return A
|
88 |
+
|
Data_Generation/Shape_Generation_Functions.py
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from Data_Generation.Piecewise_Box_Functions import back_slash_array, basic_box_array, forward_slash_array, \
|
2 |
+
hot_dog_array, hamburger_array, update_array, add_pixels
|
3 |
+
|
4 |
+
|
5 |
+
########################################################################################################################
|
6 |
+
# Series of Basic Box Shapes
|
7 |
+
|
8 |
+
def basic_box(additional_pixels, density, image_size):
|
9 |
+
A = basic_box_array(image_size) # Creates the outside edges of the box
|
10 |
+
# Increase the thickness of each part of the box
|
11 |
+
A = add_pixels(A, additional_pixels, image_size)
|
12 |
+
return A*density
|
13 |
+
|
14 |
+
|
15 |
+
def horizontal_vertical_box_split(additional_pixels, density, image_size):
|
16 |
+
A = basic_box_array(image_size) # Creates the outside edges of the box
|
17 |
+
# Place pixels across the horizontal and vertical axes to split the box
|
18 |
+
A = update_array(A, hot_dog_array(image_size), image_size)
|
19 |
+
A = update_array(A, hamburger_array(image_size), image_size)
|
20 |
+
# Increase the thickness of each part of the box
|
21 |
+
A = add_pixels(A, additional_pixels, image_size)
|
22 |
+
return A*density
|
23 |
+
|
24 |
+
|
25 |
+
def diagonal_box_split(additional_pixels, density, image_size):
|
26 |
+
A = basic_box_array(image_size) # Creates the outside edges of the box
|
27 |
+
|
28 |
+
# Add pixels along the diagonals of the box
|
29 |
+
A = update_array(A, back_slash_array(image_size), image_size)
|
30 |
+
A = update_array(A, forward_slash_array(image_size), image_size)
|
31 |
+
|
32 |
+
# Adds pixels to the thickness of each component of the box
|
33 |
+
# Increase the thickness of each part of the box
|
34 |
+
A = add_pixels(A, additional_pixels, image_size)
|
35 |
+
return A*density
|
36 |
+
|
37 |
+
|
38 |
+
def back_slash_box(additional_pixels, density, image_size):
|
39 |
+
A = basic_box_array(image_size) # Initializes A matrix with 0 values
|
40 |
+
A = update_array(A, back_slash_array(image_size), image_size)
|
41 |
+
A = add_pixels(A, additional_pixels, image_size)
|
42 |
+
return A * density
|
43 |
+
|
44 |
+
|
45 |
+
def forward_slash_box(additional_pixels, density, image_size):
|
46 |
+
A = basic_box_array(image_size) # Initializes A matrix with 0 values
|
47 |
+
A = update_array(A, forward_slash_array(image_size), image_size)
|
48 |
+
A = add_pixels(A, additional_pixels, image_size)
|
49 |
+
return A * density
|
50 |
+
|
51 |
+
|
52 |
+
def hot_dog_box(additional_pixels, density, image_size):
|
53 |
+
A = basic_box_array(image_size) # Initializes A matrix with 0 values
|
54 |
+
A = update_array(A, hot_dog_array(image_size), image_size)
|
55 |
+
A = add_pixels(A, additional_pixels, image_size)
|
56 |
+
return A * density
|
57 |
+
|
58 |
+
|
59 |
+
def hamburger_box(additional_pixels, density, image_size):
|
60 |
+
A = basic_box_array(image_size) # Initializes A matrix with 0 values
|
61 |
+
A = update_array(A, hamburger_array(image_size), image_size)
|
62 |
+
A = add_pixels(A, additional_pixels, image_size)
|
63 |
+
return A * density
|
64 |
+
|
65 |
+
|
66 |
+
def x_plus_box(additional_pixels, density, image_size):
|
67 |
+
A = basic_box_array(image_size) # Initializes A matrix with 0 values
|
68 |
+
A = update_array(A, hot_dog_array(image_size), image_size)
|
69 |
+
A = update_array(A, hamburger_array(image_size), image_size)
|
70 |
+
A = update_array(A, forward_slash_array(image_size), image_size)
|
71 |
+
A = update_array(A, back_slash_array(image_size), image_size)
|
72 |
+
A = add_pixels(A, additional_pixels, image_size)
|
73 |
+
return A * density
|
74 |
+
|
75 |
+
|
76 |
+
def forward_slash_plus_box(additional_pixels, density, image_size):
|
77 |
+
A = basic_box_array(image_size) # Initializes A matrix with 0 values
|
78 |
+
A = update_array(A, hot_dog_array(image_size), image_size)
|
79 |
+
A = update_array(A, hamburger_array(image_size), image_size)
|
80 |
+
A = update_array(A, forward_slash_array(image_size), image_size)
|
81 |
+
# A = update_array(A, back_slash_array(image_size), image_size)
|
82 |
+
A = add_pixels(A, additional_pixels, image_size)
|
83 |
+
return A * density
|
84 |
+
|
85 |
+
|
86 |
+
def back_slash_plus_box(additional_pixels, density, image_size):
|
87 |
+
A = basic_box_array(image_size) # Initializes A matrix with 0 values
|
88 |
+
A = update_array(A, hot_dog_array(image_size), image_size)
|
89 |
+
A = update_array(A, hamburger_array(image_size), image_size)
|
90 |
+
A = update_array(A, back_slash_array(image_size), image_size)
|
91 |
+
A = add_pixels(A, additional_pixels, image_size)
|
92 |
+
return A * density
|
93 |
+
|
94 |
+
|
95 |
+
def x_hot_dog_box(additional_pixels, density, image_size):
|
96 |
+
A = basic_box_array(image_size) # Initializes A matrix with 0 values
|
97 |
+
A = update_array(A, hot_dog_array(image_size), image_size)
|
98 |
+
A = update_array(A, forward_slash_array(image_size), image_size)
|
99 |
+
A = update_array(A, back_slash_array(image_size), image_size)
|
100 |
+
A = add_pixels(A, additional_pixels, image_size)
|
101 |
+
return A * density
|
102 |
+
|
103 |
+
|
104 |
+
def x_hamburger_box(additional_pixels, density, image_size):
|
105 |
+
A = basic_box_array(image_size) # Initializes A matrix with 0 values
|
106 |
+
A = update_array(A, hamburger_array(image_size), image_size)
|
107 |
+
A = update_array(A, forward_slash_array(image_size), image_size)
|
108 |
+
A = update_array(A, back_slash_array(image_size), image_size)
|
109 |
+
A = add_pixels(A, additional_pixels, image_size)
|
110 |
+
return A * density
|
111 |
+
|
requirements.txt
ADDED
Binary file (40.9 kB). View file
|
|