Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. from mrcnn.model import MaskRCNN
  2. from mrcnn.config import Config
  3. import numpy as np
  4. import cv2
  5.  
  6. class_list = [
  7.         'large_bolt',
  8.         'short_bolt',
  9.         'main_housing',
  10.         'bearing_sealing',
  11.         'top_lid',
  12.         'cup',
  13.         'cylinder_flat',
  14.         'cylinder_long',
  15.         'cylinder_medium',
  16.         'cylinder_short',
  17.         'rotor_female',
  18.         'rotor_male',
  19.         'washer',
  20.     ]
  21.  
  22. class PredictionConfig(Config):
  23.     NAME = "prediction_cfg"
  24.     NUM_CLASSES = len(class_list) + 1
  25.     GPU_COUNT = 1
  26.     IMAGES_PER_GPU = 1
  27.     RPN_ANCHOR_RATIOS = [0.55, 1.0, 1.57]
  28.    
  29. model_file = 'MaskRCNN_C40.h5'
  30.  
  31. config = PredictionConfig()
  32. model = MaskRCNN(mode='inference', config=config, model_dir='/logs')
  33. model.load_weights(model_file, by_name=True)
  34.  
  35. image = cv2.imread('test.jpg')
  36. sample = np.expand_dims(image, 0)
  37. result = model.detect(sample, verbose=0)[0]
  38.  
  39. detections = []
  40. for roi, class_id, score in zip(result['rois'], result['class_ids'], result['scores']):
  41.     class_name = class_list[class_id - 1]
  42.     print("Class:", class_name)
  43.     print("ROI:")
  44.     print(roi)
  45.     print("Score:", score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement