Search in sources :

Example 11 with StatsStorage

use of org.deeplearning4j.api.storage.StatsStorage in project deeplearning4j by deeplearning4j.

the class TrainModule method getDefaultSession.

private void getDefaultSession() {
    if (currentSessionID != null)
        return;
    long mostRecentTime = Long.MIN_VALUE;
    String sessionID = null;
    for (Map.Entry<String, StatsStorage> entry : knownSessionIDs.entrySet()) {
        List<Persistable> staticInfos = entry.getValue().getAllStaticInfos(entry.getKey(), StatsListener.TYPE_ID);
        if (staticInfos == null || staticInfos.size() == 0)
            continue;
        Persistable p = staticInfos.get(0);
        long thisTime = p.getTimeStamp();
        if (thisTime > mostRecentTime) {
            mostRecentTime = thisTime;
            sessionID = entry.getKey();
        }
    }
    if (sessionID != null) {
        currentSessionID = sessionID;
    }
}
Also used : StatsStorage(org.deeplearning4j.api.storage.StatsStorage) Persistable(org.deeplearning4j.api.storage.Persistable)

Example 12 with StatsStorage

use of org.deeplearning4j.api.storage.StatsStorage in project deeplearning4j by deeplearning4j.

the class TrainModule method getSystemData.

public Result getSystemData() {
    Long lastUpdate = lastUpdateForSession.get(currentSessionID);
    if (lastUpdate == null)
        lastUpdate = -1L;
    I18N i18n = I18NProvider.getInstance();
    //First: get the MOST RECENT update...
    //Then get all updates from most recent - 5 minutes -> TODO make this configurable...
    boolean noData = currentSessionID == null;
    StatsStorage ss = (noData ? null : knownSessionIDs.get(currentSessionID));
    List<Persistable> allStatic = (noData ? Collections.EMPTY_LIST : ss.getAllStaticInfos(currentSessionID, StatsListener.TYPE_ID));
    List<Persistable> latestUpdates = (noData ? Collections.EMPTY_LIST : ss.getLatestUpdateAllWorkers(currentSessionID, StatsListener.TYPE_ID));
    long lastUpdateTime = -1;
    if (latestUpdates == null || latestUpdates.size() == 0) {
        noData = true;
    } else {
        for (Persistable p : latestUpdates) {
            lastUpdateTime = Math.max(lastUpdateTime, p.getTimeStamp());
        }
    }
    //TODO Make configurable
    long fromTime = lastUpdateTime - 5 * 60 * 1000;
    List<Persistable> lastNMinutes = (noData ? null : ss.getAllUpdatesAfter(currentSessionID, StatsListener.TYPE_ID, fromTime));
    Map<String, Object> mem = getMemory(allStatic, lastNMinutes, i18n);
    Pair<Map<String, Object>, Map<String, Object>> hwSwInfo = getHardwareSoftwareInfo(allStatic, i18n);
    Map<String, Object> ret = new HashMap<>();
    ret.put("updateTimestamp", lastUpdate);
    ret.put("memory", mem);
    ret.put("hardware", hwSwInfo.getFirst());
    ret.put("software", hwSwInfo.getSecond());
    return ok(Json.toJson(ret));
}
Also used : StatsStorage(org.deeplearning4j.api.storage.StatsStorage) Persistable(org.deeplearning4j.api.storage.Persistable)

Example 13 with StatsStorage

use of org.deeplearning4j.api.storage.StatsStorage in project deeplearning4j by deeplearning4j.

the class TrainModule method getWorkerIdForIndex.

private synchronized String getWorkerIdForIndex(int workerIdx) {
    String sid = currentSessionID;
    if (sid == null)
        return null;
    Map<Integer, String> idxToId = workerIdxToName.get(sid);
    if (idxToId == null) {
        idxToId = Collections.synchronizedMap(new HashMap<>());
        workerIdxToName.put(sid, idxToId);
    }
    if (idxToId.containsKey(workerIdx)) {
        return idxToId.get(workerIdx);
    }
    //Need to record new worker...
    //Get counter
    AtomicInteger counter = workerIdxCount.get(sid);
    if (counter == null) {
        counter = new AtomicInteger(0);
        workerIdxCount.put(sid, counter);
    }
    //Get all worker IDs
    StatsStorage ss = knownSessionIDs.get(sid);
    List<String> allWorkerIds = new ArrayList<>(ss.listWorkerIDsForSessionAndType(sid, StatsListener.TYPE_ID));
    Collections.sort(allWorkerIds);
    //Ensure all workers have been assigned an index
    for (String s : allWorkerIds) {
        if (idxToId.containsValue(s))
            continue;
        //Unknown worker ID:
        idxToId.put(counter.getAndIncrement(), s);
    }
    //May still return null if index is wrong/too high...
    return idxToId.get(workerIdx);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StatsStorage(org.deeplearning4j.api.storage.StatsStorage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 14 with StatsStorage

use of org.deeplearning4j.api.storage.StatsStorage in project deeplearning4j by deeplearning4j.

the class TrainModule method getModelData.

private Result getModelData(String str) {
    Long lastUpdateTime = lastUpdateForSession.get(currentSessionID);
    if (lastUpdateTime == null)
        lastUpdateTime = -1L;
    //TODO validation
    int layerIdx = Integer.parseInt(str);
    I18N i18N = I18NProvider.getInstance();
    //Model info for layer
    boolean noData = currentSessionID == null;
    //First pass (optimize later): query all data...
    StatsStorage ss = (noData ? null : knownSessionIDs.get(currentSessionID));
    String wid = getWorkerIdForIndex(currentWorkerIdx);
    if (wid == null) {
        noData = true;
    }
    Map<String, Object> result = new HashMap<>();
    result.put("updateTimestamp", lastUpdateTime);
    Triple<MultiLayerConfiguration, ComputationGraphConfiguration, NeuralNetConfiguration> conf = getConfig();
    if (conf == null) {
        return ok(Json.toJson(result));
    }
    TrainModuleUtils.GraphInfo gi = getGraphInfo();
    if (gi == null) {
        return ok(Json.toJson(result));
    }
    // Get static layer info
    String[][] layerInfoTable = getLayerInfoTable(layerIdx, gi, i18N, noData, ss, wid);
    result.put("layerInfo", layerInfoTable);
    //First: get all data, and subsample it if necessary, to avoid returning too many points...
    List<Persistable> updates = (noData ? null : ss.getAllUpdatesAfter(currentSessionID, StatsListener.TYPE_ID, wid, 0));
    List<Integer> iterationCounts = null;
    boolean needToHandleLegacyIterCounts = false;
    if (updates != null && updates.size() > maxChartPoints) {
        int subsamplingFrequency = updates.size() / maxChartPoints;
        List<Persistable> subsampled = new ArrayList<>();
        iterationCounts = new ArrayList<>();
        int pCount = -1;
        int lastUpdateIdx = updates.size() - 1;
        int lastIterCount = -1;
        for (Persistable p : updates) {
            if (!(p instanceof StatsReport))
                continue;
            ;
            StatsReport sr = (StatsReport) p;
            pCount++;
            int iterCount = sr.getIterationCount();
            if (iterCount <= lastIterCount) {
                needToHandleLegacyIterCounts = true;
            }
            lastIterCount = iterCount;
            if (pCount > 0 && subsamplingFrequency > 1 && pCount % subsamplingFrequency != 0) {
                //Skip this to subsample the data
                if (pCount != lastUpdateIdx)
                    //Always keep the most recent value
                    continue;
            }
            subsampled.add(p);
            iterationCounts.add(iterCount);
        }
        updates = subsampled;
    } else if (updates != null) {
        int offset = 0;
        iterationCounts = new ArrayList<>(updates.size());
        int lastIterCount = -1;
        for (Persistable p : updates) {
            if (!(p instanceof StatsReport))
                continue;
            ;
            StatsReport sr = (StatsReport) p;
            int iterCount = sr.getIterationCount();
            if (iterCount <= lastIterCount) {
                needToHandleLegacyIterCounts = true;
            }
            iterationCounts.add(iterCount);
        }
    }
    //Now, it should use the proper iteration counts
    if (needToHandleLegacyIterCounts) {
        cleanLegacyIterationCounts(iterationCounts);
    }
    //Get mean magnitudes line chart
    ModelType mt;
    if (conf.getFirst() != null)
        mt = ModelType.MLN;
    else if (conf.getSecond() != null)
        mt = ModelType.CG;
    else
        mt = ModelType.Layer;
    MeanMagnitudes mm = getLayerMeanMagnitudes(layerIdx, gi, updates, iterationCounts, mt);
    Map<String, Object> mmRatioMap = new HashMap<>();
    mmRatioMap.put("layerParamNames", mm.getRatios().keySet());
    mmRatioMap.put("iterCounts", mm.getIterations());
    mmRatioMap.put("ratios", mm.getRatios());
    mmRatioMap.put("paramMM", mm.getParamMM());
    mmRatioMap.put("updateMM", mm.getUpdateMM());
    result.put("meanMag", mmRatioMap);
    //Get activations line chart for layer
    Triple<int[], float[], float[]> activationsData = getLayerActivations(layerIdx, gi, updates, iterationCounts);
    Map<String, Object> activationMap = new HashMap<>();
    activationMap.put("iterCount", activationsData.getFirst());
    activationMap.put("mean", activationsData.getSecond());
    activationMap.put("stdev", activationsData.getThird());
    result.put("activations", activationMap);
    //Get learning rate vs. time chart for layer
    Map<String, Object> lrs = getLayerLearningRates(layerIdx, gi, updates, iterationCounts, mt);
    result.put("learningRates", lrs);
    //Parameters histogram data
    Persistable lastUpdate = (updates != null && updates.size() > 0 ? updates.get(updates.size() - 1) : null);
    Map<String, Object> paramHistograms = getHistograms(layerIdx, gi, StatsType.Parameters, lastUpdate);
    result.put("paramHist", paramHistograms);
    //Updates histogram data
    Map<String, Object> updateHistograms = getHistograms(layerIdx, gi, StatsType.Updates, lastUpdate);
    result.put("updateHist", updateHistograms);
    return ok(Json.toJson(result));
}
Also used : Persistable(org.deeplearning4j.api.storage.Persistable) StatsReport(org.deeplearning4j.ui.stats.api.StatsReport) MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) StatsStorage(org.deeplearning4j.api.storage.StatsStorage) NeuralNetConfiguration(org.deeplearning4j.nn.conf.NeuralNetConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputationGraphConfiguration(org.deeplearning4j.nn.conf.ComputationGraphConfiguration)

Example 15 with StatsStorage

use of org.deeplearning4j.api.storage.StatsStorage in project deeplearning4j by deeplearning4j.

the class TestPlayUI method testUI.

@Test
@Ignore
public void testUI() throws Exception {
    StatsStorage ss = new InMemoryStatsStorage();
    PlayUIServer uiServer = (PlayUIServer) UIServer.getInstance();
    assertEquals(9000, uiServer.getPort());
    uiServer.stop();
    PlayUIServer playUIServer = new PlayUIServer();
    playUIServer.runMain(new String[] { "--uiPort", "9100", "-r", "true" });
    assertEquals(9100, playUIServer.getPort());
    playUIServer.stop();
    //        uiServer.attach(ss);
    //
    //        MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
    //                .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).iterations(1)
    //                .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())
    //                .pretrain(false).backprop(true).build();
    //
    //        MultiLayerNetwork net = new MultiLayerNetwork(conf);
    //        net.init();
    //        net.setListeners(new StatsListener(ss, 3), new ScoreIterationListener(1));
    //
    //        DataSetIterator iter = new IrisDataSetIterator(150, 150);
    //
    //        for (int i = 0; i < 500; i++) {
    //            net.fit(iter);
    ////            Thread.sleep(100);
    //            Thread.sleep(100);
    //        }
    //
    ////        uiServer.stop();
    Thread.sleep(100000);
}
Also used : InMemoryStatsStorage(org.deeplearning4j.ui.storage.InMemoryStatsStorage) StatsStorage(org.deeplearning4j.api.storage.StatsStorage) InMemoryStatsStorage(org.deeplearning4j.ui.storage.InMemoryStatsStorage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

StatsStorage (org.deeplearning4j.api.storage.StatsStorage)22 Persistable (org.deeplearning4j.api.storage.Persistable)14 Test (org.junit.Test)10 MultiLayerConfiguration (org.deeplearning4j.nn.conf.MultiLayerConfiguration)8 IrisDataSetIterator (org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator)7 InMemoryStatsStorage (org.deeplearning4j.ui.storage.InMemoryStatsStorage)7 MultiLayerNetwork (org.deeplearning4j.nn.multilayer.MultiLayerNetwork)6 StatsListener (org.deeplearning4j.ui.stats.StatsListener)6 Ignore (org.junit.Ignore)6 UIServer (org.deeplearning4j.ui.api.UIServer)5 DataSetIterator (org.nd4j.linalg.dataset.api.iterator.DataSetIterator)5 NeuralNetConfiguration (org.deeplearning4j.nn.conf.NeuralNetConfiguration)4 OutputLayer (org.deeplearning4j.nn.conf.layers.OutputLayer)4 ScoreIterationListener (org.deeplearning4j.optimize.listeners.ScoreIterationListener)4 StatsInitializationReport (org.deeplearning4j.ui.stats.api.StatsInitializationReport)4 MapDBStatsStorage (org.deeplearning4j.ui.storage.mapdb.MapDBStatsStorage)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ComputationGraphConfiguration (org.deeplearning4j.nn.conf.ComputationGraphConfiguration)3 StatsReport (org.deeplearning4j.ui.stats.api.StatsReport)3 File (java.io.File)2