public static void Serialize(FileStream stream, INeuralNetworkImage image)
 {
     if (image is NeuralNetworkImage cu_image)
     {
         NeuralNetworkSerializer.Serialize(stream, cu_image);
     }
     else if (image is NeuralNetworkLineImage cu_line_image)
     {
         NeuralNetworkLineSerializer.Serialize(stream, cu_line_image);
     }
     else
     {
         throw new Exception(
                   "The serializer for this type of INeuralNetworkImage is not registed.");
     }
 }
        public static void Serialize(FileStream stream, NeuralNetworkLineImage image)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            byte[] buffer;

            // new version signal
            buffer = BitConverter.GetBytes(SectionType.SECTION_START_SIGNAL); // 2-bytes
            stream.Write(buffer, 0, buffer.Length);

            // serialize section type
            buffer = new byte[] { SECTION_TYPE }; // 1-bytes
            stream.Write(buffer, 0, buffer.Length);

            // serialize version
            buffer = BitConverter.GetBytes(VERSION); // 2-bytes
            stream.Write(buffer, 0, buffer.Length);

            // serialize index
            buffer = BitConverter.GetBytes(image.index); // 4-bytes
            stream.Write(buffer, 0, buffer.Length);

            // functions serializer
            var function = new FunctionSerializerCore(stream);

            // serialize images count
            buffer = BitConverter.GetBytes(image.images.Length); // 4-bytes
            stream.Write(buffer, 0, buffer.Length);

            // serialize line
            NeuralNetworkSerializer.Serialize(stream, image.images[0]);
            for (int i = 0; i < image.combiners.Length;)
            {
                function.Serialize(image.combiners[i++]);
                NeuralNetworkSerializer.Serialize(stream, image.images[i]);
            }
        }