예제 #1
0
        public static (Symbol, NDArrayDict, NDArrayDict) LoadRNNCheckPoint(BaseRNNCell[] cells, string prefix, int epoch)
        {
            var(sym, arg, aux) = MxModel.LoadCheckpoint(prefix, epoch);
            foreach (var cell in cells)
            {
                arg = cell.PackWeights(arg);
            }

            return(sym, arg, aux);
        }
예제 #2
0
        public static Module Load(string prefix, int epoch, bool load_optimizer_states = false,
                                  string[] data_names = null, string[] label_names = null, Logger logging             = null,
                                  Context context     = null, int[] work_load_list = null, string[] fixed_param_names = null)
        {
            var(sym, args, auxs) = MxModel.LoadCheckpoint(prefix, epoch);
            var mod = new Module(sym);

            mod._arg_params       = args;
            mod._aux_params       = auxs;
            mod.ParamsInitialized = true;
            if (load_optimizer_states)
            {
                mod._preload_opt_states = $"{prefix}-{epoch.ToString("D4")}.states";
            }

            return(mod);
        }
예제 #3
0
        private static Module LoadModel(string prefix, int epoch = 0, bool gpu = true)
        {
            var(sym, arg_params, aux_params) = MxModel.LoadCheckpoint(prefix, epoch);
            arg_params["prob_label"]         = new NDArray(new float[0]);
            arg_params["softmax_label"]      = new NDArray(new float[0]);
            Module mod = null;

            if (gpu)
            {
                mod = new Module(symbol: sym, context: new[] { mx.Gpu(0) }, data_names: new string[] { "data" });
            }
            else
            {
                mod = new Module(symbol: sym, data_names: new string[] { "data" });
            }

            mod.Bind(for_training: false, data_shapes: new[] { new DataDesc("data", new Shape(1, 3, 224, 224)) });
            mod.SetParams(arg_params, aux_params);
            return(mod);
        }