-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize.py
38 lines (30 loc) · 1.06 KB
/
visualize.py
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
29
30
31
32
33
34
35
36
37
38
import torch
from torch import nn
from torchviz import make_dot
class DNN(nn.Module):
def __init__(self, input_features, num_classes, hidden_layers, hidden_nodes):
super(DNN, self).__init__()
self.layers = nn.ModuleList()
# input layer
self.layers.append(nn.Linear(input_features, hidden_nodes))
self.layers.append(nn.ReLU())
# hidden layers
for _ in range(hidden_layers - 1):
self.layers.append(nn.Linear(hidden_nodes, hidden_nodes))
self.layers.append(nn.ReLU())
# output layer
self.layers.append(nn.Linear(hidden_nodes, num_classes))
def forward(self, x):
for layer in self.layers:
x = layer(x)
return x
# Create an instance of DNN model
input_features = 78
num_classes = 15
hidden_layers = 2
hidden_nodes = 90
model = DNN(input_features, num_classes, hidden_layers, hidden_nodes)
# Visualize the model architecture
x = torch.randn(1, input_features)
visual_graph = make_dot(model(x), params=dict(model.named_parameters()))
visual_graph.view()