示例#1
0
        public static void Serialize(FileStream stream, NetProcess process)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }

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

            var state = process.ProcessInfo();

            buffer = BitConverter.GetBytes(state.running_record_count); // 4-bytes
            stream.Write(buffer, 0, buffer.Length);

            buffer = BitConverter.GetBytes(state.running_total_accruacy); // 8-bytes
            stream.Write(buffer, 0, buffer.Length);

            buffer = BitConverter.GetBytes(state.accuracy_chain_history.Length); // 4-bytes
            stream.Write(buffer, 0, buffer.Length);

            foreach (var ac in state.accuracy_chain_history)
            {
                buffer = BitConverter.GetBytes(ac); // 8-bytes
                stream.Write(buffer, 0, buffer.Length);
            }

            NeuralNetworkGeneralSerializer.Serialize(stream, state.running_image);

            if (state.stable_image == null)
            {
                buffer = new byte[] { 0 }; // 1-byte
                stream.Write(buffer, 0, buffer.Length);
            }
            else
            {
                buffer = new byte[] { 1 }; // 1-byte
                stream.Write(buffer, 0, buffer.Length);

                NeuralNetworkGeneralSerializer.Serialize(stream, state.stable_image);
            }
        }