-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathcustom_task.ts
More file actions
71 lines (62 loc) · 1.76 KB
/
Copy pathcustom_task.ts
File metadata and controls
71 lines (62 loc) · 1.76 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
66
67
68
69
70
71
import tf from "@tensorflow/tfjs-node";
import type { TaskProvider } from "@epfml/discojs";
import { defaultTasks, models } from "@epfml/discojs";
import { Server as DiscoServer } from "server";
// Define your own task provider (task definition + model)
const customTask: TaskProvider<"tabular", "federated"> = {
getTask() {
return Promise.resolve({
id: "custom-task",
dataType: "tabular",
displayInformation: {
title: "Custom task",
summary: {
preview: "task preview",
overview: "task overview",
},
},
trainingInformation: {
epochs: 5,
roundDuration: 10,
validationSplit: 0,
batchSize: 30,
inputColumns: ["Age"],
outputColumn: "Output",
scheme: "federated",
aggregationStrategy: "mean",
minNbOfParticipants: 2,
tensorBackend: "tfjs",
privacy: undefined,
},
});
},
getModel() {
const model = tf.sequential();
model.add(
tf.layers.dense({
inputShape: [1],
units: 124,
activation: "relu",
kernelInitializer: "leCunNormal",
}),
);
model.add(tf.layers.dense({ units: 32, activation: "relu" }));
model.add(tf.layers.dense({ units: 1, activation: "sigmoid" }));
model.compile({
optimizer: "rmsprop",
loss: "binaryCrossentropy",
metrics: ["accuracy"],
});
return Promise.resolve(new models.TFJS("tabular", model));
},
};
async function runServer(): Promise<void> {
// Create a server
const server = await DiscoServer.with(
defaultTasks.titanic, // with some tasks provided by Disco
customTask, // or your own custom task
);
// Start the server
await server.serve(8080);
}
runServer().catch(console.error);