marta-marta commited on
Commit
9da5a1c
1 Parent(s): abcddc5

Created base app to generate data and images for paper.

Browse files
Files changed (1) hide show
  1. app.py +76 -27
app.py CHANGED
@@ -1,40 +1,89 @@
1
- import random
2
 
3
  import matplotlib.pyplot as plt
4
  import numpy as np
5
- import pandas as pd
6
- from datasets import load_dataset, ClassLabel, Sequence
7
- import json
8
- import numpy
9
-
10
- # from transformers import AutoImageProcessor
11
- # from torchvision.transforms import RandomResizedCrop, Compose, Normalize, ToTensor
12
- # from transformers import DefaultDataCollator
13
- # # import evaluate
14
- # import numpy as np
15
- # from transformers import AutoModelForImageClassification, TrainingArguments, Trainer
16
- # from PIL import Image
17
- # from matplotlib import cm
18
 
19
  import streamlit as st
20
  from Data_Generation.Dataset_Generation_Functions import make_boxes
21
- from Data_Generation.Piecewise_Box_Functions import basic_box_array
22
-
23
- image_size = st.slider('Select a value for the image size')
 
24
  # st.write(x, 'squared is', x * x)
25
 
26
-
27
  density_selection = st.slider('Select a value for the number of equally spaced density values (0, 1]', min_value=1, max_value=10)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
- densities = pd.DataFrame(np.linspace(0,1, num=density_selection+1)[1:])
30
- densities.columns = ["Density Values"]
31
-
32
-
33
- st.write("Here are the density values that would exist in your dataset:")
34
- st.write(densities)
35
-
36
-
37
- example_density = basic_box_array(image_size, 1)
38
 
39
  '''
40
  # Testing
 
1
+
2
 
3
  import matplotlib.pyplot as plt
4
  import numpy as np
5
+
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  import streamlit as st
8
  from Data_Generation.Dataset_Generation_Functions import make_boxes
9
+ from Data_Generation.Piecewise_Box_Functions import basic_box_array, forward_slash_array, combine_arrays, add_thickness
10
+ ########################################################################################################################
11
+ # User Inputs
12
+ image_size = st.slider('Select a value for the image size', min_value=9, max_value=28)
13
  # st.write(x, 'squared is', x * x)
14
 
 
15
  density_selection = st.slider('Select a value for the number of equally spaced density values (0, 1]', min_value=1, max_value=10)
16
+ ########################################################################################################################
17
+ # Compute Example Shapes
18
+
19
+ densities = np.linspace(0, 1, num=density_selection+1)[1:]
20
+
21
+ sample_basic_box = basic_box_array(image_size, 1)
22
+ sample_forward_slash_box = forward_slash_array(image_size, 1)
23
+ sample_combined = combine_arrays([sample_forward_slash_box, sample_basic_box])
24
+ print(sample_combined)
25
+
26
+ sample_density = np.array([sample_combined * density_value for density_value in densities])
27
+
28
+ # copy = sample_combined
29
+ sample_thickness = []
30
+ # test = add_thickness(copy, 2)
31
+ # sample_thickness.append(test)
32
+ # print(sample_thickness)
33
+ for i in [1, 2, 3, 4]:
34
+ copy = sample_combined
35
+ print(i)
36
+ test = add_thickness(copy, i)
37
+ print(test)
38
+ sample_thickness.append(test)
39
+ # print(sample_thickness)
40
+ ########################################################################################################################
41
+ # Output Example Shapes
42
+ st.write("Click 'Generate Samples' to show some density values that would exist in your dataset:")
43
+
44
+
45
+ # Show samples of various density values
46
+
47
+ if st.button('Generate Samples'): # Generate the samples
48
+ plt.figure(1)
49
+ st.header("Sample Density Figures:")
50
+ max_figures = min(density_selection, 5)
51
+ for i in range(max_figures):
52
+ plt.subplot(1, max_figures+1, i+1), plt.imshow(sample_density[i], cmap='gray', vmin=0, vmax=1)
53
+ if i != 0: # Show y-label for only first figure
54
+ plt.tick_params(left=False, labelleft=False)
55
+ plt.title("Density: " + str(round(densities[i], 4)), fontsize=6)
56
+ plt.figure(1)
57
+ # cax = plt.axes([0.85, 0.1, 0.075, 0.8])
58
+ # plt.colorbar(cax=cax, shrink=0.1)
59
+ st.pyplot(plt.figure(1))
60
+
61
+ # Show samples of various thickness values
62
+ st.header("Sample Thickness Figures:")
63
+ plt.figure(2)
64
+ for i in range(len(sample_thickness)):
65
+ plt.subplot(1, 5, i+1), plt.imshow(sample_thickness[i], cmap='gray', vmin=0, vmax=1)
66
+ if i != 0: # Show y-label for only first figure
67
+ plt.tick_params(left=False, labelleft=False)
68
+ plt.title("Thickness: " + str(i+1), fontsize=6)
69
+ plt.figure(2)
70
+ # cax = plt.axes([0.85, 0.1, 0.075, 0.8])
71
+ # plt.colorbar(cax=cax, shrink=0.1)
72
+ st.pyplot(plt.figure(2))
73
+
74
+
75
+
76
+ ########################################################################################################################
77
+ # Output Generated Examples
78
+
79
+ # plt.figure(2)
80
+ # for j in range(5): # shows 5 random images to the users to view samples of the dataset
81
+ # i = np.random.randint(0, len(result))
82
+ # plt.subplot(550 + 1 + j)
83
+ # plt.imshow(result[i], cmap='gray', vmin=0, vmax=1)
84
+ # plt.figure(2)
85
+ # st.pyplot(plt.figure(2))
86
 
 
 
 
 
 
 
 
 
 
87
 
88
  '''
89
  # Testing