big_transfer icon indicating copy to clipboard operation
big_transfer copied to clipboard

AttributeError: Layer block2 has no inbound nodes.

Open himanshurawlani opened this issue 5 years ago • 0 comments

I'm trying to build an FPN network using the ResnetV2 backbone as implemented in TF2 models.py here. I have appended the below lines to the models.py:

if __name__ == "__main__":
	args_model = "BiT-M-R50x1"
	model = ResnetV2(
			num_units=NUM_UNITS[args_model],
			# num_outputs=21843,
			num_outputs=None,
			filters_factor=int(args_model[-1])*4,
			name="resnet",
			trainable=True,
			dtype=tf.float32)

	model.build((None, None, None, 3))
	
	# Get output layers.
	layer_names = ["block2", "block3", "block4"]
	layer_outputs = [model.get_layer(name).output for name in layer_names]
	for layer in layer_outputs:
		print(layer.shape)

I need to get the output of intermediate layers like block2, block3, and block4 in order to build the FPN pyramid, but while fetching the output of these layers I get the following error:

Traceback (most recent call last):
  File ".../big_transfer/bit_tf2/models.py", line 301, in <module>
    layer_outputs = [model.get_layer(name).output for name in layer_names]
  File ".../big_transfer/bit_tf2/models.py", line 301, in <listcomp>
    layer_outputs = [model.get_layer(name).output for name in layer_names]
  File "/home/himanshu/.conda/envs/tf2/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1827, in output
    raise AttributeError('Layer ' + self.name + ' has no inbound nodes.')
AttributeError: Layer block2 has no inbound nodes.

I want to use the pre-trained weights to initialize the FPN network later and hence didn't make any changes to the model code. Any suggestions on how do I solve this error?

himanshurawlani avatar Jul 31 '20 19:07 himanshurawlani