Tensorflow study notes
tf.one_hot
This paper only serves as a personal learning record, please refer to tensorFlow Chinese official website TF Chinese official website
Call format
tf.one_hot(indices, depth, on_value=None, off_value=None, axis=None, dtype=None, name=None)
Parameters that
Indices: Tensors of an index.
· depth: a scalar quantity defined in one_hot dimension
· on_value: a set of indices[j] = I (default: 1)
· off_value: a set of indices[j]! = I (default: 0)
· axis: axis to be filled (default: -1, a new innermost axis)
· dtype: the data type of the output tensor.
· name: the name of the operation (optional).
The output
A one_hot tensor
A possible mistake
- TypeError
whether on_value or off_value does not match dtype. TypeError
whether on_value and off_value do not match each other
prompt
- indices location value is on_value, while the other location is off_value. The on_value and OFF_value data types must match. If dType has a value, they must take the same value as the type displayed by DTYPE.
if on_value has no value, the default value is 1, and the output is dtype.
if off_value has no value, the default value is 0, and the output is dtype.
if the indices have N dimensions, the output is N+1. If the indices are scalars, the output is a vector with a length of depth. If the indices are tensor with features, the output will be:
. If the indices are indices with batch size [batch, features], the output will be:
. If the indices are RaggedTensor, the axis must be positive and form an axis which is hard to form. The output is equivalent to the output of one_hot applied with a value of an irregular shape, and a new irregular shape is generated from the result.
if dtype has no value, it will try to assume that the data type is on_value or off_value if one or both pass. If on_value, off_value, dtype have no value, dtpye will default to be tf.float32.
** note: if output of non-numeric types (such as tf.string, tf.bool, etc), on_value, off_value all need to have a value.
example
Read More:
- tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead.
- tf.layers.conv1d Function analysis (one dimensional convolution)
- The routine of benewake tfmini-s / tfmimi plus / tfluna / tf02 Pro / tf03 radar on Python
- Tensorflow-gpu1.14.0 cannot use more than one GPU
- If you want to open more than one program “pdc140.xxx”, the CL.EXE To write to the same. Pdb file, please use
- Tensorflow: How to use expand_Dim() to add dimensions
- In tensorflow tf.reduce_ Mean function
- How to use torch.sum()
- How to eliminate ADB error “more than one device and emulator”
- How to use matlab xlswrite
- C#: How to Use Httpclient to upload files with other parameters
- How to Solve failed Precondition Error: attempting to use uninitialized value beta1_power
- How to Use Apt get Command Under Mac OSX
- Tensorflow in function tf.Print Method of outputting intermediate value
- How to Use Subfigure in Latex
- The garbled problem of hot deployment in nginx
- How to Use the Reverse() Function
- How to use C # to get image format without system. Drawing. Common
- How to use JavaScript in HTML
- React bootstrap loading and how to use modules