-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPureDnn.sol
116 lines (100 loc) · 2.93 KB
/
PureDnn.sol
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
pragma solidity >=0.4.21 <0.7.0;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: MIT
contract PureDnn {
struct Model {
// the model params hash stored in IPFS
string model_hash;
// the testset hash stored in IPFS
string testset_hash;
// current accuracy
string accuracy;
// used to build up the distributed training network
string[] nodes;
// to determine if it is added
bool isAdded;
}
struct ModelInfo {
// the model params hash stored in IPFS
string model_hash;
// the testset hash stored in IPFS
string testset_hash;
// current accuracy
string accuracy;
}
// indice according to the model name
mapping(string => Model) public models;
// maximum 10 nodes
uint256 max_node_num = 10;
function addNewModel(
string memory modelName,
string memory model_hash,
string memory testset_hash,
string memory accuracy
) public {
// if the model doesnt exist
if (models[modelName].isAdded == false) {
string[] memory initNodes;
models[modelName] = Model({
model_hash: model_hash,
testset_hash: testset_hash,
accuracy: accuracy,
nodes: initNodes,
isAdded: true
});
}
}
function addNode(string memory modelName, string memory node) public {
if (models[modelName].nodes.length < max_node_num) {
models[modelName].nodes.push(node);
}
}
// only return the model_hash, testset_hash and accuracy
function getModelInfo(string memory modelName)
public
view
returns (ModelInfo memory)
{
Model memory queryModel = models[modelName];
return
ModelInfo({
model_hash: queryModel.model_hash,
testset_hash: queryModel.testset_hash,
accuracy: queryModel.accuracy
});
}
function getModelHash(string memory modelName)
public
view
returns (string memory)
{
return models[modelName].model_hash;
}
function getTestsetHash(string memory modelName)
public
view
returns (string memory)
{
return models[modelName].testset_hash;
}
function getNodes(string memory modelName)
public
view
returns (string[] memory)
{
return models[modelName].nodes;
}
function clearNodes(string memory modelName) public {
delete models[modelName].nodes;
}
function updateModel(string memory modelName, string memory model_hash)
public
{
models[modelName].model_hash = model_hash;
}
function updateTestset(string memory modelName, string memory testset_hash)
public
{
models[modelName].testset_hash = testset_hash;
}
}