Spaces:
Running
Running
Update pages/13_FFNN.py
Browse files- pages/13_FFNN.py +2 -4
pages/13_FFNN.py
CHANGED
|
@@ -26,7 +26,7 @@ class FeedforwardNeuralNetwork(nn.Module):
|
|
| 26 |
return x
|
| 27 |
|
| 28 |
# Function to load the data
|
| 29 |
-
@st.
|
| 30 |
def load_data():
|
| 31 |
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (0.5,))])
|
| 32 |
trainset = torchvision.datasets.MNIST(root='./data', train=True, download=True, transform=transform)
|
|
@@ -68,17 +68,15 @@ trainloader, testloader = load_data()
|
|
| 68 |
|
| 69 |
# Streamlit sidebar for input parameters
|
| 70 |
st.sidebar.header('Model Hyperparameters')
|
| 71 |
-
input_size = st.sidebar.slider('Input Size', 784, 784, 784)
|
| 72 |
hidden1_size = st.sidebar.slider('Hidden Layer 1 Size', 128, 1024, 512)
|
| 73 |
hidden2_size = st.sidebar.slider('Hidden Layer 2 Size', 128, 1024, 256)
|
| 74 |
hidden3_size = st.sidebar.slider('Hidden Layer 3 Size', 128, 1024, 128)
|
| 75 |
-
output_size = st.sidebar.slider('Output Size', 10, 10, 10)
|
| 76 |
learning_rate = st.sidebar.slider('Learning Rate', 0.001, 0.1, 0.01, step=0.001)
|
| 77 |
momentum = st.sidebar.slider('Momentum', 0.0, 1.0, 0.9, step=0.1)
|
| 78 |
epochs = st.sidebar.slider('Epochs', 1, 20, 5)
|
| 79 |
|
| 80 |
# Create the network
|
| 81 |
-
net = FeedforwardNeuralNetwork(
|
| 82 |
criterion = nn.CrossEntropyLoss()
|
| 83 |
optimizer = optim.SGD(net.parameters(), lr=learning_rate, momentum=momentum)
|
| 84 |
|
|
|
|
| 26 |
return x
|
| 27 |
|
| 28 |
# Function to load the data
|
| 29 |
+
@st.cache_data
|
| 30 |
def load_data():
|
| 31 |
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (0.5,))])
|
| 32 |
trainset = torchvision.datasets.MNIST(root='./data', train=True, download=True, transform=transform)
|
|
|
|
| 68 |
|
| 69 |
# Streamlit sidebar for input parameters
|
| 70 |
st.sidebar.header('Model Hyperparameters')
|
|
|
|
| 71 |
hidden1_size = st.sidebar.slider('Hidden Layer 1 Size', 128, 1024, 512)
|
| 72 |
hidden2_size = st.sidebar.slider('Hidden Layer 2 Size', 128, 1024, 256)
|
| 73 |
hidden3_size = st.sidebar.slider('Hidden Layer 3 Size', 128, 1024, 128)
|
|
|
|
| 74 |
learning_rate = st.sidebar.slider('Learning Rate', 0.001, 0.1, 0.01, step=0.001)
|
| 75 |
momentum = st.sidebar.slider('Momentum', 0.0, 1.0, 0.9, step=0.1)
|
| 76 |
epochs = st.sidebar.slider('Epochs', 1, 20, 5)
|
| 77 |
|
| 78 |
# Create the network
|
| 79 |
+
net = FeedforwardNeuralNetwork(784, hidden1_size, hidden2_size, hidden3_size, 10)
|
| 80 |
criterion = nn.CrossEntropyLoss()
|
| 81 |
optimizer = optim.SGD(net.parameters(), lr=learning_rate, momentum=momentum)
|
| 82 |
|