Example #1
0
        public object eval(Tensor tensor)
        {
            log(new { tensor });

            CNTKTensor _tensor  = In(tensor);
            Variable   variable = _tensor.function;
            var        inputs   = new Dictionary <Variable, Value>();
            var        outputs  = new Dictionary <Variable, Value>()
            {
                { variable, null }
            };

            _tensor.function.Evaluate(inputs, outputs, DeviceDescriptor.CPUDevice);
            Value value = outputs[variable];
            var   shape = value.Shape;

            IEnumerable <IEnumerable <double> > r =
                value.GetDenseData <double>(_tensor.function);

            if (value.DataType == CNTKDataType.Double)
            {
                return(Out <double>(variable, value, shape));
            }
            if (value.DataType == CNTKDataType.Float)
            {
                return(Out <float>(variable, value, shape));
            }
            throw new InvalidOperationException();
        }
Example #2
0
        public Tensor bias_add(Tensor output, Tensor bias)
        {
            CNTKTensor _x     = In(output);
            CNTKTensor _b     = In(bias);
            var        _shape = In(_x.CNTK_Shape).Select(x => x < 0 ? 1 : x).ToArray();

            var shape = NDShape.CreateNDShape(_shape);

            var b = C.Reshape(_b, shape);

            return(Out(new Variable(_x.function) + b));
        }
Example #3
0
        public Tensor bias_add(Tensor output, Tensor bias, DataFormatType?data_format = null, string name = null)
        {
            if (data_format != null)
            {
                throw new NotImplementedException();
            }

            using (this.name_scope("bias_add"))
            {
                CNTKTensor _x     = In(output);
                CNTKTensor _b     = In(bias);
                var        _shape = In(_x.CNTK_Shape).Select(x => x < 0 ? 1 : x).ToArray();

                var shape = NDShape.CreateNDShape(_shape);

                var b = C.Reshape(_b, shape);

                return(Out(new Variable(_x.function) + b));
            }
        }