Пример #1
0
        /// <summary>
        /// Decodes the predictions.
        /// </summary>
        /// <param name="preds">The preds.</param>
        /// <param name="top">The top.</param>
        /// <returns></returns>
        public ImageNetPrediction[] DecodePredictions(NDarray preds, int top = 3)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters["preds"] = preds;
            parameters["top"]   = top;
            var predobj = (PyObject)InvokeStaticMethod(caller, "decode_predictions", parameters);
            var d       = predobj.ToString();
            var list    = TupleSolver.TupleToList <object>(predobj[0]);
            List <ImageNetPrediction> predictions = new List <ImageNetPrediction>();

            for (int i = 0; i < list.Length; i = i++)
            {
                ImageNetPrediction pred = new ImageNetPrediction()
                {
                    WordID         = list[i].ToString(),
                    Word           = list[i + 1].ToString(),
                    PredictedValue = Convert.ToSingle(list[i + 2].ToString(), CultureInfo.InvariantCulture),
                };

                i = i + 3;

                predictions.Add(pred);
            }

            return(predictions.ToArray());
        }
Пример #2
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        /// <param name="path">The path. to load text</param>
        /// <param name="num_words">The number words.</param>
        /// <param name="skip_top">Skip top number of records.</param>
        /// <param name="maxlen">The max length.</param>
        /// <param name="test_split">The test split.</param>
        /// <param name="seed">The seed.</param>
        /// <param name="start_char">The start character.</param>
        /// <param name="oov_char">The oov character.</param>
        /// <param name="index_from">The index from.</param>
        /// <returns></returns>
        public static ((NDarray, NDarray), (NDarray, NDarray)) LoadData(string path = "reuters.npz", int?num_words = null, int skip_top = 0, int?maxlen  = null, float test_split = 0.2f,
                                                                        int seed    = 113, int start_char          = 1, int oov_char = 2, int index_from = 3)
        {
            var dlist = TupleSolver.TupleToList(Instance.keras.datasets.reuters.load_data(path: path, num_words: num_words, skip_top: skip_top, maxlen: maxlen, test_split: test_split, seed: seed, start_char: start_char,
                                                                                          oov_char: oov_char, index_from: index_from));

            return((dlist[0], dlist[1]), (dlist[2], dlist[3]));
        }
Пример #3
0
        public static (PyObject, string) NPRandom(int?seed = null)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters["seed"] = seed;

            var list = TupleSolver.TupleToList <object>((PyObject)InvokeStaticMethod(caller.seeding, "np_random", parameters));

            return((PyObject)list[0], list[1].ToString());
        }
Пример #4
0
        /// <summary>
        /// Decodes the predictions.
        /// </summary>
        /// <param name="preds">The preds.</param>
        /// <param name="top">The top.</param>
        /// <returns></returns>
        public static ImageNetPrediction[] DecodePredictions(NDarray preds, int top = 3)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters["preds"] = preds;
            parameters["top"]   = top;
            var predobj = (PyObject)InvokeStaticMethod(Instance.keras.applications.resnet50, "decode_predictions", parameters);
            var d       = predobj.ToString();
            var list    = TupleSolver.TupleToList <object>(predobj);

            return(null);
        }
Пример #5
0
        public virtual (float, object) ComputeReward(object achieved_goal, object desired_goal, Dictionary <string, object> info)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters["achieved_goal"] = achieved_goal;
            parameters["desired_goal"]  = desired_goal;
            parameters["info"]          = info;

            var py   = InvokeMethod("compute_reward", parameters);
            var list = TupleSolver.TupleToList <object>(py);

            return((float)list[0], list[1]);
        }
Пример #6
0
        public virtual EnvResult Step(object action)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters["action"] = action;
            PyObject  py     = InvokeMethod("step", parameters);
            var       list   = TupleSolver.TupleToList <object>(py);
            EnvResult result = new EnvResult()
            {
                Observation = list[0],
                Reward      = Convert.ToSingle(list[1].ToString()),
                Done        = list[2].ToString() == "True" ? true : false,
                Info        = DictSolver.ToClr <object>(new PyDict((PyObject)list[3]))
            };

            return(result);
        }
Пример #7
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public static ((NDarray, NDarray), (NDarray, NDarray)) LoadData(string path = "mnist.npz")
        {
            var dlist = TupleSolver.TupleToList(Instance.keras.datasets.mnist.load_data(path: path));

            return((dlist[0], dlist[1]), (dlist[2], dlist[3]));
        }
Пример #8
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        /// <returns></returns>
        public static ((NDarray, NDarray), (NDarray, NDarray)) LoadData()
        {
            var dlist = TupleSolver.TupleToList(Instance.keras.datasets.fashion_mnist.load_data());

            return((dlist[0], dlist[1]), (dlist[2], dlist[3]));
        }
Пример #9
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        /// <param name="label_mode">The label mode.</param>
        /// <returns></returns>
        public static ((NDarray, NDarray), (NDarray, NDarray)) LoadData(string label_mode = "fine")
        {
            var dlist = TupleSolver.TupleToList(Instance.keras.datasets.cifar10.load_data(label_mode: label_mode));

            return((dlist[0], dlist[1]), (dlist[2], dlist[3]));
        }
Пример #10
0
        /// <summary>
        /// Loads the data.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="test_split">The test split.</param>
        /// <param name="seed">The seed.</param>
        /// <returns></returns>
        public static ((NDarray, NDarray), (NDarray, NDarray)) LoadData(string path = "boston_housing.npz", float test_split = 0.2f, int seed = 113)
        {
            var dlist = TupleSolver.TupleToList(Instance.keras.datasets.boston_housing.load_data(path: path, test_split: test_split, seed: seed));

            return((dlist[0], dlist[1]), (dlist[2], dlist[3]));
        }