-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
28 lines (22 loc) · 836 Bytes
/
model.py
File metadata and controls
28 lines (22 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Neural network model definition for Forest Covertype classification
"""
import torch
import torch.nn as nn
class SimpleNN(nn.Module):
"""Simple feedforward neural network for 7-class forest covertype classification"""
def __init__(self, input_dim, num_classes):
super(SimpleNN, self).__init__()
self.fc1 = nn.Linear(input_dim, 64)
self.fc2 = nn.Linear(64, 32)
self.fc3 = nn.Linear(32, num_classes)
self.relu = nn.ReLU()
def forward(self, x):
x = self.relu(self.fc1(x))
x = self.relu(self.fc2(x))
x = self.fc3(x) # No softmax here - will use CrossEntropyLoss
return x
def build_model(input_dim, num_classes):
"""Build a simple feedforward neural network for classification"""
model = SimpleNN(input_dim, num_classes)
return model