public override void Execute(object parameter) { ITrainer trainer = Control.Trainer; trainer.Operator.WaitForStateChanged(); Control.Running = false; trainer.Reset(); trainer.Initialise(trainer.Operator.Handler); // because we're manually resetting we have to initialise manually as well // TODO maybe find a nicer way to reset and reinitialise - maybe separate command? }
private static void SampleNetworkArchitecture() { SigmaEnvironment sigma = SigmaEnvironment.Create("test"); IComputationHandler handler = new CpuFloat32Handler(); ITrainer trainer = sigma.CreateTrainer("test_trainer"); trainer.Network = new Network(); trainer.Network.Architecture = InputLayer.Construct(2, 2) + ElementwiseLayer.Construct(2 * 2) + FullyConnectedLayer.Construct(2) + 2 * (FullyConnectedLayer.Construct(4) + FullyConnectedLayer.Construct(2)) + OutputLayer.Construct(2); trainer.Network = (INetwork)trainer.Network.DeepCopy(); trainer.Operator = new CpuMultithreadedOperator(10); trainer.AddInitialiser("*.weights", new GaussianInitialiser(standardDeviation: 0.1f)); trainer.AddInitialiser("*.bias*", new GaussianInitialiser(standardDeviation: 0.01f, mean: 0.03f)); trainer.Initialise(handler); trainer.Network = (INetwork)trainer.Network.DeepCopy(); Console.WriteLine(trainer.Network.Registry); IRegistryResolver resolver = new RegistryResolver(trainer.Network.Registry); Console.WriteLine("==============="); object[] weights = resolver.ResolveGet <object>("layers.*.weights"); Console.WriteLine(string.Join("\n", weights)); Console.WriteLine("==============="); //foreach (ILayerBuffer buffer in trainer.Network.YieldLayerBuffersOrdered()) //{ // Console.WriteLine(buffer.Layer.Name + ": "); // Console.WriteLine("inputs:"); // foreach (string input in buffer.Inputs.Keys) // { // Console.WriteLine($"\t{input}: {buffer.Inputs[input].GetHashCode()}"); // } // Console.WriteLine("outputs:"); // foreach (string output in buffer.Outputs.Keys) // { // Console.WriteLine($"\t{output}: {buffer.Outputs[output].GetHashCode()}"); // } //} }
public static INetwork GenerateNetwork(double number) { if (_environment == null) { _environment = SigmaEnvironment.Create("TestAverageNetworkMergerEnvironment"); } ITrainer trainer = _environment.CreateTrainer($"trainer{_count++}"); Network net = new Network(); net.Architecture = InputLayer.Construct(2, 2) + FullyConnectedLayer.Construct(2 * 2) + OutputLayer.Construct(2); trainer.Network = net; trainer.AddInitialiser("*.weights", new ConstantValueInitialiser(number)); trainer.Operator = new CpuSinglethreadedOperator(); trainer.Initialise(new CpuFloat32Handler()); SigmaEnvironment.Clear(); return(net); }
/// <summary> /// The default item generation that will be called if no other title bar item is specified (i.e. <see cref="TitleBarFuncs"/> is empty). /// </summary> public virtual void InitialiseDefaultItems() { _log.Info("Creating default title bar items because no others have been specified."); AddSigmaFunction((app, window) => new TitleBarItem(Properties.Resources.ButtonEnvironment, Properties.Resources.MenuButtonLoad, (Action)(() => { SigmaEnvironment sigma = window.Monitor.Sigma; ITrainer activeTrainer = sigma.RunningOperatorsByTrainer.Keys.FirstOrDefault(); if (activeTrainer != null) { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Title = "Open Network"; fileDialog.Multiselect = false; fileDialog.Filter = "Sigma Network Files (*.sgnet)|*.sgnet"; fileDialog.InitialDirectory = new FileInfo(SigmaEnvironment.Globals.Get <string>("storage_path")).FullName; if (fileDialog.ShowDialog() == true) { try { INetwork network = Serialisation.Read <INetwork>(Target.FileByPath(fileDialog.FileName), Serialisers.BinarySerialiser, false); if (!Network.AreNetworkExternalsCompatible(network, activeTrainer.Network)) { throw new InvalidOperationException($"Unable to switch to network \"{network.Name}\" with incompatible internals (from {fileDialog.FileName})."); } activeTrainer.Reset(); bool forceInitialisationBefore = activeTrainer.ForceInitialisation; activeTrainer.ForceInitialisation = false; activeTrainer.Network = network; activeTrainer.Initialise(activeTrainer.Operator.Handler); activeTrainer.ForceInitialisation = forceInitialisationBefore; Task.Factory.StartNew(() => window.SnackbarMessageQueue.Enqueue( $"Switched network \"{network.Name}\", reset training (now using \"{fileDialog.FileName}\")", "Got it", null)); } catch (Exception e) { _log.Error($"Error while switching to network \"{fileDialog.FileName}\": {e.GetType()} ({e.Message})", e); } } } else { _log.Warn($"Unable to load new network because no trainer is active."); } }), Properties.Resources.MenuButtonSave, new TitleBarItem("Extras", "Extra1", "Extra2", new TitleBarItem("More", "Extra 3")))); #if DEBUG AddSigmaFunction((app, window) => new TitleBarItem(Properties.Resources.ButtonDebug, "5 second indeterminate task", (Action)(() => { new Thread(() => { ITaskObserver task = null; try { task = SigmaEnvironment.TaskManager.BeginTask(TaskType.Preprocess, "Indeterminate task"); Thread.Sleep(5000); } catch (Exception) { // ignore } finally { SigmaEnvironment.TaskManager.EndTask(task); } }).Start(); }), "Flood", (Action)(() => { ILog log = LogManager.GetLogger(typeof(TitleBarFactory)); new Thread(() => { for (int i = 1; i <= 1; i++) { log.Debug($"Flood {i}: debug"); log.Info($"Flood {i}: info"); log.Warn($"Flood {i}: warn"); log.Error($"Flood {i}: error"); log.Fatal($"Flood {i}: fatal"); } }).Start(); }), "Print Hierarchy", (Action)(() => { SigmaWindow root = window; while (!root.IsRoot) { root = root.ParentWindow; } PrintWindow(root); }) )); #endif AddSigmaFunction((app, window) => new TitleBarItem(Properties.Resources.ButtonSettings, new TitleBarItem(Properties.Resources.MenuButtonStyle, Properties.Resources.MenuButtonToggleDark, (Action)(() => window.Monitor.ColourManager.Dark = !window.Monitor.ColourManager.Dark), Properties.Resources.MenuButtonToggleAlternate, (Action)(() => window.Monitor.ColourManager.Alternate = !window.Monitor.ColourManager.Alternate) /*, * Properties.Resources.MenuButtonLanguage, (Action< Application, Window, TitleBarItem>) ((application, genericWindow, item) => * { * WPFMonitor monitor = window.Monitor; * monitor.UiCultureInfo = CultureInfo.GetCultureInfo("de-DE"); * monitor.Reload(); * })*/))); AddSigmaFunction((app, window) => { IUIFactory <UIElement> aboutFactory = (IUIFactory <UIElement>)Registry.TryGetValue(AboutFactoryIdentifier, () => new AboutFactory(window.DialogHost)); object aboutContent = aboutFactory.CreateElement(app, window); TitleBarItem about = new TitleBarItem(Properties.Resources.ButtonHelp, new TitleBarItem(Properties.Resources.MenuButtonAbout, (Action)(async() => { window.DialogHost.IsOpen = false; await DialogHost.Show(aboutContent, window.DialogHostIdentifier); }))); return(about); }); }