def _generate_model(self): '''to generate the bounding boxes''' weights_path = os.path.expanduser(self.weights_path) assert weights_path.endswith( '.h5'), 'Keras model or weights must be a .h5 file.' # Load model, or construct model and load weights. num_anchors = len(self.anchors) num_classes = len(self.class_names) #YOLOv3 model has 9 anchors and 3 feature layers but #Tiny YOLOv3 model has 6 anchors and 2 feature layers, #so we can calculate feature layers number to get model type num_feature_layers = num_anchors // 3 if num_anchors == 5: # YOLOv2 use 5 anchors inference_model = get_yolo2_inference_model( self.model_type, self.anchors, num_classes, weights_path=weights_path, input_shape=self.model_image_size + (3, ), confidence=0.1) else: inference_model = get_yolo3_inference_model( self.model_type, self.anchors, num_classes, weights_path=weights_path, input_shape=self.model_image_size + (3, ), confidence=0.1) inference_model.summary() return inference_model
def _generate_model(self): '''to generate the bounding boxes''' weights_path = os.path.expanduser(self.weights_path) assert weights_path.endswith( '.h5'), 'Keras model or weights must be a .h5 file.' # Load model, or construct model and load weights. num_anchors = len(self.anchors) num_classes = len(self.class_names) #YOLOv3 model has 9 anchors and 3 feature layers but #Tiny YOLOv3 model has 6 anchors and 2 feature layers, #so we can calculate feature layers number to get model type num_feature_layers = num_anchors // 3 if self.model_type.startswith( 'scaled_yolo4_') or self.model_type.startswith('yolo5_'): # Scaled-YOLOv4 & YOLOv5 entrance, enable "elim_grid_sense" by default inference_model = get_yolo5_inference_model( self.model_type, self.anchors, num_classes, weights_path=weights_path, input_shape=self.model_image_size + (3, ), confidence=self.score, iou_threshold=self.iou, elim_grid_sense=True) elif self.model_type.startswith('yolo3_') or self.model_type.startswith('yolo4_') or \ self.model_type.startswith('tiny_yolo3_') or self.model_type.startswith('tiny_yolo4_'): # YOLOv3 & v4 entrance inference_model = get_yolo3_inference_model( self.model_type, self.anchors, num_classes, weights_path=weights_path, input_shape=self.model_image_size + (3, ), confidence=self.score, iou_threshold=self.iou, elim_grid_sense=self.elim_grid_sense) elif self.model_type.startswith( 'yolo2_') or self.model_type.startswith('tiny_yolo2_'): # YOLOv2 entrance inference_model = get_yolo2_inference_model( self.model_type, self.anchors, num_classes, weights_path=weights_path, input_shape=self.model_image_size + (3, ), confidence=self.score, iou_threshold=self.iou, elim_grid_sense=self.elim_grid_sense) else: raise ValueError('Unsupported model type') inference_model.summary() return inference_model