Layout Detection Models

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

Bases: layoutparser.models.base_layoutmodel.BaseLayoutModel

Create a Detectron2-based Layout Detection Model

  • 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). If the config is from one of the supported datasets, Layout Parser will automatically initialize the label_map. Defaults to None.

  • device (str, optional) – Whether to use cuda or cpu devices. If not set, LayoutParser will automatically determine the device to initialize the models on.

  • 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 [].

>>> import layoutparser as lp
>>> model = lp.Detectron2LayoutModel('lp://HJDataset/faster_rcnn_R_50_FPN_3x/config')
>>> model.detect(image)
DEPENDENCIES = ['detectron2']
DETECTOR_NAME = 'detectron2'
MODEL_CATALOG = {'HJDataset': {'faster_rcnn_R_50_FPN_3x': '', 'mask_rcnn_R_50_FPN_3x': '', 'retinanet_R_50_FPN_3x': ''}, 'MFD': {'faster_rcnn_R_50_FPN_3x': ''}, 'NewspaperNavigator': {'faster_rcnn_R_50_FPN_3x': ''}, 'PrimaLayout': {'mask_rcnn_R_50_FPN_3x': ''}, 'PubLayNet': {'faster_rcnn_R_50_FPN_3x': '', 'mask_rcnn_R_50_FPN_3x': '', 'mask_rcnn_X_101_32x8d_FPN_3x': ''}, 'TableBank': {'faster_rcnn_R_101_FPN_3x': '', 'faster_rcnn_R_50_FPN_3x': ''}}

Detect the layout of a given image.


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


The detected layout of the input image

Return type


image_loader(image: Union[np.ndarray, Image.Image])[source]

It will process the input images appropriately to the target format.