From 66ba622472e68536db5fbf2fe60d72542cecf17b Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sat, 26 Sep 2020 07:06:10 -0500 Subject: [PATCH] update docs of constant. --- docs/source/Constant.md | 14 ++++++- docs/source/EagerMode.md | 3 +- docs/source/Graph.md | 2 +- docs/source/Tensor.md | 9 +++- .../constant/n-index-formula-offset.svg | 41 +++++++++++++++++++ .../_static/constant/n-index-formula.svg | 33 +++++++++++++++ 6 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 docs/source/_static/constant/n-index-formula-offset.svg create mode 100644 docs/source/_static/constant/n-index-formula.svg diff --git a/docs/source/Constant.md b/docs/source/Constant.md index f9084d3c..dd6aa3bf 100644 --- a/docs/source/Constant.md +++ b/docs/source/Constant.md @@ -44,7 +44,7 @@ Let's continue using the last examples, we're going to initialize a tensor in an ##### NDArray -The first thing we need to know is about `ndarray`'s memory model. The ndarray memory model is a very important data structure, and almost all underlying computation are inseparable from this datb a structure. One fundamental aspect of the ndarray is that an array is seen as a "chunk" of memory starting at some location. The interpretation of this memory depends on the stride information. +The first thing we need to know is about `ndarray`'s memory model. The ndarray memory model is a very important data structure, and almost all underlying computation are inseparable from this datb a structure. One fundamental aspect of the ndarray is that an array is seen as a "chunk" of memory starting at some location. The interpretation of this memory depends on the stride information. A segment of memory is inherently 1-dimensional, and there are many different schemes for arranging the items of an N-dimensional array in a 1-dimensional block. `ndarray` objects can accommodate any strided indexing scheme. In a strided scheme, the N-dimensional index corresponds to the offset (in bytes) : . @@ -60,11 +60,21 @@ Through the above diagram, we know how the data is stored in memory, and then we If you don't understand very well what `Tensor` is, you can go back to the chapter `Tensor` there is pretty much explanation if you skipped that chapter. Tensor is actually an NDArray that is with more than 2 dimensions. -TensorFlow will decide whether to copy the data or use the same pointer. Normally speaking, it's more safe whenever you copy data for the following process, especially in interoperating between .NET runtime and C++ runtime that they all have their own garbage collection (GC) mechanism, application will crash if someone access a block of destroyed memory. +TensorFlow will decide whether to copy the data or use the same pointer. Normally speaking, it's more safe whenever you copy data for the following process, especially in interoperating between .NET runtime and C++ runtime that they all have their own garbage collection (GC) mechanism, application will crash if someone access a block of destroyed memory. `TF_STRING` and `TF_RESOURCE` tensors have a different representation in `TF_Tensor` than they do in `tensorflow::Tensor`. Other types have the same representation, so copy only if it is safe to do so. +Before tensorflow is creating the `TF_Tensor`, it checks the shape and data size. If the size doesn't match, it will return `nullptr` pointer. +##### Get the data of Tensor + +For `eager` mode, it's pretty simple to view the actual value in a `tensor`. + +```csharp +var data = tensor.numpy() +``` + +The `data` will be a `ndarray` variable. ##### Other functions to create a Constant diff --git a/docs/source/EagerMode.md b/docs/source/EagerMode.md index cbb0ea02..ded56d41 100644 --- a/docs/source/EagerMode.md +++ b/docs/source/EagerMode.md @@ -1,2 +1,3 @@ -# Chapter. Eager Mode +# Chapter 4. Eager Mode +TensorFlow's eager execution is an imperative programming environment that evaluates operations immediately, without building graphs: operations return concrete values instead of constructing a computational graph to run later. This makes it easy to get started with TensorFlow and debug models, and it reduces boilerplate as well. \ No newline at end of file diff --git a/docs/source/Graph.md b/docs/source/Graph.md index 7bc473f2..874cd9a4 100644 --- a/docs/source/Graph.md +++ b/docs/source/Graph.md @@ -1,4 +1,4 @@ -# Chapter. Graph +# Chapter 3. Graph TensorFlow uses a **dataflow graph** to represent your computation in terms of the dependencies between individual operations. A graph defines the computation. It doesn't compute anything, it doesn't hold any values, it just defines the operations that you specified in your code. diff --git a/docs/source/Tensor.md b/docs/source/Tensor.md index dbab9a05..aefb884f 100644 --- a/docs/source/Tensor.md +++ b/docs/source/Tensor.md @@ -6,13 +6,13 @@ ##### What is Tensor? -Tensor holds a multi-dimensional array of elements of a single data type which is very similar with numpy's ndarray. When the dimension is zero, it can be called a scalar. When the dimension is 2, it can be called a matrix. When the dimension is greater than 2, it is usually called a tensor. If you are very familiar with numpy, then understanding Tensor will be quite easy. +Tensor holds a multi-dimensional array of elements of a single data type which is very similar with `NumPy`'s `ndarray`. When the dimension is zero, it can be called a scalar. When the dimension is 2, it can be called a matrix. When the dimension is greater than 2, it is usually called a tensor. If you are very familiar with `NumPy`, then understanding Tensor will be quite easy. ##### How to create a Tensor? -There are many ways to initialize a Tensor object in TF.NET. It can be initialized from a scalar, string, matrix or tensor. But the best way to create a Tensor is using high level APIs like `tf.constant`, `tf.zeros` and `tf.ones`. We'll talk about constant more in next chapter. +There are many ways to initialize a Tensor object in TF.NET. It can be initialized from a scalar, string, matrix or tensor. But the best way to create a Tensor is using high level APIs like `tf.constant`, `tf.zeros` and `tf.ones`. We'll talk about constant more detail in next chapter. ```csharp // Create a tensor holds a scalar value @@ -45,3 +45,8 @@ var nd = np.array(1f, 2f, 3f, 4f, 5f, 6f).reshape(2, 3); ![column-major order](_static/column-major-order.png) ![row-major order](_static/row-major-order.png) + +##### Index/ Slice of Tensor + +Tensor element can be accessed by `index` and `slice` related operations. Through some high level APIs, we can easily access specific dimension's data. + diff --git a/docs/source/_static/constant/n-index-formula-offset.svg b/docs/source/_static/constant/n-index-formula-offset.svg new file mode 100644 index 00000000..6c5a3219 --- /dev/null +++ b/docs/source/_static/constant/n-index-formula-offset.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/source/_static/constant/n-index-formula.svg b/docs/source/_static/constant/n-index-formula.svg new file mode 100644 index 00000000..5d05c06f --- /dev/null +++ b/docs/source/_static/constant/n-index-formula.svg @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file