Search in sources :

Example 11 with DAGNode

use of com.simiacryptus.mindseye.network.DAGNode in project MindsEye by SimiaCryptus.

the class StochasticSamplingSubnetLayer method average.

/**
 * Average result.
 *
 * @param samples the samples
 * @return the result
 */
public static Result average(final Result[] samples) {
    PipelineNetwork gateNetwork = new PipelineNetwork(1);
    gateNetwork.wrap(new ProductLayer(), gateNetwork.getInput(0), gateNetwork.wrap(new ValueLayer(new Tensor(1, 1, 1).mapAndFree(v -> 1.0 / samples.length)), new DAGNode[] {}));
    SumInputsLayer sumInputsLayer = new SumInputsLayer();
    try {
        return gateNetwork.evalAndFree(sumInputsLayer.evalAndFree(samples));
    } finally {
        sumInputsLayer.freeRef();
        gateNetwork.freeRef();
    }
}
Also used : PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) IntStream(java.util.stream.IntStream) JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) CountingResult(com.simiacryptus.mindseye.network.CountingResult) SumInputsLayer(com.simiacryptus.mindseye.layers.cudnn.SumInputsLayer) Tensor(com.simiacryptus.mindseye.lang.Tensor) Random(java.util.Random) Result(com.simiacryptus.mindseye.lang.Result) DAGNode(com.simiacryptus.mindseye.network.DAGNode) DataSerializer(com.simiacryptus.mindseye.lang.DataSerializer) ArrayList(java.util.ArrayList) List(java.util.List) LayerBase(com.simiacryptus.mindseye.lang.LayerBase) ProductLayer(com.simiacryptus.mindseye.layers.cudnn.ProductLayer) Map(java.util.Map) Layer(com.simiacryptus.mindseye.lang.Layer) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ProductLayer(com.simiacryptus.mindseye.layers.cudnn.ProductLayer) Tensor(com.simiacryptus.mindseye.lang.Tensor) SumInputsLayer(com.simiacryptus.mindseye.layers.cudnn.SumInputsLayer) PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) DAGNode(com.simiacryptus.mindseye.network.DAGNode)

Example 12 with DAGNode

use of com.simiacryptus.mindseye.network.DAGNode in project MindsEye by SimiaCryptus.

the class StochasticSamplingSubnetLayer method average.

/**
 * Average result.
 *
 * @param samples   the samples
 * @param precision the precision
 * @return the result
 */
public static Result average(final Result[] samples, final Precision precision) {
    PipelineNetwork gateNetwork = new PipelineNetwork(1);
    gateNetwork.wrap(new ProductLayer().setPrecision(precision), gateNetwork.getInput(0), gateNetwork.wrap(new ValueLayer(new Tensor(1, 1, 1).mapAndFree(v -> 1.0 / samples.length)), new DAGNode[] {}));
    SumInputsLayer sumInputsLayer = new SumInputsLayer().setPrecision(precision);
    try {
        return gateNetwork.evalAndFree(sumInputsLayer.evalAndFree(samples));
    } finally {
        sumInputsLayer.freeRef();
        gateNetwork.freeRef();
    }
}
Also used : PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) IntStream(java.util.stream.IntStream) JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) StochasticComponent(com.simiacryptus.mindseye.layers.java.StochasticComponent) CountingResult(com.simiacryptus.mindseye.network.CountingResult) Tensor(com.simiacryptus.mindseye.lang.Tensor) Random(java.util.Random) WrapperLayer(com.simiacryptus.mindseye.layers.java.WrapperLayer) Result(com.simiacryptus.mindseye.lang.Result) ValueLayer(com.simiacryptus.mindseye.layers.java.ValueLayer) DAGNode(com.simiacryptus.mindseye.network.DAGNode) DataSerializer(com.simiacryptus.mindseye.lang.DataSerializer) Precision(com.simiacryptus.mindseye.lang.cudnn.Precision) Map(java.util.Map) Layer(com.simiacryptus.mindseye.lang.Layer) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Tensor(com.simiacryptus.mindseye.lang.Tensor) ValueLayer(com.simiacryptus.mindseye.layers.java.ValueLayer) PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) DAGNode(com.simiacryptus.mindseye.network.DAGNode)

Example 13 with DAGNode

use of com.simiacryptus.mindseye.network.DAGNode in project MindsEye by SimiaCryptus.

the class ExplodedConvolutionLeg method add.

/**
 * Add dag node.
 *
 * @param input the input
 * @return the dag node
 */
public DAGNode add(@Nonnull final DAGNode input) {
    assertAlive();
    DAGNetwork network = input.getNetwork();
    DAGNode head = input;
    final int[] filterDimensions = this.convolutionParams.masterFilterDimensions;
    if (getInputBands() == this.convolutionParams.outputBands) {
        assert 1 == subLayers.size();
        head = network.add(subLayers.get(0), head);
    } else {
        head = network.wrap(new ImgConcatLayer().setMaxBands(this.convolutionParams.outputBands).setPrecision(this.convolutionParams.precision).setParallel(CudaSettings.INSTANCE.isConv_para_2()), subLayers.stream().map(l -> network.add(l, input)).toArray(i -> new DAGNode[i])).setParallel(CudaSettings.INSTANCE.isConv_para_2());
    }
    return head;
}
Also used : PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) IntStream(java.util.stream.IntStream) Coordinate(com.simiacryptus.mindseye.lang.Coordinate) CudaSettings(com.simiacryptus.mindseye.lang.cudnn.CudaSettings) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Tensor(com.simiacryptus.mindseye.lang.Tensor) ReferenceCountingBase(com.simiacryptus.mindseye.lang.ReferenceCountingBase) DAGNode(com.simiacryptus.mindseye.network.DAGNode) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Delta(com.simiacryptus.mindseye.lang.Delta) Precision(com.simiacryptus.mindseye.lang.cudnn.Precision) List(java.util.List) Layer(com.simiacryptus.mindseye.lang.Layer) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) DeltaSet(com.simiacryptus.mindseye.lang.DeltaSet) Nonnull(javax.annotation.Nonnull) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) DAGNode(com.simiacryptus.mindseye.network.DAGNode)

Example 14 with DAGNode

use of com.simiacryptus.mindseye.network.DAGNode in project MindsEye by SimiaCryptus.

the class ExplodedConvolutionGrid method add.

/**
 * Add dag node.
 *
 * @param input the input
 * @return the dag node
 */
public DAGNode add(@Nonnull DAGNode input) {
    assertAlive();
    DAGNetwork network = input.getNetwork();
    int defaultPaddingX = 0;
    int defaultPaddingY = 0;
    boolean customPaddingX = this.convolutionParams.paddingX != null && convolutionParams.paddingX != defaultPaddingX;
    boolean customPaddingY = this.convolutionParams.paddingY != null && convolutionParams.paddingY != defaultPaddingY;
    final DAGNode paddedInput;
    if (customPaddingX || customPaddingY) {
        int x;
        if (this.convolutionParams.paddingX < -defaultPaddingX) {
            x = this.convolutionParams.paddingX + defaultPaddingX;
        } else if (this.convolutionParams.paddingX > defaultPaddingX) {
            x = this.convolutionParams.paddingX - defaultPaddingX;
        } else {
            x = 0;
        }
        int y;
        if (this.convolutionParams.paddingY < -defaultPaddingY) {
            y = this.convolutionParams.paddingY + defaultPaddingY;
        } else if (this.convolutionParams.paddingY > defaultPaddingY) {
            y = this.convolutionParams.paddingY - defaultPaddingY;
        } else {
            y = 0;
        }
        if (x != 0 || y != 0) {
            paddedInput = network.wrap(new ImgZeroPaddingLayer(x, y).setPrecision(convolutionParams.precision), input);
        } else {
            paddedInput = input;
        }
    } else {
        paddedInput = input;
    }
    InnerNode output;
    if (subLayers.size() == 1) {
        output = (InnerNode) subLayers.get(0).add(paddedInput);
    } else {
        ImgLinearSubnetLayer linearSubnetLayer = new ImgLinearSubnetLayer();
        subLayers.forEach(leg -> {
            PipelineNetwork subnet = new PipelineNetwork();
            leg.add(subnet.getHead());
            linearSubnetLayer.add(leg.fromBand, leg.toBand, subnet);
        });
        boolean isParallel = CudaSettings.INSTANCE.isConv_para_1();
        linearSubnetLayer.setPrecision(convolutionParams.precision).setParallel(isParallel);
        output = network.wrap(linearSubnetLayer, paddedInput).setParallel(isParallel);
    }
    if (customPaddingX || customPaddingY) {
        int x = !customPaddingX ? 0 : (this.convolutionParams.paddingX - defaultPaddingX);
        int y = !customPaddingY ? 0 : (this.convolutionParams.paddingY - defaultPaddingY);
        if (x > 0)
            x = 0;
        if (y > 0)
            y = 0;
        if (x != 0 || y != 0) {
            return network.wrap(new ImgZeroPaddingLayer(x, y).setPrecision(convolutionParams.precision), output);
        }
    }
    return output;
}
Also used : PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) DAGNode(com.simiacryptus.mindseye.network.DAGNode) InnerNode(com.simiacryptus.mindseye.network.InnerNode)

Example 15 with DAGNode

use of com.simiacryptus.mindseye.network.DAGNode in project MindsEye by SimiaCryptus.

the class StyleTransfer method fitnessNetwork.

/**
 * Fitness function pipeline network.
 *
 * @param setup the setup
 * @return the pipeline network
 */
@Nonnull
public PipelineNetwork fitnessNetwork(NeuralSetup setup) {
    PipelineNetwork pipelineNetwork = getInstance().getNetwork();
    Map<T, DAGNode> nodes = new HashMap<>();
    Map<T, UUID> ids = getInstance().getNodes();
    ids.forEach((l, id) -> nodes.put(l, pipelineNetwork.getChildNode(id)));
    PipelineNetwork network = buildNetwork(setup, nodes, pipelineNetwork);
    // network = withClamp(network);
    ArtistryUtil.setPrecision(network, setup.style.precision);
    return network;
}
Also used : HashMap(java.util.HashMap) PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) DAGNode(com.simiacryptus.mindseye.network.DAGNode) UUID(java.util.UUID) Nonnull(javax.annotation.Nonnull)

Aggregations

DAGNode (com.simiacryptus.mindseye.network.DAGNode)17 Nonnull (javax.annotation.Nonnull)14 PipelineNetwork (com.simiacryptus.mindseye.network.PipelineNetwork)11 ArrayList (java.util.ArrayList)9 Nullable (javax.annotation.Nullable)8 Tensor (com.simiacryptus.mindseye.lang.Tensor)6 DAGNetwork (com.simiacryptus.mindseye.network.DAGNetwork)6 JsonObject (com.google.gson.JsonObject)5 Layer (com.simiacryptus.mindseye.lang.Layer)5 Arrays (java.util.Arrays)5 List (java.util.List)5 IntStream (java.util.stream.IntStream)5 Result (com.simiacryptus.mindseye.lang.Result)4 Map (java.util.Map)4 DataSerializer (com.simiacryptus.mindseye.lang.DataSerializer)3 MeanSqLossLayer (com.simiacryptus.mindseye.layers.cudnn.MeanSqLossLayer)3 ValueLayer (com.simiacryptus.mindseye.layers.cudnn.ValueLayer)3 ArrayTrainable (com.simiacryptus.mindseye.eval.ArrayTrainable)2 LayerBase (com.simiacryptus.mindseye.lang.LayerBase)2 TensorList (com.simiacryptus.mindseye.lang.TensorList)2