-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmodel.hh
54 lines (46 loc) · 833 Bytes
/
model.hh
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
#pragma once
#include "layers.hh"
#include <sstream>
struct ModelState
{
std::vector<LayerBase*> d_members;
void save(std::ostream& out) const
{
for(const auto& mem : d_members)
mem->save(out);
}
void save(std::string& out) const
{
std::ostringstream os;
for(const auto& mem : d_members)
mem->save(os);
out=os.str();
}
void load(std::istream& in)
{
for(auto& mem : d_members)
mem->load(in);
}
void load(std::string& in)
{
std::istringstream is(in);
load(is);
}
void learn(float lr)
{
for(auto& mem : d_members)
mem->learn(lr);
}
void zeroGrad()
{
for(auto& mem : d_members)
mem->zeroGrad();
}
uint32_t size()
{
size_t ret = 0;
for(auto& mem : d_members)
ret += mem->size();
return ret;
}
};