Layout Detection Models

class layoutparser.models.Detectron2LayoutModel(config_path, model_path=None, label_map=None, extra_config=[])[source]

Bases: layoutparser.models.layoutmodel.BaseLayoutModel

Create a Detectron2-based Layout Detection Model

Parameters
  • config_path (str) – The path to the configuration file.

  • model_path (str, None) – The path to the saved weights of the model. If set, overwrite the weights in the configuration file. Defaults to None.

  • label_map (dict, optional) – The map from the model prediction (ids) to real word labels (strings). Defaults to None.

  • extra_config (list, optional) – Extra configuration passed to the Detectron2 model configuration. The argument will be used in the merge_from_list function. Defaults to [].

Examples::
>>> import layoutparser as lp
>>> model = lp.models.Detectron2LayoutModel('lp://HJDataset/faster_rcnn_R_50_FPN_3x/config')
>>> model.detect(image)
DEPENDENCIES = ['detectron2']
MODULES = [{'import_name': '_engine', 'module_path': 'detectron2.engine'}, {'import_name': '_config', 'module_path': 'detectron2.config'}]
gather_output(outputs)[source]
detect(image)[source]

Detect the layout of a given image.

Parameters

image (np.ndarray or PIL.Image) – The input image to detect.

Returns

The detected layout of the input image

Return type

Layout