Search in sources :

Example 6 with TableOutput

use of com.simiacryptus.util.TableOutput in project MindsEye by SimiaCryptus.

the class EncodingUtil method validationReport.

/**
 * Validation report.
 *
 * @param log          the log
 * @param data         the data
 * @param dataPipeline the data pipeline
 * @param maxRows      the max rows
 */
public static void validationReport(@Nonnull final NotebookOutput log, @Nonnull final Tensor[][] data, @Nonnull final List<Layer> dataPipeline, final int maxRows) {
    log.out("Current dataset and evaluation results: ");
    log.code(() -> {
        @Nonnull final TableOutput table = new TableOutput();
        Arrays.stream(data).limit(maxRows).map(tensorArray -> {
            @Nonnull final LinkedHashMap<CharSequence, Object> row = new LinkedHashMap<>();
            for (int col = 1; col < tensorArray.length; col++) {
                EncodingUtil.renderLayer(log, dataPipeline, row, col, tensorArray[col]);
            }
            return row;
        }).filter(x -> null != x).limit(10).forEach(table::putRow);
        return table;
    });
}
Also used : PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) IntStream(java.util.stream.IntStream) Coordinate(com.simiacryptus.mindseye.lang.Coordinate) Arrays(java.util.Arrays) DoubleStatistics(com.simiacryptus.util.data.DoubleStatistics) GifSequenceWriter(com.simiacryptus.util.io.GifSequenceWriter) TableOutput(com.simiacryptus.util.TableOutput) LoggerFactory(org.slf4j.LoggerFactory) Tensor(com.simiacryptus.mindseye.lang.Tensor) Caltech101(com.simiacryptus.mindseye.test.data.Caltech101) Function(java.util.function.Function) LinkedHashMap(java.util.LinkedHashMap) ImgBandScaleLayer(com.simiacryptus.mindseye.layers.java.ImgBandScaleLayer) TrainingMonitor(com.simiacryptus.mindseye.opt.TrainingMonitor) ImageIO(javax.imageio.ImageIO) Layer(com.simiacryptus.mindseye.lang.Layer) StepRecord(com.simiacryptus.mindseye.test.StepRecord) NotebookOutput(com.simiacryptus.util.io.NotebookOutput) PCAUtil(com.simiacryptus.mindseye.test.PCAUtil) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) PrintStream(java.io.PrintStream) MeanSqLossLayer(com.simiacryptus.mindseye.layers.java.MeanSqLossLayer) Logger(org.slf4j.Logger) SysOutInterceptor(com.simiacryptus.util.test.SysOutInterceptor) BufferedImage(java.awt.image.BufferedImage) ImgBandSelectLayer(com.simiacryptus.mindseye.layers.java.ImgBandSelectLayer) IOException(java.io.IOException) TestUtil(com.simiacryptus.mindseye.test.TestUtil) FastRandom(com.simiacryptus.util.FastRandom) Collectors(java.util.stream.Collectors) File(java.io.File) DoubleStream(java.util.stream.DoubleStream) ConvolutionLayer(com.simiacryptus.mindseye.layers.cudnn.ConvolutionLayer) List(java.util.List) Stream(java.util.stream.Stream) ScalarStatistics(com.simiacryptus.util.data.ScalarStatistics) ToDoubleFunction(java.util.function.ToDoubleFunction) ImgReshapeLayer(com.simiacryptus.mindseye.layers.java.ImgReshapeLayer) ImgBandBiasLayer(com.simiacryptus.mindseye.layers.java.ImgBandBiasLayer) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) Step(com.simiacryptus.mindseye.opt.Step) Comparator(java.util.Comparator) TableOutput(com.simiacryptus.util.TableOutput) Nonnull(javax.annotation.Nonnull) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with TableOutput

use of com.simiacryptus.util.TableOutput in project MindsEye by SimiaCryptus.

the class ImageClassifierTestBase method run.

/**
 * Test.
 *
 * @param log the log
 */
public void run(@Nonnull NotebookOutput log) {
    Future<Tensor[][]> submit = Executors.newSingleThreadExecutor().submit(() -> Arrays.stream(EncodingUtil.getImages(log, img -> {
        return img;
    // return TestUtil.resize(img, 224, 224);
    // if(img.getWidth()>img.getHeight()) {
    // return TestUtil.resize(img, 224, img.getHeight() * 224 / img.getWidth());
    // } else {
    // return TestUtil.resize(img, img.getWidth() * 224 / img.getHeight(), 224);
    // }
    }, 10, new CharSequence[] {})).toArray(i -> new Tensor[i][]));
    ImageClassifier vgg16 = getImageClassifier(log);
    @Nonnull Layer network = vgg16.getNetwork();
    log.h1("Network Diagram");
    log.p("This is a diagram of the imported network:");
    log.code(() -> {
        return Graphviz.fromGraph(TestUtil.toGraph((DAGNetwork) network)).height(4000).width(800).render(Format.PNG).toImage();
    });
    // @javax.annotation.Nonnull SerializationTest serializationTest = new SerializationTest();
    // serializationTest.setPersist(true);
    // serializationTest.test(log, network, (Tensor[]) null);
    log.h1("Predictions");
    Tensor[][] images;
    try {
        images = submit.get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    @Nonnull Map<CharSequence, List<LinkedHashMap<CharSequence, Double>>> modelPredictions = new HashMap<>();
    modelPredictions.put("Source", predict(log, vgg16, network, images));
    network.freeRef();
    // serializationTest.getModels().forEach((precision, model) -> {
    // log.h2(precision.name());
    // modelPredictions.put(precision.name(), predict(log, vgg16, model, images));
    // });
    log.h1("Result");
    log.code(() -> {
        @Nonnull TableOutput tableOutput = new TableOutput();
        for (int i = 0; i < images.length; i++) {
            int index = i;
            @Nonnull HashMap<CharSequence, Object> row = new HashMap<>();
            row.put("Image", log.image(images[i][1].toImage(), ""));
            modelPredictions.forEach((model, predictions) -> {
                row.put(model, predictions.get(index).entrySet().stream().map(e -> String.format("%s -> %.2f", e.getKey(), 100 * e.getValue())).reduce((a, b) -> a + "<br/>" + b).get());
            });
            tableOutput.putRow(row);
        }
        return tableOutput;
    }, 256 * 1024);
// log.p("CudaSystem Statistics:");
// log.code(() -> {
// return TestUtil.toFormattedJson(CudaSystem.getExecutionStatistics());
// });
}
Also used : Graphviz(guru.nidi.graphviz.engine.Graphviz) Arrays(java.util.Arrays) TableOutput(com.simiacryptus.util.TableOutput) Tensor(com.simiacryptus.mindseye.lang.Tensor) NotebookReportBase(com.simiacryptus.mindseye.test.NotebookReportBase) Test(org.junit.Test) HashMap(java.util.HashMap) TestUtil(com.simiacryptus.mindseye.test.TestUtil) Executors(java.util.concurrent.Executors) LinkedHashMap(java.util.LinkedHashMap) ImageClassifier(com.simiacryptus.mindseye.applications.ImageClassifier) List(java.util.List) Future(java.util.concurrent.Future) Format(guru.nidi.graphviz.engine.Format) Map(java.util.Map) Layer(com.simiacryptus.mindseye.lang.Layer) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) NotebookOutput(com.simiacryptus.util.io.NotebookOutput) EncodingUtil(com.simiacryptus.mindseye.labs.encoding.EncodingUtil) Nonnull(javax.annotation.Nonnull) Tensor(com.simiacryptus.mindseye.lang.Tensor) Nonnull(javax.annotation.Nonnull) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) Layer(com.simiacryptus.mindseye.lang.Layer) TableOutput(com.simiacryptus.util.TableOutput) ImageClassifier(com.simiacryptus.mindseye.applications.ImageClassifier) List(java.util.List)

Aggregations

Tensor (com.simiacryptus.mindseye.lang.Tensor)7 TableOutput (com.simiacryptus.util.TableOutput)7 NotebookOutput (com.simiacryptus.util.io.NotebookOutput)7 LinkedHashMap (java.util.LinkedHashMap)7 List (java.util.List)7 Nonnull (javax.annotation.Nonnull)7 DAGNetwork (com.simiacryptus.mindseye.network.DAGNetwork)6 TestUtil (com.simiacryptus.mindseye.test.TestUtil)6 Nullable (javax.annotation.Nullable)6 IOException (java.io.IOException)5 Arrays (java.util.Arrays)5 Layer (com.simiacryptus.mindseye.lang.Layer)4 PipelineNetwork (com.simiacryptus.mindseye.network.PipelineNetwork)4 TrainingMonitor (com.simiacryptus.mindseye.opt.TrainingMonitor)4 StepRecord (com.simiacryptus.mindseye.test.StepRecord)4 Format (guru.nidi.graphviz.engine.Format)4 Graphviz (guru.nidi.graphviz.engine.Graphviz)4 ArrayList (java.util.ArrayList)4 Comparator (java.util.Comparator)4 ArrayTrainable (com.simiacryptus.mindseye.eval.ArrayTrainable)3