question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Graph disconnected: cannot obtain value for tensor Tensor

See original GitHub issue

Hi All,

I am trying to add the last layer’s output of one model to last layer’s output of another model as below.

class Student(object):

    def build(self, rgb, alpha, teacher):
        shape = (1, 1, int(1024 * alpha))
        """
        This looks dangerous. Not sure how the model would get affected with the laarning_phase variable set to True.
        """
        K.set_learning_phase(True)
        img_input = Input(shape=(32,32,3))

        conv = _conv_block(img_input, 32, alpha, strides=(2, 2))
        conv = _depthwise_conv_block(conv, 64, alpha, depth_multiplier, block_id =1)
        conv = _depthwise_conv_block(conv, 128, alpha, depth_multiplier,strides=(2, 2), block_id =2)
        conv = _depthwise_conv_block(conv, 128, alpha, depth_multiplier,block_id =3)
        conv = _depthwise_conv_block(conv, 256, alpha, depth_multiplier, strides=(2,2),block_id =4)
        conv = _depthwise_conv_block(conv, 256, alpha, depth_multiplier, block_id =5)
        conv = _depthwise_conv_block(conv, 512, alpha, depth_multiplier, strides = (2,2), block_id =6)
        conv = _depthwise_conv_block(conv, 512, alpha, depth_multiplier, block_id =8)
        conv = _depthwise_conv_block(conv, 512, alpha, depth_multiplier, block_id =9)
        conv = _depthwise_conv_block(conv, 512, alpha, depth_multiplier, block_id =10)
        conv = _depthwise_conv_block(conv, 512, alpha, depth_multiplier, block_id =11)
        conv = _depthwise_conv_block(conv, 512, alpha, depth_multiplier, block_id =12)
        conv = _depthwise_conv_block(conv, 1024, alpha, depth_multiplier,strides=(2,2), block_id =13)
        conv = _depthwise_conv_block(conv, 1024, alpha, depth_multiplier, block_id =14)

        conv = GlobalAveragePooling2D()(conv)
        conv = Reshape(shape, name='reshape_1')(conv)

        conv = Dropout(0.5, name='dropout')(conv)
        conv = Conv2D(NUM_CLASSES, (1, 1), padding='same', name='conv_preds')(conv)
        conv = Activation('softmax', name='act_softmax')(conv)
        conv = Reshape((NUM_CLASSES,), name='reshape_2')(conv)
        conv = add([conv, teacher.layers[87].output], name='add')
        model = Model(img_input, conv)
        return model

I am passing the teacher object to student build function, so that I can access teacher’s last layer output. I have used add layer to add element wise tensors of teacher and student.

But I am seeing below error. ValueError: Graph disconnected: cannot obtain value for tensor Tensor(“input_1:0”, shape=(?, 32, 32, 3), dtype=float32) at layer “input_1”. The following previous layers were accessed without issue: [] Does someone knows the issue?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

17reactions
B-Yassinecommented, May 5, 2019

I had the same issue and i solved it by constracting my merged model as follow:

mergedModel = Model(inputs=[firstModel.input, secondModel.input], outputs=secondModel.layers[-1].output)

Hope it will help 😉

4reactions
schliffencommented, Sep 25, 2018

Im trying to merge pretrained mobilenet with my model, the same error appeared:

ValueError: Graph disconnected: cannot obtain value for tensor Tensor(“dense_1_input:0”, shape=(?, 1024), dtype=float32) at layer “dense_1_input”. The following previous layers were accessed without issue: []

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot obtain value for tensor Tensor Input Keras Python
The inputs can cause this error. If you've gotten this "graph disconnected" error double check to make sure you're including all of the...
Read more >
Graph disconnected: cannot obtain value for tensor ... - GitHub
Hi,I've met the same error. Could you please tell me how to solve it? Thanks!
Read more >
Problem "Graph disconnected" - TensorFlow Forum
I'm new with Tensorflow and I'm working with a particular representation. ... ValueError: Graph disconnected: cannot obtain value for tensor ...
Read more >
ValueError: Graph disconnected - How to split a keras model ...
I could not get your example to run. Here is a code sample where a new model built from parts of an existing...
Read more >
Graph disconnected: cannot obtain value for tensor Tensor
My Problem is when I pass concatenated_input to convolution layers it gets me the following error. Graph disconnected: cannot obtain value for tensor...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found