Skip to content

Commit

Permalink
Fix PlayUIServer.detach() to allow sequential attach-detach of StatsS…
Browse files Browse the repository at this point in the history
…torage (#6950)

* Fix PlayUIServer.detach(), add test for sequentially attaching and detaching StatsStorage

* fix missing ND4J backend for TestPlayUI

* remove unused imports
  • Loading branch information
printomi authored and sshepel committed Jan 8, 2019
1 parent b34bba2 commit fdc5f7e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
Expand Up @@ -299,6 +299,13 @@
<artifactId>logback-classic</artifactId> <!-- Version set by deeplearning4j-parent dependency management -->
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
Expand Up @@ -184,6 +184,10 @@ public void onDetach(StatsStorage statsStorage) {
for (String s : knownSessionIDs.keySet()) {
if (knownSessionIDs.get(s) == statsStorage) {
knownSessionIDs.remove(s);
workerIdxCount.remove(s);
workerIdxToName.remove(s);
currentSessionID = null;
getDefaultSession();
}
}
}
Expand Down
Expand Up @@ -326,6 +326,7 @@ public synchronized void detach(StatsStorage statsStorage) {
Pair<StatsStorage, StatsStorageListener> p = iterator.next();
if (p.getFirst() == statsStorage) { //Same object, not equality
statsStorage.deregisterStatsStorageListener(p.getSecond());
listeners.remove(p);
found = true;
}
}
Expand Down
Expand Up @@ -148,11 +148,11 @@ public void testUIMultipleSessions() throws Exception {
uiServer.attach(ss);

MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
.layer(0, new DenseLayer.Builder().activation(Activation.TANH).nIn(4).nOut(4).build())
.layer(1, new OutputLayer.Builder().lossFunction(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nIn(4).nOut(3).build())
.build();
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).list()
.layer(0, new DenseLayer.Builder().activation(Activation.TANH).nIn(4).nOut(4).build())
.layer(1, new OutputLayer.Builder().lossFunction(LossFunctions.LossFunction.MCXENT)
.activation(Activation.SOFTMAX).nIn(4).nOut(3).build())
.build();

MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
Expand All @@ -167,6 +167,52 @@ public void testUIMultipleSessions() throws Exception {
}


Thread.sleep(1000000);
}

@Test
@Ignore
public void testUISequentialSessions() throws Exception {
UIServer uiServer = UIServer.getInstance();
StatsStorage ss = null;
for (int session = 0; session < 3; session++) {

if (ss != null) {
uiServer.detach(ss);
}
ss = new InMemoryStatsStorage();
uiServer.attach(ss);

int numInputs = 4;
int outputNum = 3;
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.activation(Activation.TANH)
.weightInit(WeightInit.XAVIER)
.updater(new Sgd(0.03))
.l2(1e-4)
.list()
.layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(3)
.build())
.layer(1, new DenseLayer.Builder().nIn(3).nOut(3)
.build())
.layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
.activation(Activation.SOFTMAX)
.nIn(3).nOut(outputNum).build())
.build();

MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
net.setListeners(new StatsListener(ss), new ScoreIterationListener(1));

DataSetIterator iter = new IrisDataSetIterator(150, 150);

for (int i = 0; i < 1000; i++) {
net.fit(iter);
}
Thread.sleep(5000);
}


Thread.sleep(1000000);
}

Expand Down

0 comments on commit fdc5f7e

Please sign in to comment.