def __init__(self, model_file): if isinstance(model_file, str): # load retinanet model inference_config = InferenceConfig() # config.BATCH_SIZE = 1 # len(image) must match BATCH_SIZE print('loading model:', model_file) model = modellib.MaskRCNN(mode="inference", config=inference_config) model.load_weights(model_file, by_name=True) print('load model complete:', model_file) self.model = model else: self.model = model_file
epochs=10, #20 augmentation=imgaug_seq, layers='heads') print("Train all layers") model.train(dataset_train, dataset_val, learning_rate=config.LEARNING_RATE2, epochs=40, augmentation=imgaug_seq, layers='all') # Create model # Configurations config = OpticDiscConfig() config.display() model = modellib.MaskRCNN(mode="training", config=config, model_dir='/tmp4/OpticDiscMaskRCNN') WEIGHTS_PATH = os.path.join(sys.path[0], 'weights', 'mask_rcnn_opticdisc_0018_0.234.h5') model.load_weights(WEIGHTS_PATH, by_name=True) # Training train(model) print('OK')
import sys sys.path.append(os.path.abspath('../')) sys.path.append(os.path.abspath('../../')) import cv2 from OpticDiscDetection.Mask_RCNN.optic_disc.helper.my_optic_disc_config import OpticDiscConfig from OpticDiscDetection.Mask_RCNN.optic_disc.helper.my_seg_optic_disc import seg_optic_disc, optic_disc_draw_circle, crop_posterior from OpticDiscDetection.Mask_RCNN.mrcnn import model as modellib #region Configurations and loading model config = OpticDiscConfig() config.display() config.IMAGES_PER_GPU = 1 config.BATCH_SIZE = 1 # len(image) must match BATCH_SIZE model = modellib.MaskRCNN(mode="inference", config=config) image_shape = (384, 384, 1) weights_path = '/home/ubuntu/dlp/deploy_models/ROP/segmentation_optic_disc/mask_rcnn_opticdisc_0022_loss0.2510.h5' model.load_weights(weights_path, by_name=True) #endregion dir_original = '/media/ubuntu/data1/ROP_dataset/Plus/2020_02_12/original' dir_preprocess384 = '/media/ubuntu/data1/ROP_dataset/Plus/2020_02_12/preprocess384' dir_crop_optic_disc = '/tmp5/Plus_results_2020_4_14/crop_optic_disc' # dir_crop_optic_disc = '/tmp5/Plus_results_2020_4_14/crop_optic_disc_crop_circle' dir_draw_circle = '/tmp5/Plus_results_2020_4_14/draw_circle' dir_optic_disc_seg = '/tmp5/Plus_results_2020_4_14/optic_disc_seg' dir_dest_error = '/tmp5/Plus_results_2020_4_14/optic_disc_seg_error'