TensorFlow 2.0 Layer with None type shape Tensor

ライアン・ウォルデン

以下の関数はtf.keras.layers.Lambda()、TF2.0に準拠して呼び出そうとしていますinputsそしてoutputsテンソルは、3つのカラーチャネルを有する同じ寸法の二つの画像であろう。私の目標は、outputsテンソルからマスクを抽出し、それをテンソルに適用してinputs、結果のテンソルを返すことです。テンソルを平坦化する動機は、tf.tensor_scatter_nd_update()機能の制限によるものです。モデルを作成すると、が値であるupdatesため、初期化に失敗します。初期化するために2つのテンソルを使用してモデルの外部でこのレイヤーを呼び出すと、熱心な実行で完全に正常に実行されますテンソルには値が定義されているため)。残念ながら、この関数をで呼び出すと、次のエラーが発生します。indices.shape[0]Nonetf.constant()xxtf.keras.layers.Lambda()

TypeError: can't multiply sequence by non-int of type 'NoneType'

@tf.function
def applyMask(x):
  # Extract Tensors
  inputs = x[0]
  outputs = x[1]

  # Flatten the Outputs Tensor and Extract Mask Indices 
  outputs = tf.reshape(outputs,(tf.size(outputs),))
  indices = tf.where(outputs==1.)
  indices = tf.cast(indices, tf.int32)

  # Construct Updates Tensor from Mask Indices
  updates = tf.constant([1.]*indices.shape[0])

  # Flatten Input Tensor and Apply Mask
  out_dim = inputs.shape
  inputs = tf.reshape(inputs,(tf.size(inputs),))
  tensor = tf.tensor_scatter_nd_update(inputs, indices, updates)

  # Reconstruct Input Into Tensor
  tensor = tf.reshape(tensor, out_dim)
  return tensor
したがってhv89

この複雑である必要はありません。単に行う、

inp1 = Input(shape=(None, None, 3)) # Inputs
inp2 = Input(shape=(None, None, 3)) # Outputs

out = Lambda(lambda x: tf.where(tf.equal(x[1], 1), x[1], x[0]))([inp1, inp2])

そして、あなたも持つことができるheightwidth Noneしている限りに渡される並列サンプルとしてinp1とがinp2あるまったく同じ(形状的に)、tf.where罰金を動作します。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

TensorFlow cannot feed value of shape (538, 1) for Tensor 'Placeholder_21:0', which has shape '(?, 8)'?

分類Dev

What is the shape of an image tensor in TensorFlow

分類Dev

Tensor has shape [None, None] when created with placeholders

分類Dev

TensorFlow:AttributeError: 'Tensor' object has no attribute 'shape'

分類Dev

In Tensorflow How can I add a Tensor to another Tensor with different shape?

分類Dev

Keras: `Input`レイヤーを使用すると" Found:Tensor( "input_1:0"、shape =(None、256、256、2)、dtype = float32) "エラーが発生する

分類Dev

Running Keras DNN model (UNet) using OpenCV readNetFromTensorFlow: Error: Unknown layer type Shape in op decoder_stage0_upsampling/Shape

分類Dev

isinstance() to check Keras Layer Type on Tensor

分類Dev

Tensorflow:Tensor Tensor( "Placeholder:0"、shape =(?, 3)、dtype = float32)はこのグラフの要素ではありません

分類Dev

How to explicitly broadcast a tensor to match another's shape in tensorflow?

分類Dev

グラフが切断されました:レイヤー "input_5"でテンソルTensor( "input_5:0"、shape =(None、None、None、128)、dtype = float32)の値を取得できません

分類Dev

Tensorflow:TypeError:予期されたバイナリまたはユニコード文字列、取得<tf.Tensor'Placeholder:0 'shape = <unknown> dtype = string>

分類Dev

Tensorflowで「None」として表示されるTensor

分類Dev

tf.shape(image)はTensorflow2.0でNoneを返します

分類Dev

tensorflow set block within 2d tensor to constant value

分類Dev

Slicing tensor with list - TensorFlow

分類Dev

Drop a dimension of a tensor in Tensorflow

分類Dev

Slice tensor in Keras Tensorflow

分類Dev

Keras Dense layer shape error

分類Dev

ValueError:Tensor Tensor( "Const:0"、shape =()、dtype = float32)にtf.placeholderを指定できない場合があります

分類Dev

Tensor Tensor( "predictions / Softmax:0"、shape =(?, 1000)、dtype = float32)はこのグラフの要素ではありません

分類Dev

How to reshape (None, 10)-dimensional tensor to (None, None, 10) in Keras?

分類Dev

LSTM network expects target at last layer to have 2 dimensions, but got array with shape (996, 1, 1)

分類Dev

How can I create a numpy array with shape (0, 2)?

分類Dev

Why Tensorflow error: `failed to convert object of type <class 'dict'> to Tensor` happens and How can I solve it?

分類Dev

TensorFlow Dataset: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

分類Dev

Creating tensorflow::Tensor from Eigen::Tensor

分類Dev

'(slice(None, None, None), 0)' is an invalid key

分類Dev

Keras: ValueError: Input 0 of layer sequential_1 is incompatible with the layer: expected ndim=3, found ndim=2

Related 関連記事

  1. 1

    TensorFlow cannot feed value of shape (538, 1) for Tensor 'Placeholder_21:0', which has shape '(?, 8)'?

  2. 2

    What is the shape of an image tensor in TensorFlow

  3. 3

    Tensor has shape [None, None] when created with placeholders

  4. 4

    TensorFlow:AttributeError: 'Tensor' object has no attribute 'shape'

  5. 5

    In Tensorflow How can I add a Tensor to another Tensor with different shape?

  6. 6

    Keras: `Input`レイヤーを使用すると" Found:Tensor( "input_1:0"、shape =(None、256、256、2)、dtype = float32) "エラーが発生する

  7. 7

    Running Keras DNN model (UNet) using OpenCV readNetFromTensorFlow: Error: Unknown layer type Shape in op decoder_stage0_upsampling/Shape

  8. 8

    isinstance() to check Keras Layer Type on Tensor

  9. 9

    Tensorflow:Tensor Tensor( "Placeholder:0"、shape =(?, 3)、dtype = float32)はこのグラフの要素ではありません

  10. 10

    How to explicitly broadcast a tensor to match another's shape in tensorflow?

  11. 11

    グラフが切断されました:レイヤー "input_5"でテンソルTensor( "input_5:0"、shape =(None、None、None、128)、dtype = float32)の値を取得できません

  12. 12

    Tensorflow:TypeError:予期されたバイナリまたはユニコード文字列、取得<tf.Tensor'Placeholder:0 'shape = <unknown> dtype = string>

  13. 13

    Tensorflowで「None」として表示されるTensor

  14. 14

    tf.shape(image)はTensorflow2.0でNoneを返します

  15. 15

    tensorflow set block within 2d tensor to constant value

  16. 16

    Slicing tensor with list - TensorFlow

  17. 17

    Drop a dimension of a tensor in Tensorflow

  18. 18

    Slice tensor in Keras Tensorflow

  19. 19

    Keras Dense layer shape error

  20. 20

    ValueError:Tensor Tensor( "Const:0"、shape =()、dtype = float32)にtf.placeholderを指定できない場合があります

  21. 21

    Tensor Tensor( "predictions / Softmax:0"、shape =(?, 1000)、dtype = float32)はこのグラフの要素ではありません

  22. 22

    How to reshape (None, 10)-dimensional tensor to (None, None, 10) in Keras?

  23. 23

    LSTM network expects target at last layer to have 2 dimensions, but got array with shape (996, 1, 1)

  24. 24

    How can I create a numpy array with shape (0, 2)?

  25. 25

    Why Tensorflow error: `failed to convert object of type <class 'dict'> to Tensor` happens and How can I solve it?

  26. 26

    TensorFlow Dataset: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

  27. 27

    Creating tensorflow::Tensor from Eigen::Tensor

  28. 28

    '(slice(None, None, None), 0)' is an invalid key

  29. 29

    Keras: ValueError: Input 0 of layer sequential_1 is incompatible with the layer: expected ndim=3, found ndim=2

ホットタグ

アーカイブ