Esempio n. 1
0
        private unsafe LearningModelBinding EvaluateContrastAndBrightnessSession(object input, object output)
        {
            var slope      = Math.Tan(ContrastMaxSlider.Value * 3.14159 / 2);
            var yintercept = -255 * (ContrastMinSlider.Value * 2 - 1);

            if (yintercept < 0)
            {
                // it was the x-intercept
                yintercept = slope * yintercept;
            }

            var binding = new LearningModelBinding(contrastEffectSession_);

            binding.Bind("Input", input);
            binding.Bind("Slope", TensorFloat.CreateFromArray(new long[] { 1 }, new float[] { (float)slope }));
            binding.Bind("YIntercept", TensorFloat.CreateFromArray(new long[] { 1 }, new float[] { (float)yintercept }));

            var outputBindProperties = new PropertySet();

            outputBindProperties.Add("DisableTensorCpuSync", PropertyValue.CreateBoolean(true));
            binding.Bind("Output", output, outputBindProperties);

            EvaluateInternal(contrastEffectSession_, binding);

            return(binding);
        }
        public void SaveState()
        {
            IPropertySet state = ApplicationData.Current.LocalSettings.Values;

            if (state.ContainsKey(AngleKey))
            {
                state.Remove(AngleKey);
            }
            if (state.ContainsKey(TrackingKey))
            {
                state.Remove(TrackingKey);
            }

            state.Add(AngleKey, PropertyValue.CreateSingle(_rotationY));
            state.Add(TrackingKey, PropertyValue.CreateBoolean(_tracking));
        }
Esempio n. 3
0
        private LearningModelBinding Evaluate(LearningModelSession session, object input, object output, bool wait = false)
        {
            // Create the binding
            var binding = new LearningModelBinding(session);

            // Bind inputs and outputs
            string inputName  = session.Model.InputFeatures[0].Name;
            string outputName = session.Model.OutputFeatures[0].Name;

            binding.Bind(inputName, input);

            var outputBindProperties = new PropertySet();

            outputBindProperties.Add("DisableTensorCpuSync", PropertyValue.CreateBoolean(true));
            binding.Bind(outputName, output, outputBindProperties);

            // Evaluate
            EvaluateInternal(session, binding, wait);

            return(binding);
        }
Esempio n. 4
0
        public static object Parse(AppDataType.Type type, string s)
        {
            object obj = null;

            switch (type)
            {
            case AppDataType.Type.Empty: obj = PropertyValue.CreateEmpty();; break;

            case AppDataType.Type.UInt8: obj = PropertyValue.CreateUInt8(s.IsEmpty() ? (byte)0 : Byte.Parse(s)); break;

            case AppDataType.Type.Int16: obj = PropertyValue.CreateInt16(s.IsEmpty() ? (short)0 : Int16.Parse(s)); break;

            case AppDataType.Type.UInt16: obj = PropertyValue.CreateUInt16(s.IsEmpty() ? (ushort)0 : UInt16.Parse(s)); break;

            case AppDataType.Type.Int32: obj = PropertyValue.CreateInt32(s.IsEmpty() ? 0 : Int32.Parse(s)); break;

            case AppDataType.Type.UInt32: obj = PropertyValue.CreateUInt32(s.IsEmpty() ? 0 : UInt32.Parse(s)); break;

            case AppDataType.Type.Int64: obj = PropertyValue.CreateInt64(s.IsEmpty() ? 0 : Int64.Parse(s)); break;

            case AppDataType.Type.UInt64: obj = PropertyValue.CreateUInt64(s.IsEmpty() ? 0 : UInt64.Parse(s)); break;

            case AppDataType.Type.Single: obj = PropertyValue.CreateSingle(s.IsEmpty() ? 0 : Single.Parse(s)); break;

            case AppDataType.Type.Double: obj = PropertyValue.CreateDouble(s.IsEmpty() ? 0 : Double.Parse(s)); break;

            case AppDataType.Type.Char16: obj = PropertyValue.CreateChar16(Char.Parse(s)); break;

            case AppDataType.Type.Boolean: obj = PropertyValue.CreateBoolean(s.IsEmpty() ? false : Boolean.Parse(s)); break;

            case AppDataType.Type.String: obj = s; break;

            default: break;
            }
            return(obj);
        }
        private static LearningModelEvaluationResult Evaluate(LearningModelSession session, object input)
        {
            // Create the binding
            var binding = new LearningModelBinding(session);

            // Create an empty output, that will keep the output resources on the GPU
            // It will be chained into a the post processing on the GPU as well
            var output = TensorFloat.Create();

            // Bind inputs and outputs
            // For squeezenet these evaluate to "data", and "squeezenet0_flatten0_reshape0"
            string inputName  = session.Model.InputFeatures[0].Name;
            string outputName = session.Model.OutputFeatures[0].Name;

            binding.Bind(inputName, input);

            var outputBindProperties = new PropertySet();

            outputBindProperties.Add("DisableTensorCpuSync", PropertyValue.CreateBoolean(true));
            binding.Bind(outputName, output, outputBindProperties);

            // Evaluate
            return(session.Evaluate(binding, ""));
        }