在 TensorFlow 2.0 中,迭代 TensorShape 實例會返回值。
用法
tf.compat.v1.enable_v2_tensorshape()
這啟用了新的行為。
具體來說,tensor_shape[i]
在 V1 中返回了一個 Dimension 實例,但在 V2 中它返回一個整數或 None。
例子:
#######################
# If you had this in V1:
value = tensor_shape[i].value
# Do this in V2 instead:
value = tensor_shape[i]
#######################
# If you had this in V1:
for dim in tensor_shape:
value = dim.value
print(value)
# Do this in V2 instead:
for value in tensor_shape:
print(value)
#######################
# If you had this in V1:
dim = tensor_shape[i]
dim.assert_is_compatible_with(other_shape) # or using any other shape method
# Do this in V2 instead:
if tensor_shape.rank is None:
dim = Dimension(None)
else:
dim = tensor_shape.dims[i]
dim.assert_is_compatible_with(other_shape) # or using any other shape method
# The V2 suggestion above is more explicit, which will save you from
# the following trap (present in V1):
# you might do in-place modifications to `dim` and expect them to be reflected
# in `tensor_shape[i]`, but they would not be.
相關用法
- Python tf.compat.v1.enable_eager_execution用法及代碼示例
- Python tf.compat.v1.estimator.DNNEstimator用法及代碼示例
- Python tf.compat.v1.estimator.experimental.KMeans用法及代碼示例
- Python tf.compat.v1.estimator.tpu.RunConfig用法及代碼示例
- Python tf.compat.v1.expand_dims用法及代碼示例
- Python tf.compat.v1.estimator.regressor_parse_example_spec用法及代碼示例
- Python tf.compat.v1.estimator.BaselineRegressor用法及代碼示例
- Python tf.compat.v1.estimator.inputs.numpy_input_fn用法及代碼示例
- Python tf.compat.v1.executing_eagerly_outside_functions用法及代碼示例
- Python tf.compat.v1.estimator.LinearRegressor用法及代碼示例
- Python tf.compat.v1.estimator.BaselineEstimator用法及代碼示例
- Python tf.compat.v1.estimator.BaselineClassifier用法及代碼示例
- Python tf.compat.v1.estimator.LinearClassifier用法及代碼示例
- Python tf.compat.v1.estimator.DNNLinearCombinedRegressor用法及代碼示例
- Python tf.compat.v1.executing_eagerly用法及代碼示例
- Python tf.compat.v1.estimator.tpu.TPUEstimator用法及代碼示例
- Python tf.compat.v1.estimator.DNNClassifier用法及代碼示例
- Python tf.compat.v1.estimator.DNNRegressor用法及代碼示例
- Python tf.compat.v1.estimator.tpu.experimental.EmbeddingConfigSpec用法及代碼示例
- Python tf.compat.v1.estimator.DNNLinearCombinedEstimator用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.enable_v2_tensorshape。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。