示例#1
0
        public ExpressionSampler(string name, Variable expression, Variable inputVariable = null, int minibatchSize = 1, Value initialValue = null, int iterationsPerEpoch = int.MaxValue)
        {
            Name          = name;
            Expression    = expression;
            InputVariable = inputVariable;
            MinibatchSize = minibatchSize;

            _initialValue = initialValue;

            if (initialValue != null)
            {
                PrevValue = initialValue;
            }
            else
            {
                if (InputVariable != null)
                {
                    var shape         = expression.Shape;
                    var initialBuffer = new float[shape.TotalSize * minibatchSize];

                    var dims = new int[shape.Rank + 1];
                    shape.Dimensions.CopyTo(dims, 0);
                    dims[shape.Rank] = minibatchSize;

                    PrevValue = new Value(NDArrayViewMethods.SafeCreate(dims, initialBuffer, DeviceDescriptor.UseDefaultDevice()));
                }
            }

            IterationsPerEpoch = iterationsPerEpoch;

            Iterations = 0;
        }
示例#2
0
        public static CNTK.NDArrayView ArrayToNDArrayView(float[] data, int[] dimensions, CNTK.DeviceDescriptor device = null)
        {
            if (device == null)
            {
                device = CNTK.DeviceDescriptor.UseDefaultDevice();
            }

            return(NDArrayViewMethods.SafeCreate(dimensions, data, device));
        }
示例#3
0
        protected override void EndProcessing()
        {
            Constant result;

            if (InitialValue.Length == 1)
            {
                result = Constant.Scalar(DataType, InitialValue[0]);
            }
            else
            {
                if (Dimensions == null)
                {
                    Dimensions = new int[] { InitialValue.Length }
                }
                ;

                var array = NDArrayViewMethods.SafeCreate(Dimensions, InitialValue, Device);
                result = new Constant(array, Name);
            }

            WriteObject(new WrappedVariable(result));
        }
    }