Exemplo n.º 1
0
        /// <inheritdoc />
        protected override void Then(TrainingWindow window)
        {
            ICourse  result       = ExtractTraining(window);
            IChapter firstChapter = result.Data.Chapters.First();

            // The chapter exits
            Assert.NotNull(firstChapter);

            // The step exits
            IStep firstStep = firstChapter.Data.FirstStep;

            Assert.NotNull(firstChapter);

            IList <ITransition> transitions = GetTransitionsFromStep(firstStep);

            // It has two transition.
            Assert.That(transitions.Count == 2);

            ITransition firstTransition  = transitions[0];
            ITransition secondTransition = transitions[1];
            IStep       nextStep;

            // The first step's transition points to itself.
            if (TryToGetStepFromTransition(firstTransition, out nextStep))
            {
                Assert.That(firstStep == nextStep);
            }

            // The second step's transition is the end of the course.
            Assert.False(TryToGetStepFromTransition(secondTransition, out nextStep));
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        protected override void Then(TrainingWindow window)
        {
            ICourse result = ExtractTraining(window);

            IChapter firstChapter = result.Data.Chapters.First();

            Assert.NotNull(firstChapter);

            IStep firstStep = firstChapter.Data.FirstStep;

            Assert.NotNull(firstStep);

            IList <ITransition> transitions = GetTransitionsFromStep(firstStep);

            Assert.That(transitions.Count == 1);

            IStep nextStep;

            if (TryToGetStepFromTransition(transitions.First(), out nextStep))
            {
                Assert.Fail("First step is not the end of the chapter.");
            }

            Assert.Null(nextStep);
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        protected override TrainingWindow Given()
        {
            TrainingWindow window = base.Given();

            iteratedSteps = 0;

            return(window);
        }
        public void OnClickedTrainWindowButton()
        {
            this.ModelNotLoaded = false;
            TrainingViewModel   = new TrainingWindowViewModel(ref NeuralNetwork);
            TrainingWindow trainWindow = new TrainingWindow(TrainingViewModel);

            trainWindow.ShowDialog();
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        protected override void Then(TrainingWindow window)
        {
            ICourse  result       = ExtractTraining(window);
            IChapter firstChapter = result.Data.Chapters.First();

            Assert.NotNull(firstChapter);

            IStep         firstStep = firstChapter.Data.FirstStep;
            IList <IStep> steps     = firstChapter.Data.Steps;

            validatedSteps.Clear();
            ValidateLinearCourse(firstStep);

            Assert.That(iteratedSteps == steps.Count);
        }
Exemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        UpdateSelectedConfigurationName();
        UpdateSelectedCoursePath();

        selectedConfigurationIndex    = EditorGUILayout.Popup("Configuration", selectedConfigurationIndex, shortConfigurationTypeNames);
        configurationName.stringValue = configurationTypeNames[selectedConfigurationIndex];

        selectedCourseIndex = EditorGUILayout.Popup("Selected Training Course", selectedCourseIndex, trainingCourseDisplayNames);

        if (trainingCourseStreamingAssetsPaths.Length > 0)
        {
            selectedCourseStreamingAssetsPath.stringValue = trainingCourseStreamingAssetsPaths[selectedCourseIndex];
        }

        EditorGUI.BeginDisabledGroup(IsCourseListEmpty());
        {
            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Open course in Workflow Editor"))
                {
                    TrainingWindow trainingWindow = TrainingWindow.GetWindow();

                    trainingWindow.LoadTrainingCourseFromFile(GetSelectedCourseAbsolutePath());

                    trainingWindow.Focus();
                }

                if (GUILayout.Button(new GUIContent("Show course folder in Explorer...", Path.GetDirectoryName(GetSelectedCourseAbsolutePath()))))
                {
                    EditorUtility.RevealInFinder(Path.GetDirectoryName(GetSelectedCourseAbsolutePath()));
                }
            }
            GUILayout.EndHorizontal();
        }
        EditorGUI.EndDisabledGroup();

        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 7
0
        public MainWindow()
        {
            //Static MainWindow
            mMainWindow = this;
            //Windows.main = this;
            DataContext = BindMngr;

            loadingScreen.Show();
            InitializeComponent();

            mTrainingWindow = new TrainingWindow();

            // Setup background worker
            PreviewRoutine.previewSetup();
            ConnectRoutine.connectionSetup();
            ImageResizing.ImageResizingSetup();
            ResNet.CNTK_ResNetSetup();
            ZxingDecoder.DecoderSetup();
            mTrainingWindow.TrainModelRoutineSetup();

            OCR.OCRSetup(OCRMode.NUMBERS);

            // Create Directories
            GV.ML_Folders[(int)MLFolders.MLRoot]           = Environment.CurrentDirectory + MLFolders.MLRoot.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_CNTK]          = Environment.CurrentDirectory + MLFolders.ML_CNTK.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_CNTK_model]    = Environment.CurrentDirectory + MLFolders.ML_CNTK_model.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_YOLO]          = Environment.CurrentDirectory + MLFolders.ML_YOLO.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_YOLO_backup]   = Environment.CurrentDirectory + MLFolders.ML_YOLO_backup.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_YOLO_model]    = Environment.CurrentDirectory + MLFolders.ML_YOLO_model.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_YOLO_data]     = Environment.CurrentDirectory + MLFolders.ML_YOLO_data.GetDescription();
            GV.ML_Folders[(int)MLFolders.ML_YOLO_data_img] = Environment.CurrentDirectory + MLFolders.ML_YOLO_data_img.GetDescription();

            foreach (string str in GV.ML_Folders)
            {
                if (str != null && !Directory.Exists(str))
                {
                    Directory.CreateDirectory(str);
                }
            }
        }
Exemplo n.º 8
0
        /// <inheritdoc />
        protected override void Then(TrainingWindow window)
        {
            ICourse result = ExtractTraining(window);

            IChapter firstChapter = result.Data.Chapters.First();

            Assert.NotNull(firstChapter);

            IStep firstStep = firstChapter.Data.FirstStep;

            Assert.NotNull(firstStep);

            IList <ITransition> transitions = GetTransitionsFromStep(firstStep);

            Assert.That(transitions.Count == 2);

            foreach (ITransition transition in transitions)
            {
                IStep nextStep;

                if (TryToGetStepFromTransition(transition, out nextStep) == false)
                {
                    Assert.Fail("First step does not always go to another step.");
                }

                IList <ITransition> transitionsFromNextStep = GetTransitionsFromStep(nextStep);
                Assert.That(transitionsFromNextStep.Count == 1);

                IStep endOfChapter;

                if (TryToGetStepFromTransition(transitionsFromNextStep.First(), out endOfChapter))
                {
                    Assert.Fail("Branched step is not the end of the chapter.");
                }
            }
        }
Exemplo n.º 9
0
 private void open_TrainingWindow(object sender, RoutedEventArgs e)
 {
     GlobalVariable.messageQueueInterval = 15;
     trainingWindow = new TrainingWindow();
     trainingWindow.Show();
 }
Exemplo n.º 10
0
        private void EnterMovesButton_Click(object sender, RoutedEventArgs e)
        {
            var trainingWindow = new TrainingWindow();

            trainingWindow.ShowDialog();
        }
        public DeepQLearn(int num_states, int num_actions, TrainingOptions opt)
        {
            this.util = new Util();
            this.opt  = opt;

            // in number of time steps, of temporal memory
            // the ACTUAL input to the net will be (x,a) temporal_window times, and followed by current x
            // so to have no information from previous time step going into value function, set to 0.
            this.temporal_window = opt.temporal_window != int.MinValue ? opt.temporal_window : 1;
            // size of experience replay memory
            this.experience_size = opt.experience_size != int.MinValue ? opt.experience_size : 30000;
            // number of examples in experience replay memory before we begin learning
            this.start_learn_threshold = opt.start_learn_threshold != double.MinValue ? opt.start_learn_threshold : Math.Floor(Math.Min(this.experience_size * 0.1, 1000));
            // gamma is a crucial parameter that controls how much plan-ahead the agent does. In [0,1]
            this.gamma = opt.gamma != double.MinValue ? opt.gamma : 0.8;

            // number of steps we will learn for
            this.learning_steps_total = opt.learning_steps_total != int.MinValue ? opt.learning_steps_total : 100000;
            // how many steps of the above to perform only random actions (in the beginning)?
            this.learning_steps_burnin = opt.learning_steps_burnin != int.MinValue ? opt.learning_steps_burnin : 3000;
            // what epsilon value do we bottom out on? 0.0 => purely deterministic policy at end
            this.epsilon_min = opt.epsilon_min != double.MinValue ? opt.epsilon_min : 0.05;
            // what epsilon to use at test time? (i.e. when learning is disabled)
            this.epsilon_test_time = opt.epsilon_test_time != double.MinValue ? opt.epsilon_test_time : 0.00;

            // advanced feature. Sometimes a random action should be biased towards some values
            // for example in flappy bird, we may want to choose to not flap more often
            if (opt.random_action_distribution != null)
            {
                // this better sum to 1 by the way, and be of length this.num_actions
                this.random_action_distribution = opt.random_action_distribution;
                if (this.random_action_distribution.Count != num_actions)
                {
                    Console.WriteLine("TROUBLE. random_action_distribution should be same length as num_actions.");
                }

                var sum_of_dist = this.random_action_distribution.Sum();
                if (Math.Abs(sum_of_dist - 1.0) > 0.0001)
                {
                    Console.WriteLine("TROUBLE. random_action_distribution should sum to 1!");
                }
            }
            else
            {
                this.random_action_distribution = new List <double>();
            }

            // states that go into neural net to predict optimal action look as
            // x0,a0,x1,a1,x2,a2,...xt
            // this variable controls the size of that temporal window. Actions are
            // encoded as 1-of-k hot vectors
            this.net_inputs    = num_states * this.temporal_window + num_actions * this.temporal_window + num_states;
            this.num_states    = num_states;
            this.num_actions   = num_actions;
            this.window_size   = Math.Max(this.temporal_window, 2); // must be at least 2, but if we want more context even more
            this.state_window  = new List <Volume>();
            this.action_window = new List <int>();
            this.reward_window = new List <double>();
            this.net_window    = new List <double[]>();

            // Init wth dummy data
            for (int i = 0; i < window_size; i++)
            {
                this.state_window.Add(new Volume(1, 1, 1));
            }
            for (int i = 0; i < window_size; i++)
            {
                this.action_window.Add(0);
            }
            for (int i = 0; i < window_size; i++)
            {
                this.reward_window.Add(0.0);
            }
            for (int i = 0; i < window_size; i++)
            {
                this.net_window.Add(new double[] { 0.0 });
            }

            // create [state -> value of all possible actions] modeling net for the value function
            var layer_defs = new List <LayerDefinition>();

            if (opt.layer_defs != null)
            {
                // this is an advanced usage feature, because size of the input to the network, and number of
                // actions must check out. This is not very pretty Object Oriented programming but I can't see
                // a way out of it :(
                layer_defs = opt.layer_defs;
                if (layer_defs.Count < 2)
                {
                    Console.WriteLine("TROUBLE! must have at least 2 layers");
                }
                if (layer_defs[0].type != "input")
                {
                    Console.WriteLine("TROUBLE! first layer must be input layer!");
                }
                if (layer_defs[layer_defs.Count - 1].type != "regression")
                {
                    Console.WriteLine("TROUBLE! last layer must be input regression!");
                }
                if (layer_defs[0].out_depth * layer_defs[0].out_sx * layer_defs[0].out_sy != this.net_inputs)
                {
                    Console.WriteLine("TROUBLE! Number of inputs must be num_states * temporal_window + num_actions * temporal_window + num_states!");
                }
                if (layer_defs[layer_defs.Count - 1].num_neurons != this.num_actions)
                {
                    Console.WriteLine("TROUBLE! Number of regression neurons should be num_actions!");
                }
            }
            else
            {
                // create a very simple neural net by default
                layer_defs.Add(new LayerDefinition {
                    type = "input", out_sx = 1, out_sy = 1, out_depth = this.net_inputs
                });
                if (opt.hidden_layer_sizes != null)
                {
                    // allow user to specify this via the option, for convenience
                    var hl = opt.hidden_layer_sizes;
                    for (var k = 0; k < hl.Length; k++)
                    {
                        layer_defs.Add(new LayerDefinition {
                            type = "fc", num_neurons = hl[k], activation = "relu"
                        });                                                                                            // relu by default
                    }
                }
            }

            // Create the network
            this.value_net = new Net();
            this.value_net.makeLayers(layer_defs);

            // and finally we need a Temporal Difference Learning trainer!
            var options = new Options {
                learning_rate = 0.01, momentum = 0.0, batch_size = 64, l2_decay = 0.01
            };

            if (opt.options != null)
            {
                options = opt.options; // allow user to overwrite this
            }

            this.tdtrainer = new Trainer(this.value_net, options);

            // experience replay
            this.experience = new List <Experience>();
            //DeepQLearn.experienceShared = new List<ExperienceShared>(); // static list not threadsafe
            DeepQLearn.experienceShared = new ConcurrentDictionary <int, ExperienceShared>();

            // various housekeeping variables
            this.age            = 0;   // incremented every backward()
            this.forward_passes = 0;   // incremented every forward()
            this.epsilon        = 1.0; // controls exploration exploitation tradeoff. Should be annealed over time
            this.latest_reward  = 0;
            //this.last_input = [];
            this.average_reward_window = new TrainingWindow(1000, 10);
            this.average_loss_window   = new TrainingWindow(1000, 10);
            this.learning = true;
        }
Exemplo n.º 12
0
        /// <inheritdoc />
        protected override TrainingWindow Given()
        {
            TrainingWindow window = base.Given();

            return(window);
        }