Esempio n. 1
0
        public void StringArrayConverting()
        {
            var nd = np.array(strArray);

            nd.Should().BeOfType <char>()
            .And.BeShaped(28)
            .And.BeOfValues(50, 32, 54, 32, 49, 53, 58, 72, 101, 108, 108, 111, 44, 32, 83, 99, 105, 83, 104, 97, 114, 112, 32, 84, 101, 97, 109, 33);

            NDArray.AsStringArray(nd).SequenceEqual(strArray);
        }
Esempio n. 2
0
        public string save(Session sess,
                           string save_path,
                           int global_step          = -1,
                           string latest_filename   = "",
                           string meta_graph_suffix = "meta",
                           bool write_meta_graph    = true,
                           bool write_state         = true,
                           bool strip_default_attrs = false,
                           bool save_debug_info     = false)
        {
            if (string.IsNullOrEmpty(latest_filename))
            {
                latest_filename = "checkpoint";
            }
            NDArray[] model_checkpoint_path = null;
            string    checkpoint_file       = "";

            if (global_step > 0)
            {
                checkpoint_file = $"{save_path}-{global_step}";
            }
            else
            {
                checkpoint_file = save_path;
            }

            var save_path_parent = Path.GetDirectoryName(save_path);

            if (!_is_empty)
            {
                model_checkpoint_path = sess.run(_saver_def.SaveTensorName,
                                                 (_saver_def.FilenameTensorName, checkpoint_file));

                if (write_state)
                {
                    var path = NDArray.AsStringArray(model_checkpoint_path[0])[0];
                    _RecordLastCheckpoint(path);
                    checkpoint_management.update_checkpoint_state_internal(
                        save_dir: save_path_parent,
                        model_checkpoint_path: path,
                        all_model_checkpoint_paths: _last_checkpoints.Keys.Select(x => x).ToList(),
                        latest_filename: latest_filename,
                        save_relative_paths: _save_relative_paths);
                    _MaybeDeleteOldCheckpoints(meta_graph_suffix: meta_graph_suffix);
                }
            }

            if (write_meta_graph)
            {
                string meta_graph_filename = checkpoint_management.meta_graph_filename(checkpoint_file, meta_graph_suffix: meta_graph_suffix);
                export_meta_graph(meta_graph_filename, strip_default_attrs: strip_default_attrs, save_debug_info: save_debug_info);
            }

            return(_is_empty ? string.Empty : NDArray.AsStringArray(model_checkpoint_path[0])[0]);
        }
        public bool Run()
        {
            // Eager model is enabled by default.
            tf.enable_eager_execution();

            /* Create a Constant op
             * The op is added as a node to the default graph.
             *
             * The value returned by the constructor represents the output
             * of the Constant op. */
            var str   = "Hello, TensorFlow.NET!";
            var hello = tf.constant(str);

            // tf.Tensor: shape=(), dtype=string, numpy=b'Hello, TensorFlow.NET!'
            print(hello);

            var tensor = NDArray.AsStringArray(hello.numpy())[0];

            return(str == tensor);
        }