public DropoutLayer(DropoutLayerConfig config) : base(config) { this.config = config; dropoutRatio = config.DropoutRatio; mask = new bool[LayerSize]; rnd = new Random(); }
public static DropoutLayer Load(BinaryReader br, LayerType layerType) { DropoutLayer dropoutLayer; DropoutLayerConfig config = new DropoutLayerConfig(); SimpleLayer simpleLayer = SimpleLayer.Load(br, layerType); config.DropoutRatio = br.ReadSingle(); config.LayerSize = simpleLayer.LayerSize; dropoutLayer = new DropoutLayer(config); dropoutLayer.SparseFeatureSize = simpleLayer.SparseFeatureSize; dropoutLayer.DenseFeatureSize = simpleLayer.DenseFeatureSize; if (dropoutLayer.SparseFeatureSize > 0) { dropoutLayer.SparseWeights = simpleLayer.SparseWeights; } if (dropoutLayer.DenseFeatureSize > 0) { dropoutLayer.DenseWeights = simpleLayer.DenseWeights; } return(dropoutLayer); }
private void SetHiddenLayers() { //Get hidden layer settings //Example: LSTM:200, Dropout:0.5 HiddenLayersConfig = new List <LayerConfig>(); var hiddenLayers = config.GetValueRequired(HIDDEN_LAYER); foreach (var layer in hiddenLayers.Split(',')) { var items = layer.Split(':'); var sLayerType = items[0].Trim(); var layerType = LayerType.None; foreach ( var type in Enum.GetValues(typeof(LayerType)) .Cast <LayerType>() .Where( type => sLayerType.Equals(type.ToString(), StringComparison.InvariantCultureIgnoreCase)) ) { layerType = type; break; } LayerConfig baseLayerConfig; switch (layerType) { case LayerType.LSTM: { var layerConfig = new LSTMLayerConfig(); layerConfig.LayerSize = int.Parse(items[1]); layerConfig.LayerType = layerType; baseLayerConfig = layerConfig; Logger.WriteLine($"Initialize configuration for LSTM layer. Layer size = {layerConfig.LayerSize}"); } break; case LayerType.DropOut: { var layerConfig = new DropoutLayerConfig { DropoutRatio = float.Parse(items[1]) }; layerConfig.LayerSize = (NetworkType == NETWORKTYPE.BiDirectional) ? HiddenLayersConfig[HiddenLayersConfig.Count - 1].LayerSize * 2 : HiddenLayersConfig[HiddenLayersConfig.Count - 1].LayerSize; layerConfig.LayerType = layerType; baseLayerConfig = layerConfig; Logger.WriteLine( $"Initialize configuration for Dropout layer. Dropout ratio = '{layerConfig.DropoutRatio}'"); } break; default: throw new ArgumentException($"Invalidated layer type: {sLayerType}"); } HiddenLayersConfig.Add(baseLayerConfig); } Logger.WriteLine($"Hidden layer : {HiddenLayersConfig.Count}"); Logger.WriteLine($"Hidden layer : {hiddenLayers}"); }
public override void Load(BinaryReader br, LayerType layerType, bool forTraining = false) { config = new DropoutLayerConfig(); config.LayerSize = br.ReadInt32(); mask = new bool[LayerSize]; rnd = new Random(); int sparseFeatureSize = br.ReadInt32(); int denseFeatureSize = br.ReadInt32(); config.DropoutRatio = br.ReadSingle(); InitializeWeights(sparseFeatureSize, denseFeatureSize); if (forTraining) { InitializeInternalTrainingParameters(); } }
public DropoutLayer(DropoutLayerConfig config) : base(config) { dropoutRatio = config.DropoutRatio; rnd = new Random(); }
private void SetHiddenLayers() { //Get hidden layer settings HiddenLayersConfig = new List <LayerConfig>(); var hiddenLayers = config.GetValueRequired(HIDDEN_LAYER); foreach (var layer in hiddenLayers.Split(',')) { var items = layer.Split(':'); var sLayerSize = items[0].Trim(); var sLayerType = items[1].Trim(); //Parse layer size and type var layerSize = int.Parse(sLayerSize); var layerType = LayerType.None; foreach ( var type in Enum.GetValues(typeof(LayerType)) .Cast <LayerType>() .Where( type => sLayerType.Equals(type.ToString(), StringComparison.InvariantCultureIgnoreCase)) ) { layerType = type; break; } LayerConfig baseLayerConfig; switch (layerType) { case LayerType.LSTM: { var layerConfig = new LSTMLayerConfig(); baseLayerConfig = layerConfig; Logger.WriteLine("Initialize configuration for LSTM layer."); } break; case LayerType.BPTT: { if (items.Length != 3) { throw new ArgumentException( $"Invalidated settings for BPTT: {layer}, it should be [size:BPTT:bptt_value], such as [200:BPTT:5] ."); } var layerConfig = new BPTTLayerConfig { Bptt = int.Parse(items[2]) }; baseLayerConfig = layerConfig; Logger.WriteLine($"Initialize configuration for BPTT layer. BPTT = '{layerConfig.Bptt}'"); } break; case LayerType.DropOut: { var layerConfig = new DropoutLayerConfig { DropoutRatio = float.Parse(items[2]) }; baseLayerConfig = layerConfig; Logger.WriteLine( $"Initialize configuration for Dropout layer. Dropout ratio = '{layerConfig.DropoutRatio}'"); } break; default: throw new ArgumentException($"Invalidated layer type: {sLayerType}"); } baseLayerConfig.LayerType = layerType; baseLayerConfig.LayerSize = layerSize; HiddenLayersConfig.Add(baseLayerConfig); } Logger.WriteLine($"Hidden layer : {HiddenLayersConfig.Count}"); Logger.WriteLine($"Hidden layer : {hiddenLayers}"); }