Search in sources :

Example 16 with NotebookOutput

use of com.simiacryptus.util.io.NotebookOutput in project MindsEye by SimiaCryptus.

the class StyleTransfer method styleTransfer.

/**
 * Style transfer buffered image.
 *
 * @param server          the server
 * @param log             the log
 * @param canvasImage     the canvas image
 * @param styleParameters the style parameters
 * @param trainingMinutes the training minutes
 * @param measureStyle    the measure style
 * @return the buffered image
 */
public BufferedImage styleTransfer(final StreamNanoHTTPD server, @Nonnull final NotebookOutput log, final BufferedImage canvasImage, final StyleSetup<T> styleParameters, final int trainingMinutes, final NeuralSetup measureStyle) {
    BufferedImage result = ArtistryUtil.logExceptionWithDefault(log, () -> {
        log.p("Input Content:");
        log.p(log.image(styleParameters.contentImage, "Content Image"));
        log.p("Style Content:");
        styleParameters.styleImages.forEach((file, styleImage) -> {
            log.p(log.image(styleImage, file));
        });
        log.p("Input Canvas:");
        log.p(log.image(canvasImage, "Input Canvas"));
        System.gc();
        Tensor canvas = Tensor.fromRGB(canvasImage);
        TestUtil.monitorImage(canvas, false, false);
        log.p("Input Parameters:");
        log.code(() -> {
            return ArtistryUtil.toJson(styleParameters);
        });
        Trainable trainable = log.code(() -> {
            PipelineNetwork network = fitnessNetwork(measureStyle);
            network.setFrozen(true);
            ArtistryUtil.setPrecision(network, styleParameters.precision);
            TestUtil.instrumentPerformance(network);
            if (null != server)
                ArtistryUtil.addLayersHandler(network, server);
            return new ArrayTrainable(network, 1).setVerbose(true).setMask(true).setData(Arrays.asList(new Tensor[][] { { canvas } }));
        });
        log.code(() -> {
            @Nonnull ArrayList<StepRecord> history = new ArrayList<>();
            new IterativeTrainer(trainable).setMonitor(TestUtil.getMonitor(history)).setOrientation(new TrustRegionStrategy() {

                @Override
                public TrustRegion getRegionPolicy(final Layer layer) {
                    return new RangeConstraint().setMin(1e-2).setMax(256);
                }
            }).setIterationsPerSample(100).setLineSearchFactory(name -> new BisectionSearch().setSpanTol(1e-1).setCurrentRate(1e6)).setTimeout(trainingMinutes, TimeUnit.MINUTES).setTerminateThreshold(Double.NEGATIVE_INFINITY).runAndFree();
            return TestUtil.plot(history);
        });
        return canvas.toImage();
    }, canvasImage);
    log.p("Output Canvas:");
    log.p(log.image(result, "Output Canvas"));
    return result;
}
Also used : PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TrustRegion(com.simiacryptus.mindseye.opt.region.TrustRegion) MeanSqLossLayer(com.simiacryptus.mindseye.layers.cudnn.MeanSqLossLayer) LoggerFactory(org.slf4j.LoggerFactory) Tensor(com.simiacryptus.mindseye.lang.Tensor) TrustRegionStrategy(com.simiacryptus.mindseye.opt.orient.TrustRegionStrategy) HashMap(java.util.HashMap) NullNotebookOutput(com.simiacryptus.util.io.NullNotebookOutput) MultiLayerImageNetwork(com.simiacryptus.mindseye.models.MultiLayerImageNetwork) ArrayList(java.util.ArrayList) JsonUtil(com.simiacryptus.util.io.JsonUtil) Trainable(com.simiacryptus.mindseye.eval.Trainable) Precision(com.simiacryptus.mindseye.lang.cudnn.Precision) Tuple2(com.simiacryptus.util.lang.Tuple2) Map(java.util.Map) Layer(com.simiacryptus.mindseye.lang.Layer) GateBiasLayer(com.simiacryptus.mindseye.layers.cudnn.GateBiasLayer) StepRecord(com.simiacryptus.mindseye.test.StepRecord) NotebookOutput(com.simiacryptus.util.io.NotebookOutput) IterativeTrainer(com.simiacryptus.mindseye.opt.IterativeTrainer) Nonnull(javax.annotation.Nonnull) Logger(org.slf4j.Logger) BufferedImage(java.awt.image.BufferedImage) ValueLayer(com.simiacryptus.mindseye.layers.cudnn.ValueLayer) TestUtil(com.simiacryptus.mindseye.test.TestUtil) UUID(java.util.UUID) DAGNode(com.simiacryptus.mindseye.network.DAGNode) Collectors(java.util.stream.Collectors) BandAvgReducerLayer(com.simiacryptus.mindseye.layers.cudnn.BandAvgReducerLayer) StreamNanoHTTPD(com.simiacryptus.util.StreamNanoHTTPD) TimeUnit(java.util.concurrent.TimeUnit) BisectionSearch(com.simiacryptus.mindseye.opt.line.BisectionSearch) List(java.util.List) GramianLayer(com.simiacryptus.mindseye.layers.cudnn.GramianLayer) Stream(java.util.stream.Stream) ArrayTrainable(com.simiacryptus.mindseye.eval.ArrayTrainable) BinarySumLayer(com.simiacryptus.mindseye.layers.cudnn.BinarySumLayer) InnerNode(com.simiacryptus.mindseye.network.InnerNode) ScalarStatistics(com.simiacryptus.util.data.ScalarStatistics) MultiLayerVGG16(com.simiacryptus.mindseye.models.MultiLayerVGG16) RangeConstraint(com.simiacryptus.mindseye.opt.region.RangeConstraint) LayerEnum(com.simiacryptus.mindseye.models.LayerEnum) MultiLayerVGG19(com.simiacryptus.mindseye.models.MultiLayerVGG19) Tensor(com.simiacryptus.mindseye.lang.Tensor) IterativeTrainer(com.simiacryptus.mindseye.opt.IterativeTrainer) Nonnull(javax.annotation.Nonnull) ArrayList(java.util.ArrayList) PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) ArrayTrainable(com.simiacryptus.mindseye.eval.ArrayTrainable) MeanSqLossLayer(com.simiacryptus.mindseye.layers.cudnn.MeanSqLossLayer) Layer(com.simiacryptus.mindseye.lang.Layer) GateBiasLayer(com.simiacryptus.mindseye.layers.cudnn.GateBiasLayer) ValueLayer(com.simiacryptus.mindseye.layers.cudnn.ValueLayer) BandAvgReducerLayer(com.simiacryptus.mindseye.layers.cudnn.BandAvgReducerLayer) GramianLayer(com.simiacryptus.mindseye.layers.cudnn.GramianLayer) BinarySumLayer(com.simiacryptus.mindseye.layers.cudnn.BinarySumLayer) BufferedImage(java.awt.image.BufferedImage) StepRecord(com.simiacryptus.mindseye.test.StepRecord) RangeConstraint(com.simiacryptus.mindseye.opt.region.RangeConstraint) BisectionSearch(com.simiacryptus.mindseye.opt.line.BisectionSearch) Trainable(com.simiacryptus.mindseye.eval.Trainable) ArrayTrainable(com.simiacryptus.mindseye.eval.ArrayTrainable) TrustRegionStrategy(com.simiacryptus.mindseye.opt.orient.TrustRegionStrategy)

Example 17 with NotebookOutput

use of com.simiacryptus.util.io.NotebookOutput in project MindsEye by SimiaCryptus.

the class CudaLayerTester method testNonstandardBoundsBackprop.

/**
 * Test nonstandard bounds backprop tolerance statistics.
 *
 * @param log            the log
 * @param layer          the layer
 * @param inputPrototype the input prototype
 * @return the tolerance statistics
 */
@Nonnull
public ToleranceStatistics testNonstandardBoundsBackprop(final NotebookOutput log, @Nullable final Layer layer, @Nonnull final Tensor[] inputPrototype) {
    log.h2("Irregular Backprop");
    log.p("This layer should accept non-dense tensors as delta input.");
    return log.code(() -> {
        Tensor[] randomized = Arrays.stream(inputPrototype).map(x -> x.map(v -> getRandom())).toArray(i -> new Tensor[i]);
        logger.info("Input: " + Arrays.stream(randomized).map(Tensor::prettyPrint).collect(Collectors.toList()));
        Precision precision = Precision.Double;
        TensorList[] controlInput = Arrays.stream(randomized).map(original -> {
            return TensorArray.wrap(original);
        }).toArray(i -> new TensorList[i]);
        @Nonnull final SimpleResult testResult = CudaSystem.run(gpu -> {
            TensorList[] copy = copy(controlInput);
            SimpleResult result = new SimpleGpuEval(layer, gpu, copy) {

                @Nonnull
                @Override
                public TensorList getFeedback(@Nonnull final TensorList original) {
                    Tensor originalTensor = original.get(0).mapAndFree(x -> 1);
                    CudaTensorList cudaTensorList = buildIrregularCudaTensor(gpu, precision, originalTensor);
                    originalTensor.freeRef();
                    return cudaTensorList;
                }
            }.call();
            Arrays.stream(copy).forEach(ReferenceCounting::freeRef);
            return result;
        });
        @Nonnull final SimpleResult controlResult = CudaSystem.run(gpu -> {
            TensorList[] copy = copy(controlInput);
            SimpleResult result = SimpleGpuEval.run(layer, gpu, copy);
            Arrays.stream(copy).forEach(ReferenceCounting::freeRef);
            return result;
        }, 1);
        try {
            ToleranceStatistics compareOutput = compareOutput(controlResult, testResult);
            ToleranceStatistics compareDerivatives = compareDerivatives(controlResult, testResult);
            return compareDerivatives.combine(compareOutput);
        } finally {
            Arrays.stream(controlInput).forEach(ReferenceCounting::freeRef);
            controlResult.freeRef();
            testResult.freeRef();
        }
    });
}
Also used : IntStream(java.util.stream.IntStream) SimpleResult(com.simiacryptus.mindseye.test.SimpleResult) SimpleGpuEval(com.simiacryptus.mindseye.test.SimpleGpuEval) Arrays(java.util.Arrays) CudaMemory(com.simiacryptus.mindseye.lang.cudnn.CudaMemory) LoggerFactory(org.slf4j.LoggerFactory) Tensor(com.simiacryptus.mindseye.lang.Tensor) ReferenceCountingBase(com.simiacryptus.mindseye.lang.ReferenceCountingBase) Random(java.util.Random) Function(java.util.function.Function) Precision(com.simiacryptus.mindseye.lang.cudnn.Precision) CudnnHandle(com.simiacryptus.mindseye.lang.cudnn.CudnnHandle) Layer(com.simiacryptus.mindseye.lang.Layer) NotebookOutput(com.simiacryptus.util.io.NotebookOutput) ReferenceCounting(com.simiacryptus.mindseye.lang.ReferenceCounting) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IntFunction(java.util.function.IntFunction) Logger(org.slf4j.Logger) CudaDevice(com.simiacryptus.mindseye.lang.cudnn.CudaDevice) CudaTensor(com.simiacryptus.mindseye.lang.cudnn.CudaTensor) CudaTensorList(com.simiacryptus.mindseye.lang.cudnn.CudaTensorList) Collectors(java.util.stream.Collectors) Stream(java.util.stream.Stream) CudaSystem(com.simiacryptus.mindseye.lang.cudnn.CudaSystem) ToleranceStatistics(com.simiacryptus.mindseye.test.ToleranceStatistics) TensorList(com.simiacryptus.mindseye.lang.TensorList) MemoryType(com.simiacryptus.mindseye.lang.cudnn.MemoryType) TensorArray(com.simiacryptus.mindseye.lang.TensorArray) Tensor(com.simiacryptus.mindseye.lang.Tensor) CudaTensor(com.simiacryptus.mindseye.lang.cudnn.CudaTensor) Nonnull(javax.annotation.Nonnull) CudaTensorList(com.simiacryptus.mindseye.lang.cudnn.CudaTensorList) TensorList(com.simiacryptus.mindseye.lang.TensorList) SimpleGpuEval(com.simiacryptus.mindseye.test.SimpleGpuEval) SimpleResult(com.simiacryptus.mindseye.test.SimpleResult) CudaTensorList(com.simiacryptus.mindseye.lang.cudnn.CudaTensorList) ReferenceCounting(com.simiacryptus.mindseye.lang.ReferenceCounting) Precision(com.simiacryptus.mindseye.lang.cudnn.Precision) ToleranceStatistics(com.simiacryptus.mindseye.test.ToleranceStatistics) Nonnull(javax.annotation.Nonnull)

Example 18 with NotebookOutput

use of com.simiacryptus.util.io.NotebookOutput in project MindsEye by SimiaCryptus.

the class CudaLayerTester method testInterGpu.

/**
 * Test inter gpu tolerance statistics.
 *
 * @param log            the log
 * @param reference      the reference
 * @param inputPrototype the input prototype
 * @return the tolerance statistics
 */
@Nonnull
public ToleranceStatistics testInterGpu(final NotebookOutput log, @Nullable final Layer reference, @Nonnull final Tensor[] inputPrototype) {
    log.h2("Multi-GPU Compatibility");
    log.p("This layer should be able to apply using a GPU context other than the one used to create the inputs.");
    return log.code(() -> {
        final TensorList[] heapInput = Arrays.stream(inputPrototype).map(t -> TensorArray.wrap(IntStream.range(0, getBatchSize()).mapToObj(i -> t.map(v -> getRandom())).toArray(i -> new Tensor[i]))).toArray(i -> new TensorList[i]);
        logger.info("Input: " + Arrays.stream(heapInput).flatMap(x -> x.stream()).map(tensor -> {
            String prettyPrint = tensor.prettyPrint();
            tensor.freeRef();
            return prettyPrint;
        }).collect(Collectors.toList()));
        TensorList[] gpuInput = CudaSystem.run(gpu -> {
            return Arrays.stream(heapInput).map(original -> {
                return CudaTensorList.wrap(gpu.getTensor(original, Precision.Double, MemoryType.Managed, false), original.length(), original.getDimensions(), Precision.Double);
            }).toArray(i -> new TensorList[i]);
        }, 0);
        @Nonnull final SimpleResult fromHeap = CudaSystem.run(gpu -> {
            return SimpleGpuEval.run(reference, gpu, heapInput);
        }, 1);
        @Nonnull final SimpleResult fromGPU = CudaSystem.run(gpu -> {
            return SimpleGpuEval.run(reference, gpu, gpuInput);
        }, 1);
        try {
            ToleranceStatistics compareOutput = compareOutput(fromHeap, fromGPU);
            ToleranceStatistics compareDerivatives = compareDerivatives(fromHeap, fromGPU);
            return compareDerivatives.combine(compareOutput);
        } finally {
            Arrays.stream(gpuInput).forEach(ReferenceCounting::freeRef);
            Arrays.stream(heapInput).forEach(x -> x.freeRef());
            fromGPU.freeRef();
            fromHeap.freeRef();
        }
    });
}
Also used : IntStream(java.util.stream.IntStream) SimpleResult(com.simiacryptus.mindseye.test.SimpleResult) SimpleGpuEval(com.simiacryptus.mindseye.test.SimpleGpuEval) Arrays(java.util.Arrays) CudaMemory(com.simiacryptus.mindseye.lang.cudnn.CudaMemory) LoggerFactory(org.slf4j.LoggerFactory) Tensor(com.simiacryptus.mindseye.lang.Tensor) ReferenceCountingBase(com.simiacryptus.mindseye.lang.ReferenceCountingBase) Random(java.util.Random) Function(java.util.function.Function) Precision(com.simiacryptus.mindseye.lang.cudnn.Precision) CudnnHandle(com.simiacryptus.mindseye.lang.cudnn.CudnnHandle) Layer(com.simiacryptus.mindseye.lang.Layer) NotebookOutput(com.simiacryptus.util.io.NotebookOutput) ReferenceCounting(com.simiacryptus.mindseye.lang.ReferenceCounting) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IntFunction(java.util.function.IntFunction) Logger(org.slf4j.Logger) CudaDevice(com.simiacryptus.mindseye.lang.cudnn.CudaDevice) CudaTensor(com.simiacryptus.mindseye.lang.cudnn.CudaTensor) CudaTensorList(com.simiacryptus.mindseye.lang.cudnn.CudaTensorList) Collectors(java.util.stream.Collectors) Stream(java.util.stream.Stream) CudaSystem(com.simiacryptus.mindseye.lang.cudnn.CudaSystem) ToleranceStatistics(com.simiacryptus.mindseye.test.ToleranceStatistics) TensorList(com.simiacryptus.mindseye.lang.TensorList) MemoryType(com.simiacryptus.mindseye.lang.cudnn.MemoryType) TensorArray(com.simiacryptus.mindseye.lang.TensorArray) Tensor(com.simiacryptus.mindseye.lang.Tensor) CudaTensor(com.simiacryptus.mindseye.lang.cudnn.CudaTensor) ReferenceCounting(com.simiacryptus.mindseye.lang.ReferenceCounting) Nonnull(javax.annotation.Nonnull) ToleranceStatistics(com.simiacryptus.mindseye.test.ToleranceStatistics) CudaTensorList(com.simiacryptus.mindseye.lang.cudnn.CudaTensorList) TensorList(com.simiacryptus.mindseye.lang.TensorList) SimpleResult(com.simiacryptus.mindseye.test.SimpleResult) Nonnull(javax.annotation.Nonnull)

Example 19 with NotebookOutput

use of com.simiacryptus.util.io.NotebookOutput in project MindsEye by SimiaCryptus.

the class SerializationTest method test.

@Nullable
@Override
public ToleranceStatistics test(@Nonnull final NotebookOutput log, @Nonnull final Layer layer, final Tensor... inputPrototype) {
    log.h1("Serialization");
    log.p("This apply will demonstrate the layer's JSON serialization, and verify deserialization integrity.");
    String prettyPrint = "";
    log.h2("Raw Json");
    try {
        prettyPrint = log.code(() -> {
            final JsonObject json = layer.getJson();
            @Nonnull final Layer echo = Layer.fromJson(json);
            if (echo == null)
                throw new AssertionError("Failed to deserialize");
            if (layer == echo)
                throw new AssertionError("Serialization did not copy");
            if (!layer.equals(echo))
                throw new AssertionError("Serialization not equal");
            echo.freeRef();
            return new GsonBuilder().setPrettyPrinting().create().toJson(json);
        });
        @Nonnull String filename = layer.getClass().getSimpleName() + "_" + log.getName() + ".json";
        log.p(log.file(prettyPrint, filename, String.format("Wrote Model to %s; %s characters", filename, prettyPrint.length())));
    } catch (RuntimeException e) {
        e.printStackTrace();
        Util.sleep(1000);
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        Util.sleep(1000);
    }
    log.p("");
    @Nonnull Object outSync = new Object();
    if (prettyPrint.isEmpty() || prettyPrint.length() > 1024 * 64)
        Arrays.stream(SerialPrecision.values()).parallel().forEach(precision -> {
            try {
                @Nonnull File file = new File(log.getResourceDir(), log.getName() + "_" + precision.name() + ".zip");
                layer.writeZip(file, precision);
                @Nonnull final Layer echo = Layer.fromZip(new ZipFile(file));
                getModels().put(precision, echo);
                synchronized (outSync) {
                    log.h2(String.format("Zipfile %s", precision.name()));
                    log.p(log.link(file, String.format("Wrote Model apply %s precision to %s; %.3fMiB bytes", precision, file.getName(), file.length() * 1.0 / (0x100000))));
                }
                if (!isPersist())
                    file.delete();
                if (echo == null)
                    throw new AssertionError("Failed to deserialize");
                if (layer == echo)
                    throw new AssertionError("Serialization did not copy");
                if (!layer.equals(echo))
                    throw new AssertionError("Serialization not equal");
            } catch (RuntimeException e) {
                e.printStackTrace();
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
            } catch (ZipException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) Util(com.simiacryptus.util.Util) Arrays(java.util.Arrays) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ZipException(java.util.zip.ZipException) Tensor(com.simiacryptus.mindseye.lang.Tensor) IOException(java.io.IOException) HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) File(java.io.File) IOUtils(org.apache.commons.io.IOUtils) Charset(java.nio.charset.Charset) ToleranceStatistics(com.simiacryptus.mindseye.test.ToleranceStatistics) Layer(com.simiacryptus.mindseye.lang.Layer) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipFile(java.util.zip.ZipFile) SerialPrecision(com.simiacryptus.mindseye.lang.SerialPrecision) NotebookOutput(com.simiacryptus.util.io.NotebookOutput) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) GsonBuilder(com.google.gson.GsonBuilder) Nonnull(javax.annotation.Nonnull) JsonObject(com.google.gson.JsonObject) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) Layer(com.simiacryptus.mindseye.lang.Layer) ZipFile(java.util.zip.ZipFile) JsonObject(com.google.gson.JsonObject) File(java.io.File) ZipFile(java.util.zip.ZipFile) Nullable(javax.annotation.Nullable)

Example 20 with NotebookOutput

use of com.simiacryptus.util.io.NotebookOutput in project MindsEye by SimiaCryptus.

the class StandardLayerTests method run.

/**
 * Test.
 *
 * @param log the log
 */
public void run(@Nonnull final NotebookOutput log) {
    long seed = (long) (Math.random() * Long.MAX_VALUE);
    int[][] smallDims = getSmallDims(new Random(seed));
    final Layer smallLayer = getLayer(smallDims, new Random(seed));
    int[][] largeDims = getLargeDims(new Random(seed));
    final Layer largeLayer = getLayer(largeDims, new Random(seed));
    try {
        if (smallLayer instanceof DAGNetwork) {
            try {
                log.h1("Network Diagram");
                log.p("This is a network apply the following layout:");
                log.code(() -> {
                    return Graphviz.fromGraph(TestUtil.toGraph((DAGNetwork) smallLayer)).height(400).width(600).render(Format.PNG).toImage();
                });
            } catch (Throwable e) {
                logger.info("Error plotting graph", e);
            }
        } else if (smallLayer instanceof Explodable) {
            try {
                Layer explode = ((Explodable) smallLayer).explode();
                if (explode instanceof DAGNetwork) {
                    log.h1("Exploded Network Diagram");
                    log.p("This is a network apply the following layout:");
                    @Nonnull DAGNetwork network = (DAGNetwork) explode;
                    log.code(() -> {
                        @Nonnull Graphviz graphviz = Graphviz.fromGraph(TestUtil.toGraph(network)).height(400).width(600);
                        @Nonnull File file = new File(log.getResourceDir(), log.getName() + "_network.svg");
                        graphviz.render(Format.SVG_STANDALONE).toFile(file);
                        log.link(file, "Saved to File");
                        return graphviz.render(Format.SVG).toString();
                    });
                }
            } catch (Throwable e) {
                logger.info("Error plotting graph", e);
            }
        }
        @Nonnull ArrayList<TestError> exceptions = standardTests(log, seed);
        if (!exceptions.isEmpty()) {
            if (smallLayer instanceof DAGNetwork) {
                for (@Nonnull Invocation invocation : getInvocations(smallLayer, smallDims)) {
                    log.h1("Small SubTests: " + invocation.getLayer().getClass().getSimpleName());
                    log.p(Arrays.deepToString(invocation.getDims()));
                    tests(log, getLittleTests(), invocation, exceptions);
                    invocation.freeRef();
                }
            }
            if (largeLayer instanceof DAGNetwork) {
                testEquivalency = false;
                for (@Nonnull Invocation invocation : getInvocations(largeLayer, largeDims)) {
                    log.h1("Large SubTests: " + invocation.getLayer().getClass().getSimpleName());
                    log.p(Arrays.deepToString(invocation.getDims()));
                    tests(log, getBigTests(), invocation, exceptions);
                    invocation.freeRef();
                }
            }
        }
        log.code(() -> {
            throwException(exceptions);
        });
    } finally {
        smallLayer.freeRef();
        largeLayer.freeRef();
    }
    getFinalTests().stream().filter(x -> null != x).forEach(test -> {
        final Layer perfLayer;
        perfLayer = getLayer(largeDims, new Random(seed));
        perfLayer.assertAlive();
        @Nonnull Layer copy;
        copy = perfLayer.copy();
        Tensor[] randomize = randomize(largeDims);
        try {
            test.test(log, copy, randomize);
        } finally {
            test.freeRef();
            for (@Nonnull Tensor tensor : randomize) {
                tensor.freeRef();
            }
            perfLayer.freeRef();
            copy.freeRef();
        }
    });
}
Also used : JsonObject(com.google.gson.JsonObject) Graphviz(guru.nidi.graphviz.engine.Graphviz) Arrays(java.util.Arrays) Tensor(com.simiacryptus.mindseye.lang.Tensor) ReferenceCountingBase(com.simiacryptus.mindseye.lang.ReferenceCountingBase) NotebookReportBase(com.simiacryptus.mindseye.test.NotebookReportBase) HashMap(java.util.HashMap) Random(java.util.Random) Result(com.simiacryptus.mindseye.lang.Result) DataSerializer(com.simiacryptus.mindseye.lang.DataSerializer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Format(guru.nidi.graphviz.engine.Format) Map(java.util.Map) Layer(com.simiacryptus.mindseye.lang.Layer) CudaError(com.simiacryptus.mindseye.lang.cudnn.CudaError) NotebookOutput(com.simiacryptus.util.io.NotebookOutput) ReferenceCounting(com.simiacryptus.mindseye.lang.ReferenceCounting) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) SysOutInterceptor(com.simiacryptus.util.test.SysOutInterceptor) Collection(java.util.Collection) TestUtil(com.simiacryptus.mindseye.test.TestUtil) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) LayerBase(com.simiacryptus.mindseye.lang.LayerBase) Explodable(com.simiacryptus.mindseye.layers.cudnn.Explodable) ToleranceStatistics(com.simiacryptus.mindseye.test.ToleranceStatistics) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) LifecycleException(com.simiacryptus.mindseye.lang.LifecycleException) Explodable(com.simiacryptus.mindseye.layers.cudnn.Explodable) Graphviz(guru.nidi.graphviz.engine.Graphviz) Tensor(com.simiacryptus.mindseye.lang.Tensor) Nonnull(javax.annotation.Nonnull) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) Layer(com.simiacryptus.mindseye.lang.Layer) Random(java.util.Random) File(java.io.File)

Aggregations

NotebookOutput (com.simiacryptus.util.io.NotebookOutput)48 Nonnull (javax.annotation.Nonnull)48 Tensor (com.simiacryptus.mindseye.lang.Tensor)46 Nullable (javax.annotation.Nullable)40 Layer (com.simiacryptus.mindseye.lang.Layer)39 Arrays (java.util.Arrays)38 List (java.util.List)37 IntStream (java.util.stream.IntStream)31 TestUtil (com.simiacryptus.mindseye.test.TestUtil)25 Logger (org.slf4j.Logger)25 LoggerFactory (org.slf4j.LoggerFactory)25 Stream (java.util.stream.Stream)23 Collectors (java.util.stream.Collectors)22 ArrayList (java.util.ArrayList)21 HashMap (java.util.HashMap)21 DAGNetwork (com.simiacryptus.mindseye.network.DAGNetwork)20 PipelineNetwork (com.simiacryptus.mindseye.network.PipelineNetwork)19 TrainingMonitor (com.simiacryptus.mindseye.opt.TrainingMonitor)19 TimeUnit (java.util.concurrent.TimeUnit)19 StepRecord (com.simiacryptus.mindseye.test.StepRecord)18