config.display() # Training dataset dataset_train = ShapesDataset() dataset_train.load_shapes(1000, config.IMAGE_SHAPE[0], config.IMAGE_SHAPE[1]) dataset_train.prepare() # Validation dataset dataset_val = ShapesDataset() dataset_val.load_shapes(100, config.IMAGE_SHAPE[0], config.IMAGE_SHAPE[1]) dataset_val.prepare() image, gt_class_ids, gt_boxes, gt_masks = mutils.load_image_gt( dataset_train, config, image_id=440, augment=None, augmentation=None, use_mini_mask=config.USE_MINI_MASK) # config.BATCH_SIZE = 1 model = modellib.MaskYOLO(mode="training", config=config, yolo_pretrain_dir=None, yolo_trainable=True) model.load_weights('./saved_model_Dec27-14-43.h5') # model.detect(image, './saved_model_Dec27-14-43.h5') model.train(dataset_train, dataset_val, learning_rate=config.LEARNING_RATE,
dataset_val = RiceDataset() dataset_val.load_rice(RICE_DIR, "val") dataset_val.prepare() # all_info = [] # for id in range(0, 500): # image, gt_class_ids, gt_boxes, gt_masks = \ # mutils.load_image_gt(dataset_train, config, id, # use_mini_mask=config.USE_MINI_MASK) # all_info.append([image, gt_class_ids, gt_boxes, gt_masks]) # Data generators train_info = [] for id in range(0, 53): image, gt_class_ids, gt_boxes, gt_masks = \ mutils.load_image_gt(dataset_train, config, id, use_mini_mask=config.USE_MINI_MASK) train_info.append([image, gt_class_ids, gt_boxes, gt_masks]) val_info = [] for id in range(0, 6): image, gt_class_ids, gt_boxes, gt_masks = \ mutils.load_image_gt(dataset_val, config, id, use_mini_mask=config.USE_MINI_MASK) val_info.append([image, gt_class_ids, gt_boxes, gt_masks]) train_generator = mutils.BatchGenerator(train_info, config, mode='training', shuffle=True, jitter=False, norm=True)
inference_config.BATCH_SIZE = 1 inference_config.display() ''' Recreate the model in inference mode ''' model = modellib.MaskYOLO(mode="inference", config=inference_config) ''' Load trained weights ''' model.load_weights('./model_1216.h5', by_name=True) ''' Training dataset ''' dataset_train = ShapesDataset() dataset_train.load_shapes(500, inference_config.IMAGE_SHAPE[0], inference_config.IMAGE_SHAPE[1]) dataset_train.prepare() ''' Validation dataset ''' dataset_val = ShapesDataset() dataset_val.load_shapes(50, inference_config.IMAGE_SHAPE[0], inference_config.IMAGE_SHAPE[1]) dataset_val.prepare() ''' Test on a random image ''' image_id = random.choice(dataset_val.image_ids) original_image, gt_class_id, gt_bbox, gt_mask = mutils.load_image_gt( dataset_val, inference_config, image_id, use_mini_mask=False) # visualize.display_instances(original_image, gt_bbox, gt_mask, gt_class_id, # dataset_train.class_names, figsize=(8, 8)) results = model.detect_for_one([original_image], verbose=1) r = results[0] print(r) # visualize.display_instances(original_image, r['rois'], r['masks'], r['class_ids'], # dataset_val.class_names, r['scores'], ax=get_ax())