experiencor / keras-yolo2

Easy training on custom dataset. Various backends (MobileNet and SqueezeNet) supported. A YOLO demo to detect raccoon run entirely in brower is accessible at https://git.io/vF7vI (not on Windows).
MIT License
1.73k stars 787 forks source link

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

Open PRBtc opened 3 years ago

PRBtc commented 3 years ago

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 commented 2 years ago

+1

EduardoHT commented 2 years ago

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}.