-
Notifications
You must be signed in to change notification settings - Fork 4
/
ValohaiMetadataCreator.java
50 lines (42 loc) · 1.55 KB
/
ValohaiMetadataCreator.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
48
49
50
package org.deeplearning4j.feedforward.mnist;
import org.deeplearning4j.nn.api.Model;
import org.deeplearning4j.optimize.api.BaseTrainingListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Serializable;
/**
* Score iteration listener. Reports the score (value of the loss function )of the network during training every
* N iterations
*
* @author Adam Gibson
*/
public class ValohaiMetadataCreator extends BaseTrainingListener implements Serializable {
private int printIterations = 10;
private static Logger log = LoggerFactory.getLogger(ValohaiMetadataCreator.class);
/**
* @param printIterations frequency with which to print scores (i.e., every printIterations parameter updates)
*/
public ValohaiMetadataCreator(int printIterations) {
this.printIterations = printIterations;
}
/** Default constructor printing every 10 iterations */
public ValohaiMetadataCreator() {}
@Override
public void iterationDone(Model model, int iteration, int epoch) {
if (printIterations <= 0)
printIterations = 1;
if (iteration % printIterations == 0) {
double score = model.score();
System.out.println(String.format(
"{\"epoch\": %d, \"iteration\": %d, \"score (loss function)\": %f}",
epoch,
iteration,
score)
);
}
}
@Override
public String toString(){
return String.format("ScoreIterationListener(%d)", printIterations);
}
}