Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: The layer has never been called and thus has no defined output shape. #462

Open
PRBtc opened this issue Dec 7, 2020 · 2 comments

Comments

@PRBtc
Copy link

PRBtc commented Dec 7, 2020

Hi I trying to train train.py with backend model as Full Yolo or ResNet50. But I encounter the following error. CCould you please let me know what could be the error here. tHanks

Traceback (most recent call last):
File "train.py", line 101, in
main(args)
File "train.py", line 70, in main
anchors = config['model']['anchors'])
File "/Users/priyanka/Desktop/Yolo/YOLO_V2_Resnet/keras-yolo2/frontend.py", line 60, in init
print(self.feature_extractor.get_output_shape())
File "/Users/priyanka/Desktop/Yolo/YOLO_V2_Resnet/keras-yolo2/backend.py", line 33, in get_output_shape
return self.feature_extractor.get_output_shape_at(-1)[1:3]
File "//anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 2040, in get_output_shape_at
'output shape')
File "//anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 2631, in _get_node_attribute_at_index
'and thus has no defined ' + attr_name + '.')
RuntimeError: The layer has never been called and thus has no defined output shape.

@jia0511
Copy link

jia0511 commented Aug 6, 2021

+1

@EduardoHT
Copy link

with open(config_path) as config_buffer:
config = json.load(config_buffer)

###############################

Make the model

###############################

yolo = YOLO(backend = config['model']['backend'],
input_size = config['model']['input_size'],
labels = config['model']['labels'],
max_box_per_image = config['model']['max_box_per_image'],
anchors = config['model']['anchors'])

###############################

Load trained weights

###############################

yolo.load_weights(weights_path)

Output:::::::::::::::::::::::::::::::::

RuntimeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_6012/3719954046.py in
6 ###############################
7
----> 8 yolo = YOLO(backend = config['model']['backend'],
9 input_size = config['model']['input_size'],
10 labels = config['model']['labels'],

~\Eduardo\ModelosProntosSingapura\keras-yolo2-master\frontend.py in init(self, backend, input_size, labels, max_box_per_image, anchors)
56 raise Exception('Architecture not supported! Only support Full Yolo, Tiny Yolo, MobileNet, SqueezeNet, VGG16, ResNet50, and Inception3 at the moment!')
57
---> 58 print(self.feature_extractor.get_output_shape())
59 self.grid_h, self.grid_w = self.feature_extractor.get_output_shape()
60 features = self.feature_extractor.extract(input_image)

~\Eduardo\ModelosProntosSingapura\keras-yolo2-master\backend.py in get_output_shape(self)
29
30 def get_output_shape(self):
---> 31 return self.feature_extractor.get_output_shape_at(-1)[1:3]
32
33 def extract(self, input_image):

~\Anaconda3\envs\TesteComYolo\lib\site-packages\keras\engine\base_layer.py in get_output_shape_at(self, node_index)
2075 RuntimeError: If called in Eager mode.
2076 """
-> 2077 return self._get_node_attribute_at_index(node_index, 'output_shapes',
2078 'output shape')
2079

~\Anaconda3\envs\TesteComYolo\lib\site-packages\keras\engine\base_layer.py in _get_node_attribute_at_index(self, node_index, attr, attr_name)
2681 """
2682 if not self._inbound_nodes:
-> 2683 raise RuntimeError(f'The layer {self.name} has never been called '
2684 'and thus has no defined {attr_name}.')
2685 if not len(self._inbound_nodes) > node_index:

RuntimeError: The layer model has never been called and thus has no defined {attr_name}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants