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();
}
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations