Peter2023HuggingFace commited on
Commit
c130983
·
verified ·
1 Parent(s): 87d5d0e

nbrdf mlp model source code

Browse files
Files changed (1) hide show
  1. nbrdf-release.py +59 -0
nbrdf-release.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ NBRDF MLP model
3
+ - input_size 3
4
+ - hidden_size 21
5
+ - hidden_layer 3
6
+ - output_size 3
7
+
8
+ @author
9
+ Copyright (c) 2024-2025 Peter HU.
10
+
11
+ @file
12
+ reference: https://github.com/asztr/Neural-BRDF
13
+
14
+ '''
15
+ # --- built in ---
16
+ import sys
17
+ import path
18
+ # --- 3rd party ---
19
+ import numpy as np
20
+ import torch
21
+ import torch.nn as nn
22
+ import torch.nn.functional as F
23
+ import random
24
+
25
+ # --- related module ---
26
+ device = torch.device(
27
+ "cuda" if torch.cuda.is_available()
28
+ else torch.device("mps") if torch.backends.mps.is_available()
29
+ else "cpu")
30
+
31
+
32
+ class MLP(nn.Module):
33
+ '''Pytorch NBRDF MLP model'''
34
+ def __init__(self, input_size, hidden_size, output_size) -> None:
35
+ super().__init__()
36
+ # Initialize separately
37
+ self.fc1 = nn.Linear(input_size, hidden_size, bias=True)
38
+ self.fc2 = nn.Linear(hidden_size, hidden_size, bias=True)
39
+ self.fc3 = nn.Linear(hidden_size, output_size, bias=True)
40
+ # initialize the weight
41
+
42
+ # Reproducibility for generation purpose
43
+ torch.manual_seed(0)
44
+ random.seed(0)
45
+ with torch.no_grad():
46
+ for func in [self.fc1, self.fc2, self.fc3]:
47
+ func.bias.zero_()
48
+ func.weight.uniform_(0.0, 0.02)
49
+
50
+
51
+ def forward(self, x):
52
+ out = self.fc1(x)
53
+ out = F.leaky_relu(out)
54
+ out = self.fc2(out)
55
+ out = F.leaky_relu(out)
56
+ out = self.fc3(out)
57
+ out = F.relu(torch.exp(out) - 1.0)
58
+
59
+ return out