-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsiren.cpp
More file actions
65 lines (56 loc) · 1.56 KB
/
siren.cpp
File metadata and controls
65 lines (56 loc) · 1.56 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "siren.h"
#include <cassert>
namespace nn
{
Siren::Siren(Type type, int hidden_layers, int layer_size)
{
assert(hidden_layers > 0);
assert(layer_size > 3);
unsigned input_dim = 3;
switch (type)
{
case Type::Image:
input_dim = 2;
break;
case Type::SDF:
input_dim = 3;
break;
case Type::Gen_SDF_32124:
input_dim = 3+3+1+3+3;
break;
case Type::Chair:
input_dim = 3+6;
break;
}
point.resize(input_dim);
distance.resize(1);
add_layer(std::make_shared<DenseLayer>(input_dim, layer_size), Initializer::Siren);
for (int i=0;i<hidden_layers-1;i++)
{
add_layer(std::make_shared<SinLayer>());
add_layer(std::make_shared<DenseLayer>(layer_size, layer_size), Initializer::Siren);
}
add_layer(std::make_shared<SinLayer>());
add_layer(std::make_shared<DenseLayer>(layer_size, 1), Initializer::Siren);
}
void Siren::train(const std::vector<float> &inputs /*[input_size, count]*/, const std::vector<float> &outputs /*[output_size, count]*/,
int batch_size, int iterations, bool verbose)
{
NeuralNetwork::train(inputs, outputs, batch_size, iterations, OptimizerAdam(0.00002f), Loss::MSE, verbose);
}
float Siren::get(float x, float y)
{
point[0] = x;
point[1] = y;
evaluate(point, distance);
return distance[0];
}
float Siren::get(float x, float y, float z)
{
point[0] = x;
point[1] = y;
point[2] = z;
evaluate(point, distance);
return distance[0];
}
}