Search in sources :

Example 1 with StyleText

use of org.deeplearning4j.ui.components.text.style.StyleText in project deeplearning4j by deeplearning4j.

the class StatsUtils method exportStatsAsHTML.

/**
     * Generate and export a HTML representation (including charts, etc) of the Spark training statistics<br>
     * This overload is for writing to an output stream
     *
     * @param sparkTrainingStats Stats to generate HTML page for
     * @param maxTimelineSizeMs  maximum amount of activity to show in a single timeline plot (multiple plots will be used if training exceeds this amount of time)
     * @throws Exception IO errors or error generating HTML file
     */
public static void exportStatsAsHTML(SparkTrainingStats sparkTrainingStats, long maxTimelineSizeMs, OutputStream outputStream) throws Exception {
    Set<String> keySet = sparkTrainingStats.getKeySet();
    List<Component> components = new ArrayList<>();
    StyleChart styleChart = new StyleChart.Builder().backgroundColor(Color.WHITE).width(700, LengthUnit.Px).height(400, LengthUnit.Px).build();
    StyleText styleText = new StyleText.Builder().color(Color.BLACK).fontSize(20).build();
    Component headerText = new ComponentText("Deeplearning4j - Spark Training Analysis", styleText);
    Component header = new ComponentDiv(new StyleDiv.Builder().height(40, LengthUnit.Px).width(100, LengthUnit.Percent).build(), headerText);
    components.add(header);
    Set<String> keySetInclude = new HashSet<>();
    for (String s : keySet) if (sparkTrainingStats.defaultIncludeInPlots(s))
        keySetInclude.add(s);
    Collections.addAll(components, getTrainingStatsTimelineChart(sparkTrainingStats, keySetInclude, maxTimelineSizeMs));
    for (String s : keySet) {
        List<EventStats> list = new ArrayList<>(sparkTrainingStats.getValue(s));
        Collections.sort(list, new StartTimeComparator());
        double[] x = new double[list.size()];
        double[] duration = new double[list.size()];
        double minDur = Double.MAX_VALUE;
        double maxDur = -Double.MAX_VALUE;
        for (int i = 0; i < duration.length; i++) {
            x[i] = i;
            duration[i] = list.get(i).getDurationMs();
            minDur = Math.min(minDur, duration[i]);
            maxDur = Math.max(maxDur, duration[i]);
        }
        Component line = new ChartLine.Builder(s, styleChart).addSeries("Duration", x, duration).setYMin(minDur == maxDur ? minDur - 1 : null).setYMax(minDur == maxDur ? minDur + 1 : null).build();
        //Also build a histogram...
        Component hist = null;
        if (minDur != maxDur && !list.isEmpty())
            hist = getHistogram(duration, 20, s, styleChart);
        Component[] temp;
        if (hist != null) {
            temp = new Component[] { line, hist };
        } else {
            temp = new Component[] { line };
        }
        components.add(new ComponentDiv(new StyleDiv.Builder().width(100, LengthUnit.Percent).build(), temp));
        //TODO this is really ugly
        if (!list.isEmpty() && (list.get(0) instanceof ExampleCountEventStats || list.get(0) instanceof PartitionCountEventStats)) {
            boolean exCount = list.get(0) instanceof ExampleCountEventStats;
            double[] y = new double[list.size()];
            double miny = Double.MAX_VALUE;
            double maxy = -Double.MAX_VALUE;
            for (int i = 0; i < y.length; i++) {
                y[i] = (exCount ? ((ExampleCountEventStats) list.get(i)).getTotalExampleCount() : ((PartitionCountEventStats) list.get(i)).getNumPartitions());
                miny = Math.min(miny, y[i]);
                maxy = Math.max(maxy, y[i]);
            }
            String title = s + " / " + (exCount ? "Number of Examples" : "Number of Partitions");
            Component line2 = new ChartLine.Builder(title, styleChart).addSeries((exCount ? "Examples" : "Partitions"), x, y).setYMin(miny == maxy ? miny - 1 : null).setYMax(miny == maxy ? miny + 1 : null).build();
            //Also build a histogram...
            Component hist2 = null;
            if (miny != maxy)
                hist2 = getHistogram(y, 20, title, styleChart);
            Component[] temp2;
            if (hist2 != null) {
                temp2 = new Component[] { line2, hist2 };
            } else {
                temp2 = new Component[] { line2 };
            }
            components.add(new ComponentDiv(new StyleDiv.Builder().width(100, LengthUnit.Percent).build(), temp2));
        }
    }
    String html = StaticPageUtil.renderHTML(components);
    outputStream.write(html.getBytes("UTF-8"));
}
Also used : StyleText(org.deeplearning4j.ui.components.text.style.StyleText) StyleChart(org.deeplearning4j.ui.components.chart.style.StyleChart) Component(org.deeplearning4j.ui.api.Component) ComponentDiv(org.deeplearning4j.ui.components.component.ComponentDiv) ComponentText(org.deeplearning4j.ui.components.text.ComponentText)

Aggregations

Component (org.deeplearning4j.ui.api.Component)1 StyleChart (org.deeplearning4j.ui.components.chart.style.StyleChart)1 ComponentDiv (org.deeplearning4j.ui.components.component.ComponentDiv)1 ComponentText (org.deeplearning4j.ui.components.text.ComponentText)1 StyleText (org.deeplearning4j.ui.components.text.style.StyleText)1