Here are the examples of the csharp api System.Func.Invoke(Variable) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4 Examples
19
Source : NP.CNTKHelper.cs
with MIT License
from KIWI-ST
with MIT License
from KIWI-ST
public static Function ConvolutionTranspose(
Variable input,
int[] filter_shape,
int num_filters,
DeviceDescriptor device,
Func<Variable, Function> activation = null,
bool use_padding =true,
int[] strides =null,
bool use_bias = true,
int[] output_shape=null,
int[] dilation = null,
uint max_temp_mem_size_in_samples = 0,
string name = "")
{
strides = strides?? new int[] { 1 };
var sharing = PadToShape(filter_shape, true);
var padding = PadToShape(filter_shape, use_padding);
padding = Concat(padding, new bool[] { false });
if (dilation == null)
dilation = PadToShape(filter_shape, 1);
var output_channels_shape = new int[] { num_filters };
var kernel_shape = Concat(filter_shape, output_channels_shape, new int[] { NDShape.InferredDimension });
var output_full_shape = output_shape;
if (output_full_shape != null)
output_full_shape = Concat(output_shape, output_channels_shape);
var filter_rank = filter_shape.Length;
var init = CNTKLib.GlorotUniformInitializer(CNTKLib.DefaultParamInitScale, CNTKLib.SentinelValueForInferParamInitRank, CNTKLib.SentinelValueForInferParamInitRank, 1);
var W = new Parameter(kernel_shape, DataType.Float, init, device, name = "W");
var r = CNTKLib.ConvolutionTranspose(
convolutionMap: W,
operand: input,
strides: strides,
sharing: new BoolVector(sharing),
autoPadding: new BoolVector(padding),
outputShape: output_full_shape,
dilation: dilation,
reductionRank: 1, // in this case, the reductionRank must be equals 1
maxTempMemSizeInSamples: max_temp_mem_size_in_samples);
if (use_bias)
{
var b_shape = Concat(Enumerable.Repeat(1, filter_shape.Length).ToArray(), output_channels_shape);
var b = new Parameter(b_shape, 0.0, device, "B");
r = CNTKLib.Plus(r, b);
}
if (activation != null)
r = activation(r);
return r;
}
19
Source : NP.CNTKHelper.cs
with MIT License
from KIWI-ST
with MIT License
from KIWI-ST
public static Function ConvolutionWithMaxPooling(
Variable input,
int kernelWidth,
int kernelHeight,
int inputChannel,
int outputChannel,
int hStride, int vStride,
int poolingWindowWidth,
int poolingWindowHeight,
DeviceDescriptor device,
Func<Variable, Function> activation = null,
string outputName = "")
{
float convWScale = 0.26f;
var W = new Parameter(
new int[] { kernelWidth, kernelHeight, inputChannel, outputChannel },
DataType.Float,
CNTKLib.GlorotUniformInitializer(convWScale, -1, 2),
device);
Function y = CNTKLib.Convolution(W, input, new int[] { 1, 1, inputChannel });
y = activation != null ? activation(y) : y;
//pooling
y = CNTKLib.Pooling(y,
PoolingType.Max,
new int[] { poolingWindowWidth, poolingWindowHeight },
new int[] { hStride, vStride },
new bool[] { true });
return y;
}
19
Source : NP.CNTKHelper.cs
with MIT License
from KIWI-ST
with MIT License
from KIWI-ST
public static Function Dense(Variable input, int outputDim, DeviceDescriptor device, Func<Variable, Function> activation = null, string outputName = "")
{
if (input.Shape.Rank != 1)
{
int reshapeDim = input.Shape.Dimensions.Aggregate((d1, d2) => d1 * d2);
input = CNTKLib.Reshape(input, new int[] { reshapeDim });
}
Function fc = FullyConnectedLinearLayer(input, outputDim, device, outputName);
fc = activation != null ? activation(fc) : fc;
return fc;
}
19
Source : VariableEditor.cs
with Apache License 2.0
from marcosecchi
with Apache License 2.0
from marcosecchi
public static void VariableField(SerializedProperty property,
GUIContent label,
Flowchart flowchart,
string defaultText,
Func<Variable, bool> filter,
Func<string, int, string[], int> drawer = null)
{
List<string> variableKeys = new List<string>();
List<Variable> variableObjects = new List<Variable>();
variableKeys.Add(defaultText);
variableObjects.Add(null);
List<Variable> variables = flowchart.Variables;
int index = 0;
int selectedIndex = 0;
Variable selectedVariable = property.objectReferenceValue as Variable;
// When there are multiple Flowcharts in a scene with variables, switching
// between the Flowcharts can cause the wrong variable property
// to be inspected for a single frame. This has the effect of causing private
// variable references to be set to null when inspected. When this condition
// occurs we just skip displaying the property for this frame.
if (selectedVariable != null &&
selectedVariable.gameObject != flowchart.gameObject &&
selectedVariable.Scope == VariableScope.Private)
{
property.objectReferenceValue = null;
return;
}
foreach (Variable v in variables)
{
if (filter != null)
{
if (!filter(v))
{
continue;
}
}
variableKeys.Add(v.Key);
variableObjects.Add(v);
index++;
if (v == selectedVariable)
{
selectedIndex = index;
}
}
Flowchart[] fsList = GameObject.FindObjectsOfType<Flowchart>();
foreach (Flowchart fs in fsList)
{
if (fs == flowchart)
{
continue;
}
List<Variable> publicVars = fs.GetPublicVariables();
foreach (Variable v in publicVars)
{
if (filter != null)
{
if (!filter(v))
{
continue;
}
}
variableKeys.Add(fs.name + " / " + v.Key);
variableObjects.Add(v);
index++;
if (v == selectedVariable)
{
selectedIndex = index;
}
}
}
if (drawer == null)
{
selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray());
}
else
{
selectedIndex = drawer(label.text, selectedIndex, variableKeys.ToArray());
}
property.objectReferenceValue = variableObjects[selectedIndex];
}