Graph disconnected: cannot obtain value for tensor Tensor

Roshni Amber

I have to train a GAN network with Generator and Discriminator. My Generator Network is as below.

def Generator(image_shape=(512,512,3):
  inputs = Input(image_shape)
  # 5 convolution Layers
  # 5 Deconvolution Layers along with concatenation
  # output shape is (512,512,3) 
  model=Model(inputs=inputs,outputs=outputs, name='Generator')
  return model, output

My Discriminator Network is as below. The first step in Discriminator network is that I have to concatenate the input of discriminator with output of Generator.

def Discriminator(Generator_output, image_shape=(512,512,3)):
  inputs=Input(image_shape)
  concatenated_input=concatenate([Generator_output, inputs], axis=-1)
  # Now start applying Convolution Layers on concatenated_input
  # Deconvolution Layers
  return Model(inputs=inputs,outputs=outputs, name='Discriminator')

Initiating the Architectures

G, Generator_output=Generator(image_shape=(512,512,3))
G.summary

D=Discriminator(Generator_output, image_shape=(512,512,3))
D.summary()

My Problem is when I pass concatenated_input to convolution layers it gets me the following error.

Graph disconnected: cannot obtain value for tensor Tensor("input_1:0", shape=(?, 512, 512, 3), dtype=float32) at layer "input_1". The following previous layers were accessed without issue: []

If I remove the concatenation layer it works perfectly but why it's not working after concatenation layer although the shape of inputs and Generator_output in concatenation is also same i.e. (512,512,3).

nuric

The key insight that will help you here is that Models are just like layers in Keras but self contained. So to connect one model output to another, you need to say the second model receieves an input of matching shape rather than directly passing that tensor:

def Discriminator(gen_output_shape, image_shape=(512,512,3)):
  inputs=Input(image_shape)
  gen_output=Input(gen_output_shape)
  concatenated_input=concatenate([gen_output, inputs], axis=-1)
  # Now start applying Convolution Layers on concatenated_input
  # Deconvolution Layers
  return Model(inputs=[inputs, gen_output],outputs=outputs, name='Discriminator')

And then you can use it like a layer:

G=Generator(image_shape=(512,512,3))
D=Discriminator((512,512,3), image_shape=(512,512,3))
some_other_image_input = Input((512,512,3))
discriminator_output = D(some_other_image_input, G) # model is used like a layer
# so the output of G is connected to the input of D
D.summary()
gan = Model(inputs=[all,your,inputs], outputs=[outputs,for,training])
# you can still use G and D like separate models, save them, train them etc

To train them together you can create another Model that has all the required inputs, calls the generator / discriminator. Think of using a lock and key idea, every model has some inputs and you can use them like layers in another Model so long you provide the correct inputs.

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

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

編集
0

コメントを追加

0

関連記事

分類Dev

How to get the value of a tensor? Python

分類Dev

Save a Hash Value as a Tensor in pytorch

分類Dev

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

分類Dev

Tensorflow: Cannot interpret feed_dict key as Tensor

分類Dev

How to get value from a theano tensor variable backed by a shared variable?

分類Dev

tensorflow set block within 2d tensor to constant value

分類Dev

tensorflow InvalidArgumentError: "You must feed a value for placeholder tensor"

分類Dev

How to process different row in tensor based on the first column value in tensorflow

分類Dev

Android - TFLite OD - Cannot copy to a TensorFlowLite tensor (normalized_input_image_tensor) with 307200 bytes from a Java Buffer with 4320000 bytes

分類Dev

Creating tensorflow::Tensor from Eigen::Tensor

分類Dev

Given a tensor flow model graph, how to find the input node and output node names

分類Dev

Tensorflow: applying an imported graph operation to each element of 2d tensor

分類Dev

OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution. Add Metrics to compile function

分類Dev

reshaping a tensor with padding in pytorch

分類Dev

Slicing tensor with list - TensorFlow

分類Dev

Drop a dimension of a tensor in Tensorflow

分類Dev

Transform a tensor into another

分類Dev

Slice tensor in Keras Tensorflow

分類Dev

Extract tensor from string

分類Dev

How to index a tensor in a for loop?

分類Dev

Clip parts of a tensor

分類Dev

How to fill a tensor of values based on tensor of indices in tensorflow?

分類Dev

Keras: Construct a full tensor of the same batch size as a given tensor

分類Dev

Indexando um tensor multidimensional com um tensor em PyTorch

分類Dev

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

分類Dev

Having trouble extracting the string value from a tensor with datatype tf.string

分類Dev

Why does multiple calls to a tensor change its value each time using reshape

分類Dev

Vectorized computation of numpys tensor dot

分類Dev

Replicate Kronecker tensor with repmat in MATLAB

Related 関連記事

  1. 1

    How to get the value of a tensor? Python

  2. 2

    Save a Hash Value as a Tensor in pytorch

  3. 3

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

  4. 4

    Tensorflow: Cannot interpret feed_dict key as Tensor

  5. 5

    How to get value from a theano tensor variable backed by a shared variable?

  6. 6

    tensorflow set block within 2d tensor to constant value

  7. 7

    tensorflow InvalidArgumentError: "You must feed a value for placeholder tensor"

  8. 8

    How to process different row in tensor based on the first column value in tensorflow

  9. 9

    Android - TFLite OD - Cannot copy to a TensorFlowLite tensor (normalized_input_image_tensor) with 307200 bytes from a Java Buffer with 4320000 bytes

  10. 10

    Creating tensorflow::Tensor from Eigen::Tensor

  11. 11

    Given a tensor flow model graph, how to find the input node and output node names

  12. 12

    Tensorflow: applying an imported graph operation to each element of 2d tensor

  13. 13

    OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution. Add Metrics to compile function

  14. 14

    reshaping a tensor with padding in pytorch

  15. 15

    Slicing tensor with list - TensorFlow

  16. 16

    Drop a dimension of a tensor in Tensorflow

  17. 17

    Transform a tensor into another

  18. 18

    Slice tensor in Keras Tensorflow

  19. 19

    Extract tensor from string

  20. 20

    How to index a tensor in a for loop?

  21. 21

    Clip parts of a tensor

  22. 22

    How to fill a tensor of values based on tensor of indices in tensorflow?

  23. 23

    Keras: Construct a full tensor of the same batch size as a given tensor

  24. 24

    Indexando um tensor multidimensional com um tensor em PyTorch

  25. 25

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

  26. 26

    Having trouble extracting the string value from a tensor with datatype tf.string

  27. 27

    Why does multiple calls to a tensor change its value each time using reshape

  28. 28

    Vectorized computation of numpys tensor dot

  29. 29

    Replicate Kronecker tensor with repmat in MATLAB

ホットタグ

アーカイブ