<jupyter_start><jupyter_text>Load the modelYou can simply load the model and the function is going to assume that the model is saved at the standard path. Otherwise you can specify a different path.<jupyter_code># Simply load the model 
model = load_model()
# You can also specify a different model path:
#model = load_model(path = 'model_trained/mask_rcnn_molecule.h5')<jupyter_output>WARNING:tensorflow:From C:\Users\<NAME>\anaconda3\envs\DECIMER_IMGSEG\lib\site-packages\tensorflow\python\util\deprecation.py:574: calling map_fn_v2 (from tensorflow.python.ops.map_fn) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Use fn_output_signature instead<jupyter_text>Define pdf path and convert to imagePlease uncomment according to the system you are using. If you are using Windows, make sure, poppler is installed properly.On Linux and MacOS, this should work properly without any problems.  Uncomment below according to your needs.<jupyter_code>path = os.path.abspath('./Validation/test_page.pdf')

#If you are using Windows, make sure to have poppler installed and show pdf2image where to find it. 
#poppler_path = r"C:\Program Files (x86)\poppler-0.68.0\bin"  # CHANGE PATH
#pages = convert_from_path(path, 500, poppler_path = poppler_path)

# If you are using Linux or MacOS, this should hopefully have been installed via conda/pip.
# In that case, you just run:
#pages = convert_from_path(path, 500)<jupyter_output><empty_output><jupyter_text>Run the detection using the Mask R CNN model<jupyter_code>image = np.asarray(pages[0])
results = model.detect([image], verbose=1)
r = results[0]<jupyter_output>WARNING:tensorflow:From C:\Users\<NAME>\anaconda3\envs\DECIMER_IMGSEG\lib\site-packages\tensorflow\python\keras\engine\training_v1.py:2070: Model.state_updates (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.
Instructions for updating:
This property should not be used in TensorFlow 2.0, as updates are applied automatically.<jupyter_text>Visualize the masks resultsAs you can see below, the model alone performs relatively well but the lower structure is not covered completely by its mask.<jupyter_code>visualize.display_instances(image = image, 
                             masks = r['masks'], 
                             class_ids = r["class_ids"], 
                             boxes = r['rois'],
                            class_names = ['structure', 'structure'])<jupyter_output><empty_output><jupyter_text>Run the mask expansionIf the debug parameter is set to True, the results of the binarization and the dilation are shown.<jupyter_code>exp_masks = complete_structure_mask(image, r['masks'], debug = True)<jupyter_output><empty_output><jupyter_text>Visualize results after mask expansionAs you can see below, the masks in the final output are significantly slimmer and cover the complete structures.<jupyter_code>visualize.display_instances(image = image, 
                             masks = exp_masks, 
                             class_ids = r["class_ids"], 
                             boxes = r['rois'],
                             class_names = ['structure', 'structure'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08289514382926075, 'fraction_numerical': 0.009279307145066501, 'mean_word_length': 4.053125, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '541310', 'license': 'MIT', 'n_tokens_mistral': 950, 'n_tokens_neox': 917, 'n_words': 301, 'path': 'DECIMER_Segmentation_notebook.ipynb', 'repo_name': 'Kohulan/DECIMER-Image-Segmentation', 'size': '3249'}