public layer_description(LAYERTYPE Layer_type, int Start_neurons_num,
                          int Adding_neurons_num = 0, int Dropout_perc = 0, float Neurons_adding_timewait = 1f)
 {
     layer_type              = Layer_type;
     start_neurons_num       = Start_neurons_num;
     adding_neurons_num      = Adding_neurons_num;
     dropout_perc            = Dropout_perc;
     neurons_adding_timewait = Neurons_adding_timewait;
 }
Esempio n. 2
0
        public static void CheckModelFileType(string filename, out MODELDIRECTION modelDir, out MODELTYPE modelType)
        {
            using (StreamReader sr = new StreamReader(filename))
            {
                BinaryReader br        = new BinaryReader(sr.BaseStream);
                LAYERTYPE    layerType = (LAYERTYPE)br.ReadInt32();
                modelDir  = (MODELDIRECTION)br.ReadInt32();
                modelType = (MODELTYPE)br.ReadInt32();

                Logger.WriteLine("Model information:");
                Logger.WriteLine("File name : '{0}'", filename);
                Logger.WriteLine("Direction: '{0}'", modelDir);
                Logger.WriteLine("Model type: '{0}'", modelType);
                Logger.WriteLine("Layer type: '{0}'", layerType);
            }
        }
Esempio n. 3
0
        public override void LoadModel(string filename)
        {
            Logger.WriteLine("Loading SimpleRNN model: {0}", filename);

            StreamReader sr = new StreamReader(filename);
            BinaryReader br = new BinaryReader(sr.BaseStream);

            LAYERTYPE layerType = (LAYERTYPE)br.ReadInt32();

            ModelDirection = (MODELDIRECTION)br.ReadInt32();
            ModelType      = (MODELTYPE)br.ReadInt32();
            IsCRFTraining  = br.ReadBoolean();

            //Create cells of each layer
            int layerSize = br.ReadInt32();

            HiddenLayerList = new List <SimpleLayer>();
            for (int i = 0; i < layerSize; i++)
            {
                SimpleLayer layer = null;
                if (layerType == LAYERTYPE.BPTT)
                {
                    layer = new BPTTLayer();
                }
                else
                {
                    layer = new LSTMLayer();
                }

                layer.Load(br);
                HiddenLayerList.Add(layer);
            }

            Logger.WriteLine("Create output layer");
            OutputLayer = new SimpleLayer();
            OutputLayer.Load(br);

            if (IsCRFTraining == true)
            {
                Logger.WriteLine("Loading CRF tag trans weights...");
                CRFTagTransWeights = RNNHelper.LoadMatrix(br);
            }

            sr.Close();
        }
    private GameObject InstantiateNeuron(LAYERTYPE l_type)
    {
        switch (l_type)
        {
        case (LAYERTYPE.MPL):
            return(Instantiate(neuron_l0));

        case (LAYERTYPE.CONVOLUTIONAL):
            return(Instantiate(kernel_l0));

        case (LAYERTYPE.POOLING):
            return(Instantiate(pooling_kernel_l0));

        case (LAYERTYPE.INPUT):
            return(Instantiate(input_kernel_l0));

        default:
            return(Instantiate(neuron_l0));
        }
    }
    private void Activate(int neuron_id, int layer_id)
    {
        //show neuron to bhe active
        Appear(neuron_id, layer_id);
        LAYERTYPE    l_type = layer_types[layer_id];
        LineRenderer curlr;

        //show input links to be active
        if (layer_id < layer_types.Count - 1)
        {
            LAYERTYPE next_l_type = layer_types[layer_id + 1];
            if (l_type == LAYERTYPE.CONVOLUTIONAL && next_l_type == LAYERTYPE.POOLING)
            {
                curlr = layers[layer_id][neuron_id].transform.GetChild(neuron_id).GetComponent <LineRenderer>();
                StartCoroutine(Appear(curlr));
            }
        }
        if (layer_id == 1 && layer_types[0] == LAYERTYPE.INPUT)
        {
            show_input_pattern_convolutional(neuron_id);
        }
    }
    void AddLayer(LAYERTYPE layer_type)
    {
        int        layer_id = layers.Count;
        GameObject new_l    = new GameObject();

        new_l.name = "Layer" + layer_id;
        //neurons of layer container
        layers.Add(new List <GameObject>());
        new_l.transform.parent   = MPL.transform;
        new_l.transform.position = new Vector3(layer_id * distance_between_layers,
                                               new_l.transform.position.y, new_l.transform.position.z);
        //add first neuron to layer
        GameObject new_neuron = InstantiateNeuron(layer_type);

        new_neuron.name               = "n" + layer_id + "0";
        new_neuron.transform.parent   = new_l.transform;
        new_neuron.transform.position = new Vector3(new_l.transform.position.x, new_l.transform.position.y, new_l.transform.position.z);
        new_neuron.GetComponent <Renderer>().material.color = GetNeuronColor(layer_id);

        layers[layer_id].Add(new_neuron);

        StartCoroutine(ChangeColor(new_neuron));



        if (layer_id > 0)
        {
            if (layer_types[layer_id] == LAYERTYPE.POOLING && layer_types[layer_id - 1] == LAYERTYPE.CONVOLUTIONAL)
            {
                StopCoroutine(ChangeColor(new_neuron));
            }

            foreach (var n in layers[layer_id - 1])
            {
                Addlink(n, new_neuron);
            }
        }
    }
Esempio n. 7
0
        public override void LoadModel(string filename)
        {
            Logger.WriteLine(Logger.Level.info, "Loading bi-directional model: {0}", filename);

            using (StreamReader sr = new StreamReader(filename))
            {
                BinaryReader br = new BinaryReader(sr.BaseStream);

                LAYERTYPE layerType = (LAYERTYPE)br.ReadInt32();
                ModelDirection = (MODELDIRECTION)br.ReadInt32();
                ModelType      = (MODELTYPE)br.ReadInt32();
                IsCRFTraining  = br.ReadBoolean();

                int layerSize = br.ReadInt32();
                //Load forward layers from file
                forwardHiddenLayers = new List <SimpleLayer>();
                for (int i = 0; i < layerSize; i++)
                {
                    SimpleLayer layer = null;
                    if (layerType == LAYERTYPE.BPTT)
                    {
                        Logger.WriteLine("Create BPTT hidden layer");
                        layer = new BPTTLayer();
                    }
                    else
                    {
                        Logger.WriteLine("Create LSTM hidden layer");
                        layer = new LSTMLayer();
                    }

                    layer.Load(br);
                    forwardHiddenLayers.Add(layer);
                }

                //Load backward layers from file
                backwardHiddenLayers = new List <SimpleLayer>();
                for (int i = 0; i < layerSize; i++)
                {
                    SimpleLayer layer = null;
                    if (layerType == LAYERTYPE.BPTT)
                    {
                        Logger.WriteLine("Create BPTT hidden layer");
                        layer = new BPTTLayer();
                    }
                    else
                    {
                        Logger.WriteLine("Create LSTM hidden layer");
                        layer = new LSTMLayer();
                    }

                    layer.Load(br);
                    backwardHiddenLayers.Add(layer);
                }

                Logger.WriteLine("Create output layer");
                OutputLayer = new SimpleLayer();
                OutputLayer.Load(br);

                if (IsCRFTraining == true)
                {
                    Logger.WriteLine("Loading CRF tag trans weights...");
                    CRFTagTransWeights = RNNHelper.LoadMatrix(br);
                }
            }
        }