@@ -17,7 +17,32 @@ def detect(self): pass
1717
1818
1919class Detectron2LayoutModel (BaseLayoutModel ):
20-
20+ """Create a Detectron2-based Layout Detection Model
21+
22+ Args:
23+ config_path (:obj:`str`):
24+ The path to the configuration file.
25+ model_path (:obj:`str`, None):
26+ The path to the saved weights of the model.
27+ If set, overwrite the weights in the configuration file.
28+ Defaults to `None`.
29+ label_map (:obj:`dict`, optional):
30+ The map from the model prediction (ids) to real
31+ word labels (strings).
32+ Defaults to `None`.
33+ extra_config (:obj:`list`, optional):
34+ Extra configuration passed to the Detectron2 model
35+ configuration. The argument will be used in the `merge_from_list
36+ <https://detectron2.readthedocs.io/modules/config.html
37+ #detectron2.config.CfgNode.merge_from_list>`_ function.
38+ Defaults to `[]`.
39+
40+ Examples::
41+ >>> import layoutparser as lp
42+ >>> model = lp.models.Detectron2LayoutModel('lp://HJDataset/faster_rcnn_R_50_FPN_3x/config')
43+ >>> model.detect(image)
44+
45+ """
2146 def __init__ (self , config_path ,
2247 model_path = None ,
2348 label_map = None ,
@@ -63,7 +88,14 @@ def _create_model(self):
6388 self .model = DefaultPredictor (self .cfg )
6489
6590 def detect (self , image ):
91+ """Detect the layout of a given image.
92+
93+ Args:
94+ image (:obj:`np.ndarray`): The input image to detect.
6695
96+ Returns:
97+ :obj:`~layoutparser.Layout`: The detected layout of the input image
98+ """
6799 outputs = self .model (image )
68100 layout = self .gather_output (outputs )
69101 return layout
0 commit comments