Ejemplo n.º 1
0
        public void load(string file_path_name)
        {
            FileStream stream = new FileStream(file_path_name, FileMode.Open);

            BinaryReader reader = new BinaryReader(stream);

            WeightLayerPool.load(reader);

            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                string id = reader.ReadString();

                int depth = reader.ReadInt32();

                int width = reader.ReadInt32();

                int height = reader.ReadInt32();

                UnitLayer layer = new UnitLayer(id, width, height, depth);

                UnitLayers.Add(id, layer);
            }

            reader.Close();

            stream.Close();
        }
Ejemplo n.º 2
0
        private void backward_convolute_on_depth(UnitLayer to, int stride, int depth, int length)
        {
            int to_depth = depth + length;

            if (to_depth >= Depth)
            {
                to_depth = Depth;
            }

            for (int d = depth; d < to_depth; d++)
            {
                WeightLayer weights = WeightLayerPool.find(to.Id, Id, d);

                int width_of_weights = weights.Width, height_of_weights = weights.Height;

                for (int y = 0; y < Height; y++)
                {
                    int top = y * stride;

                    int bottom = top + height_of_weights;

                    for (int x = 0; x < Width; x++)
                    {
                        int left = x * stride;

                        to.diff_convolute_product(left, top, left + width_of_weights, bottom, Units[x, y, d].gradient_at_inport, weights);
                    }
                }

                weights.diff_weights();
            }
        }
Ejemplo n.º 3
0
        private void forward_convolute_on_depth(UnitLayer to, int stride, int depth, int length)
        {
            int to_depth = depth + length;

            if (to_depth >= to.Depth)
            {
                to_depth = to.Depth;
            }

            for (int d = depth; d < to_depth; d++)
            {
                WeightLayer weights = WeightLayerPool.find(Id, to.Id, d);

                int width_of_weights = weights.Width, height_of_weights = weights.Height;

                int width_of_units = to.Width, height_of_units = to.Height;

                for (int y = 0; y < height_of_units; y++)
                {
                    int top = y * stride;

                    int bottom = top + height_of_weights;

                    for (int x = 0; x < width_of_units; x++)
                    {
                        int left = x * stride;

                        to.set_value_at_inport(x, y, d, weights.convolute_product(left, top, left + width_of_weights, bottom, Units));
                    }
                }
            }
        }
Ejemplo n.º 4
0
        static public void create_convolution(UnitLayer from, UnitLayer to, int width, int height)
        {
            for (int d = 0; d < to.Depth; d++)
            {
                string id = string.Format("C/{0}/{1}/{2}", from.Id, to.Id, d);

                WeightLayer layer = new WeightLayer(id, width, height, from.Depth);

                layer.fill_weights(from.Width * from.Height * from.Depth);

                WeightLayers.Add(id, layer);
            }
        }
Ejemplo n.º 5
0
        public void backward_convolute(UnitLayer to, int stride)
        {
            int index = 0, length = Depth / Config.MAX_NUMBER_OF_TASKS + Config.MIN_LENGTH_OF_TASKS;

            Task[] tasks = new Task[Config.MAX_NUMBER_OF_TASKS];

            for (int d = 0; d < Depth; d += length)
            {
                tasks[index++] = Task.Factory.StartNew((depth) => backward_convolute_on_depth(to, stride, (int)depth, length), d);
            }

            Array.Resize(ref tasks, index);

            Task.WaitAll(tasks);
        }
Ejemplo n.º 6
0
        public void forward_fully_connect(UnitLayer to)
        {
            int index = 0, length = to.Depth / Config.MAX_NUMBER_OF_TASKS + Config.MIN_LENGTH_OF_TASKS;

            Task[] tasks = new Task[Config.MAX_NUMBER_OF_TASKS];

            for (int d = 0; d < to.Depth; d += length)
            {
                tasks[index++] = Task.Factory.StartNew((depth) => forward_fully_connect_on_depth(to, (int)depth, length), d);
            }

            Array.Resize(ref tasks, index);

            Task.WaitAll(tasks);
        }
Ejemplo n.º 7
0
        public double[] get_location_at_forward_convolution(UnitLayer units, int width_of_kernel, int height_of_kernel, int stride, double x, double y)
        {
            int width_of_layer = units.Width;

            int height_of_layer = units.Height;

            int width = (width_of_layer - width_of_kernel) / stride + 1;

            int height = (height_of_layer - height_of_kernel) / stride + 1;

            x = x * width / width_of_layer;

            y = y * height / height_of_layer;

            return(new double[] { x, y });
        }
Ejemplo n.º 8
0
        static public void create_fully_connection(UnitLayer from, UnitLayer to)
        {
            for (int d = 0; d < to.Depth; d++)
            {
                for (int y = 0; y < to.Height; y++)
                {
                    for (int x = 0; x < to.Width; x++)
                    {
                        string id = string.Format("F/{0}/{1}/{2}/{3}/{4}", from.Id, to.Id, x, y, d);

                        WeightLayer layer = new WeightLayer(id, from.Width, from.Height, from.Depth);

                        layer.fill_weights(from.Width * from.Height * from.Depth);

                        WeightLayers.Add(id, layer);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public void backward_average_pool(UnitLayer to, int width, int height, int stride)
        {
            for (int d = 0; d < Depth; d++)
            {
                for (int y = 0; y < Height; y++)
                {
                    int top = y * stride;

                    int bottom = top + height;

                    for (int x = 0; x < Width; x++)
                    {
                        int left = x * stride;

                        to.diff_average_pool(left, top, left + width, bottom, d, Units[x, y, d].gradient_at_inport);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void forward_average_pool(UnitLayer to, int width, int height, int stride)
        {
            int width_of_units = to.Width, height_of_units = to.Height;

            for (int d = 0; d < Depth; d++)
            {
                for (int y = 0; y < height_of_units; y++)
                {
                    int top = y * stride;

                    int bottom = top + height;

                    for (int x = 0; x < width_of_units; x++)
                    {
                        int left = x * stride;

                        to.set_value_at_inport(x, y, d, average_pool(left, top, left + width, bottom, d));
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private void backward_fully_connect_on_depth(UnitLayer to, int depth, int length)
        {
            int to_depth = depth + length;

            if (to_depth >= Depth)
            {
                to_depth = Depth;
            }

            for (int d = depth; d < to_depth; d++)
            {
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        WeightLayer weights = WeightLayerPool.find(to.Id, Id, x, y, d);

                        to.diff_fully_product(Units[x, y, d].gradient_at_inport, weights);

                        weights.diff_weights();
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private void forward_fully_connect_on_depth(UnitLayer to, int depth, int length)
        {
            int width = to.Width, height = to.Height;

            int to_depth = depth + length;

            if (to_depth >= to.Depth)
            {
                to_depth = to.Depth;
            }

            for (int d = depth; d < to_depth; d++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        WeightLayer weights = WeightLayerPool.find(Id, to.Id, x, y, d);

                        to.set_value_at_inport(x, y, d, weights.fully_product(Units));
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public void create_unit_layer(string id, int width, int height, int depth)
        {
            UnitLayer layer = new UnitLayer(id, width, height, depth);

            UnitLayers.Add(id, layer);
        }
Ejemplo n.º 14
0
 public void create_convolution(UnitLayer to, int width, int height)
 {
     WeightLayerPool.create_convolution(this, to, width, height);
 }
Ejemplo n.º 15
0
 public void create_fully_connection(UnitLayer to)
 {
     WeightLayerPool.create_fully_connection(this, to);
 }