Views
No views yet
NUM_CLASSES: 69+1 (background)DETECTION_MIN_CONFIDENCE: 0.76crucifixionangelcrown of thornsmonkswordchalicedovelion, shepherd, scroll, key of heaven, mitre, and moreFull class list is available in the source notebook.
1from mrcnn.config import Config
2from mrcnn.model import MaskRCNN
3from mrcnn.model import mold_image
4from keras.preprocessing.image import load_img, img_to_array
5from numpy import expand_dims
6import matplotlib.pyplot as plt
7from matplotlib.patches import Rectangle
8
9# Define class labels (shortened list)
10classids=["BG","crucifixion","angel","person","crown of thorns", "horse", "dragon","bird","dog","boat","cat","book",
11 "sheep","shepherd","elephant","zebra","crown","tiara","camauro","zucchetto","mitre","saturno","skull",
12 "orange","apple","banana","nude","monk","lance","key of heaven", "banner","chalice","palm","sword","rooster",
13 "knight","scroll","lily","horn","prayer","tree","arrow","crozier","deer","devil","dove","eagle","hands",
14 "head","lion","serpent","stole","trumpet","judith","halo","helmet","shield","jug","holy shroud","god the father",
15 "swan", "butterfly", "bear", "centaur","pegasus","donkey","mouse","monkey","cow","unicorn"]
16
17# Define the inference config
18class PredictionConfig(Config):
19 NAME = "PREDICTION_cfg"
20 NUM_CLASSES = len(classids)
21 GPU_COUNT = 1
22 IMAGES_PER_GPU = 1
23 DETECTION_MIN_CONFIDENCE = 0.76
24
25# Initialize model
26cfg = PredictionConfig()
27model = MaskRCNN(mode='inference', model_dir='./', config=cfg)
28model.load_weights('<weights of model>', by_name=True)
29
30# Load and process image
31img = load_img("example.jpg")
32image = img_to_array(img)
33scaled_image = mold_image(image, cfg)
34sample = expand_dims(scaled_image, 0)
35
36# Run detection
37yhat = model.detect(sample, verbose=0)[0]
38
39# Visualize detections
40fig = plt.figure(figsize=(12, 12))
41ax = fig.add_subplot(111)
42ax.imshow(img)
43for i in range(len(yhat['rois'])):
44 y1, x1, y2, x2 = yhat['rois'][i]
45 width, height = x2 - x1, y2 - y1
46 rect = Rectangle((x1, y1), width, height, fill=False, color='red')
47 ax.add_patch(rect)
48 ax.text(x1 + 5, y1 + 10, classids[yhat['class_ids'][i]], fontsize=12, color='white')
49plt.show()@misc{reshetnikov2022deartdataseteuropeanart,
title={DEArt: Dataset of European Art},
author={Artem Reshetnikov and Maria-Cristina Marinescu and Joaquim More Lopez},
year={2022},
eprint={2211.01226},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2211.01226},
}