Esempio n. 1
0
        public static void LoadCheckpoint(string prefix,
                                          int?epoch,
                                          out Symbol symbol,
                                          out Dictionary <string, NdArray> argParams,
                                          out Dictionary <string, NdArray> auxParams)
        {
            symbol = Symbol.Load($"{prefix}-symbol.json");
            Dictionary <string, NdArray> saveDict;

            if (epoch.HasValue)
            {
                NdArray.Load($"{prefix}-{epoch:D4}.params", out saveDict);
            }
            else
            {
                int i = 1;
                for (; i < 10000; i++)
                {
                    var path = $"{prefix}-{i:D4}.params";
                    if (!File.Exists(path))
                    {
                        i--;
                        break;
                    }
                }
                var readpath = $"{prefix}-{i:D4}.params";
                if (File.Exists(readpath))
                {
                    NdArray.Load(readpath, out saveDict);
                }
                else
                {
                    throw new FileNotFoundException("can not laod params files,check you prefix and epoch");
                }
            }

            argParams = new Dictionary <string, NdArray>();
            auxParams = new Dictionary <string, NdArray>();

            foreach (var kvitem in saveDict)
            {
                var sp   = kvitem.Key.Split(':');
                var tp   = sp[0];
                var name = sp[1];

                if (tp == "arg")
                {
                    argParams[name] = kvitem.Value;
                }
                if (tp == "aux")
                {
                    auxParams[name] = kvitem.Value;
                }
            }
        }