Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

my_torch_model.py 898 B

You have to be logged in to leave a comment. Sign In
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
  1. import torch.nn as nn
  2. import torch.nn.functional as F
  3. class Net(nn.Module):
  4. def __init__(self,
  5. conv1_out_channels=20, conv1_kernel=5,
  6. conv2_out_channels=50, conv2_kernel=5,
  7. fc1_in_dim=4*4*50, fc1_out_dim=500,
  8. **kwargs
  9. ):
  10. super(Net, self).__init__()
  11. self.conv1 = nn.Conv2d(1, conv1_out_channels, conv1_kernel, 1)
  12. self.conv2 = nn.Conv2d(conv1_out_channels, conv2_out_channels, conv2_kernel, 1)
  13. self.fc1 = nn.Linear(fc1_in_dim, fc1_out_dim)
  14. self.fc2 = nn.Linear(fc1_out_dim, 10)
  15. self.fc1_in_dim = fc1_in_dim
  16. def forward(self, x):
  17. x = F.relu(self.conv1(x))
  18. x = F.max_pool2d(x, 2, 2)
  19. x = F.relu(self.conv2(x))
  20. x = F.max_pool2d(x, 2, 2)
  21. x = x.view(-1, self.fc1_in_dim)
  22. x = F.relu(self.fc1(x))
  23. x = self.fc2(x)
  24. return F.log_softmax(x, dim=1)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...