-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExportNeuralNets.java
47 lines (37 loc) · 1.48 KB
/
ExportNeuralNets.java
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
package code.NN;
import code.Lets_Go_Champ.DQN;
import java.io.*;
/**
* @author Alexandre Martens
*/
public class ExportNeuralNets {
/**
* Saves the network to a local file
* @param policy_network DQN policy_network object
* @param target_network DQN target_network object
*/
public static void exportNetworks(DQN policy_network, DQN target_network){
try {
// Create the files
FileOutputStream file_policy_network = new FileOutputStream(new File("policy_network"));
FileOutputStream file_target_network = new FileOutputStream(new File("target_network"));
// Create a stream
ObjectOutputStream out_policy_network = new ObjectOutputStream(file_policy_network);
ObjectOutputStream out_target_network = new ObjectOutputStream(file_target_network);
// Write networks to file
out_policy_network.writeObject(policy_network);
out_target_network.writeObject(target_network);
// Close the steam
out_policy_network.close();
out_target_network.close();
// Close the file
file_policy_network.close();
file_target_network.close();
} catch (FileNotFoundException e) {
System.out.println("File not found");
} catch (IOException e) {
System.out.println("Error initializing stream");
}
System.out.println(" ===> All networks exported");
}
}