eagle0504 commited on
Commit
71d416d
·
1 Parent(s): dffa879

more models added

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -25,8 +25,23 @@ def create_datasets(n_samples=1500):
25
 
26
 
27
  # Function to create a simple one-layer neural network
28
- def create_model(input_shape):
29
- model = Sequential([Dense(1, input_shape=input_shape, activation="sigmoid")])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  return model
31
 
32
 
@@ -106,6 +121,12 @@ def main():
106
  st.sidebar.header('Configuration')
107
  n_samples = st.sidebar.slider('Number of Samples', min_value=500, max_value=3000, value=1500, step=100)
108
  threshold = st.sidebar.slider('Threshold', min_value=0.0, max_value=1.0, value=0.1, step=0.01)
 
 
 
 
 
 
109
  epochs = st.sidebar.slider('Number of Epochs', min_value=10, max_value=100, value=20, step=5)
110
 
111
  # Generate datasets
@@ -154,7 +175,7 @@ def main():
154
  )
155
 
156
  # Train with MSE loss
157
- model_mse = create_model((2,))
158
  model_mse.compile(
159
  optimizer="sgd", loss="binary_crossentropy", metrics=["accuracy"]
160
  )
@@ -175,7 +196,7 @@ def main():
175
  st.pyplot(fig)
176
 
177
  # Train with custom loss
178
- model_custom = create_model((2,))
179
  model_custom.compile(
180
  optimizer="sgd",
181
  loss=soft_loss_wrapper(threshold),
 
25
 
26
 
27
  # Function to create a simple one-layer neural network
28
+ def create_model(input_shape, layers):
29
+ model = Sequential()
30
+ # Add layers based on the selection
31
+ if layers == 'one-layer neural network':
32
+ model.add(Dense(1, input_shape=input_shape, activation="sigmoid"))
33
+ elif layers == 'three-layer neural network':
34
+ model.add(Dense(128, input_shape=input_shape, activation="relu"))
35
+ model.add(Dense(128, activation="relu"))
36
+ model.add(Dense(128, activation="relu"))
37
+ model.add(Dense(1, activation="sigmoid"))
38
+ elif layers == 'five-layer neural network':
39
+ model.add(Dense(128, input_shape=input_shape, activation="relu"))
40
+ model.add(Dense(128, activation="relu"))
41
+ model.add(Dense(128, activation="relu"))
42
+ model.add(Dense(128, activation="relu"))
43
+ model.add(Dense(128, activation="relu"))
44
+ model.add(Dense(1, activation="sigmoid"))
45
  return model
46
 
47
 
 
121
  st.sidebar.header('Configuration')
122
  n_samples = st.sidebar.slider('Number of Samples', min_value=500, max_value=3000, value=1500, step=100)
123
  threshold = st.sidebar.slider('Threshold', min_value=0.0, max_value=1.0, value=0.1, step=0.01)
124
+
125
+ # Sidebar: model selection
126
+ model_option = st.sidebar.selectbox(
127
+ 'Choose the neural network model:',
128
+ ('one-layer neural network', 'three-layer neural network', 'five-layer neural network')
129
+ )
130
  epochs = st.sidebar.slider('Number of Epochs', min_value=10, max_value=100, value=20, step=5)
131
 
132
  # Generate datasets
 
175
  )
176
 
177
  # Train with MSE loss
178
+ model_mse = create_model((2,), model_option)
179
  model_mse.compile(
180
  optimizer="sgd", loss="binary_crossentropy", metrics=["accuracy"]
181
  )
 
196
  st.pyplot(fig)
197
 
198
  # Train with custom loss
199
+ model_custom = create_model((2,), model_option)
200
  model_custom.compile(
201
  optimizer="sgd",
202
  loss=soft_loss_wrapper(threshold),