Reputation: 115
In my code I am getting this error. How I can solve it?
ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name='input_2'), name='input_2', description="created by layer 'input_2'") at layer "conv1_pad". The following previous layers were accessed without issue: []
My model is
def multiple_outputs(generator):
for batch_x,batch_y in generator:
yield (batch_x, np.hsplit(batch_y,[26,28])) #here splitting input data into 6 groups
image_input = Input(shape=(input_size))
base_model =ResNet50(weights='imagenet',include_top=False)
m = base_model.output
x = GlobalAveragePooling2D(name='avg_pool')(m)
x = Dropout(0.2)(x)
type_out = Dense(26, activation='sigmoid', name='type_output')(x)
top_out = Dense(3, activation='softmax', name='top_output')(x)
model = Model(inputs=image_input,outputs= [type_out, top_out])
following I have mentioned model.fit
section
history = model.fit(x=multiple_outputs(train_generator),
steps_per_epoch=STEP_SIZE_TRAIN,
validation_data=multiple_outputs(valid_generator),
validation_steps=STEP_SIZE_VALID,
callbacks=callbacks,
max_queue_size=10,
workers=1,
use_multiprocessing=False,
epochs=1)
Please, can someone help me in solving this issue?
Upvotes: 1
Views: 223
Reputation: 115
Answer is, here I have done a mistake in model initialization. Input_tensor should be added in model initialization.
base_model = ResNet50(weights='imagenet', include_top=False, input_tensor=image_input)
Upvotes: 2
Reputation: 519
The answer lies in carefully going through your Model Architecture and the nature of the error that you are getting.
Here your image_input is not connected to the rest part of your model
image_input = Input(shape=(input_size))
In the rest of your code you can see that every layer is connected to every other layer and you can traverse from each of your layer to the output But input_image is not connected to any of them
base_model =ResNet50(weights='imagenet',include_top=False)
m = base_model.output
x = GlobalAveragePooling2D(name='avg_pool')(m)
x = Dropout(0.2)(x)
type_out = Dense(26, activation='sigmoid', name='type_output')(x)
top_out = Dense(3, activation='softmax', name='top_output')(x)
bottom_out = Dense(8, activation='softmax', name='bottom_output')(x)
headwear_out = Dense(3, activation='softmax', name='headwear_output')(x)
footwear_out = Dense(3, activation='softmax', name='footwear_output')(x)
sleeve_out = Dense(5, activation='softmax', name='sleeve_output')(x)
gender_out = Dense(3, activation='softmax', name='gender_output')(x)
But in your model you are trying to take inputs=input_image
and outputs=[type_out, top_out, bottom_out, headwear_out, footwear_out, sleeve_out, gender_out]
But since your input_image
is not connected at all the model has a disconnected graph with it.
So, try and connect your input_image
layer with that of base_model
or in whatever fashion you want and the graph will be connected.
Upvotes: 3