public static LearningProcessInfo Restore(string path, out byte[] extra)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            using var stream = File.OpenRead(path);

            // read file signature
            var file_type_signature = SectionType.ReadSigniture(stream, Encoding.ASCII);

            if (file_type_signature != FILE_TYPE_SIGNATURE_STRING)
            {
                throw new Exception($"Invalid nnp file signature ({file_type_signature}).");
            }

            // restore file
            var process = Restore(stream);

            if (stream.Position < stream.Length)
            {
                extra = new byte[stream.Length - stream.Position];
                stream.Read(extra, 0, extra.Length);
            }
            else
            {
                extra = null;
            }

            return(process);
        }
Beispiel #2
0
        public static object Restore(string path, out byte[] extra)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            using var stream = File.OpenRead(path);

            // read file signature
            var    file_type_signature = SectionType.ReadSigniture(stream, Encoding.ASCII);
            object result;

            switch (file_type_signature)
            {
            case LearningProcessSerializer.FILE_TYPE_SIGNATURE_STRING:
                result = LearningProcessSerializer.Restore(stream);
                extra  = ReadExtra(stream);
                return(result);

            case NeuralNetworkSerializer.FILE_TYPE_SIGNATURE_STRING:
                result = NeuralNetworkSerializer.Restore(stream);
                extra  = ReadExtra(stream);
                return(result);

            case NeuralNetworkLineSerializer.FILE_TYPE_SIGNATURE_STRING:
                result = NeuralNetworkLineSerializer.Restore(stream);
                extra  = ReadExtra(stream);
                return(result);

            default:
                throw new Exception($"Invalid file type ({file_type_signature}).");
            }
        }
        public static NeuralNetworkLineImage Restore(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            using var stream = File.OpenRead(path);

            // read file signature
            var file_type_signature = SectionType.ReadSigniture(stream, Encoding.ASCII);

            if (file_type_signature != FILE_TYPE_SIGNATURE_STRING)
            {
                throw new Exception($"Invalid nnli file signature ({file_type_signature}).");
            }

            // restore file
            return(Restore(stream));
        }