<jupyter_start><jupyter_text>Show Output from 50 Epoch Results<jupyter_code># Load the libraries
import os
import sys
import random
import matplotlib
import matplotlib.pyplot as plt
import glob
import skimage

# Import Mask RCNN from Matterport
from mrcnn import utils
from mrcnn import visualize
from mrcnn.visualize import display_images
from mrcnn import model
import mrcnn.model as modellib
from mrcnn.model import log
import custom

import tensorflow as tf

%matplotlib inline
# Supress Warnings
import warnings
warnings.filterwarnings('ignore')
# Root directory of the project
ROOT_DIR = os.getcwd()
sys.path.append(ROOT_DIR)  # To find local version of the library
MODEL_DIR = os.path.join(ROOT_DIR, "logs")
config = custom.CustomConfig()
custom_DIR = os.path.join(ROOT_DIR, "custom/")
custom_WEIGHTS_PATH = os.path.join(MODEL_DIR, "damage20200407T1358/mask_rcnn_damage_0050.h5")<jupyter_output><empty_output><jupyter_text>Run Model For Inference  Setup Environment<jupyter_code>config = custom.CustomConfig()
CUSTOM_DIR = os.path.join(ROOT_DIR + "/custom/")
class InferenceConfig(config.__class__):
    # Run detection on one image at a time
    GPU_COUNT = 1
    IMAGES_PER_GPU = 1

config = InferenceConfig()
DEVICE = "/gpu:1"
TEST_MODE = "inference"<jupyter_output><empty_output><jupyter_text>Show Example Preidcted Images for Unseen Data<jupyter_code>%matplotlib inline

val_dir = CUSTOM_DIR + 'test/'
filelist = glob.glob(os.path.join(val_dir, '*.JPEG'))

# Create model in inference mode   
with tf.device(DEVICE):
    model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
    
model.load_weights(custom_WEIGHTS_PATH, by_name=True) 

# Get a random image
image_id = random.choice(filelist)
image = skimage.io.imread(image_id)  

# Get the prediction results for the random image
results = model.detect([image], verbose=1)
r = results[0]

# Show the original and MASKed image next to each other
fig, ax = plt.subplots(1, 2, figsize=(20, 5))

# original image
ax[0].set_axis_off()
ax[0].imshow(image)

# MASKed image
visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], 
                    'damage', r['scores'], ax=ax[1],
                    title="Predictions")<jupyter_output>Re-starting from epoch 50
Processing 1 images
image                    shape: (183, 276, 3)         min:    0.00000  max:  255.00000  uint8
molded_images            shape: (1, 1024, 1024, 3)    min: -123.70000  max:  151.10000  float64
image_metas              shape: (1, 14)               min:    0.00000  max: 1024.00000  float64
anchors                  shape: (1, 261888, 4)        min:   -0.35390  max:    1.29134  float32
{'fraction_non_alphanumeric': 0.10090022505626407, 'fraction_numerical': 0.047636909227306824, 'mean_word_length': 4.0896946564885495, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '36396', 'license': 'MIT', 'n_tokens_mistral': 1000, 'n_tokens_neox': 902, 'n_words': 245, 'path': 'example_images.ipynb', 'repo_name': 'SextonCJ/maskRCNN', 'size': '2666'}