コード例 #1
0
COCO_DIR = os.path.join(ROOT_DIR, 'data/coco')
DEFAULT_MODEL_DIR = os.path.join(MODEL_DIR, "mask_rcnn_256_cocoperson_0283.h5")

## Dataset
class_names = ['person']  # all classes: None
dataset_train = coco.CocoDataset()
dataset_train.load_coco(COCO_DIR, "train", class_names=class_names)
dataset_train.prepare()
dataset_val = coco.CocoDataset()
dataset_val.load_coco(COCO_DIR, "val", class_names=class_names)
dataset_val.prepare()

## Model
config = coco.CocoConfig()
config.display()
model = modellib.MaskRCNN(mode="training", model_dir=MODEL_DIR, config=config)
model.keras_model.summary()

## Weights
model_path = model.get_imagenet_weights()
#model_path = model.find_last()[1]
#model_path = DEFAULT_MODEL_DIR
print("> Loading weights from {}".format(model_path))
model.load_weights(model_path, by_name=True)

## Training - Config
starting_epoch = model.epoch
epoch = dataset_train.dataset_size // (config.STEPS_PER_EPOCH *
                                       config.BATCH_SIZE)
epochs_warmup = epoch // 2  #+ starting_epoch
epochs_heads = 5 * epoch  #+ starting_epoch
コード例 #2
0
import numpy as np

# Import Mobile Mask R-CNN
from mmrcnn import model as modellib, utils, visualize
from mmrcnn.model import log
import coco

# Paths
ROOT_DIR = os.getcwd()
MODEL_DIR = os.path.join(ROOT_DIR, "logs")
COCO_DIR = os.path.join(ROOT_DIR, 'data/coco')
NUM_EVALS = 10

# Load Model
config = coco.CocoConfig()
model = modellib.MaskRCNN(mode="inference", config=config, model_dir=MODEL_DIR)

# Get path to saved weights
# Either set a specific path or find last trained weights
#model_path = os.path.join(MODEL_DIR, "mask_rcnn_512_cocoperson_0396.h5")
model_path = model.find_last()[1]

# Load trained weights (fill in path to trained weights here)
assert model_path != "", "Provide path to trained weights"
print("> Loading weights from {}".format(model_path))
model.load_weights(model_path, by_name=True)

# Dataset
class_names = ['person']  # all classes: None
dataset_val = coco.CocoDataset()
COCO = dataset_val.load_coco(COCO_DIR,
コード例 #3
0
# Device to load the neural network on.
# Useful if you're training a model on the same
# machine, in which case use CPU and leave the
# GPU for training.
#DEVICE = "/cpu:0"
DEVICE = "/gpu:0"

# Inspect the model in training or inference modes
# values: 'inference' or 'training'
# TODO: code for 'training' test mode not ready yet
TEST_MODE = "inference"
#TEST_MODE = "training"

# Create model in inference mode
model = modellib.MaskRCNN(mode=TEST_MODE, model_dir=MODEL_DIR, config=config)
# Set path to model weights
weights_path = DEFAULT_WEIGHTS
# Load weights
print("Loading weights ", weights_path)
model.load_weights(weights_path, by_name=True)

# COCO Class names
# Index of the class in the list is its ID. For example, to get ID of
# the teddy bear class, use: class_names.index('teddy bear')
class_names = [
    'BG', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train',
    'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign',
    'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
    'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag',
    'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite',
コード例 #4
0
    else:

        class InferenceConfig(CocoConfig):
            # Set batch size to 1 since we'll be running inference on
            # one image at a time. Batch size = GPU_COUNT * IMAGES_PER_GPU
            GPU_COUNT = 1
            IMAGES_PER_GPU = 1
            DETECTION_MIN_CONFIDENCE = 0

        config = InferenceConfig()
    config.display()

    # Create model
    if args.command == "train":
        model = modellib.MaskRCNN(mode="training",
                                  config=config,
                                  model_dir=args.logs)
    else:
        model = modellib.MaskRCNN(mode="inference",
                                  config=config,
                                  model_dir=args.logs)

    # Select weights file to load
    if args.model.lower() == "coco":
        model_path = COCO_MODEL_PATH
    elif args.model.lower() == "last":
        # Find last trained weights
        model_path = model.find_last()[1]
    elif args.model.lower() == "imagenet":
        # Start from ImageNet trained weights
        model_path = model.get_imagenet_weights()
コード例 #5
0
               'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza',
               'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed',
               'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote',
               'keyboard', 'cell phone', 'microwave', 'oven', 'toaster',
               'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors',
               'teddy bear', 'hair drier', 'toothbrush']

config = coco.CocoConfig()
<<<<<<< HEAD
model_path = model_path = os.path.join(WEIGHTS_DIR, "trained_coco_2018-Jun-13__11_02_08.h5")
=======
model_path = model_path = os.path.join(WEIGHTS_DIR, "trained_coco_2018-Jun-13__15_20_23.h5")
>>>>>>> 536f2b4cf039aaa66c898f02c27d7212ec378360
#model_path = "/home/thiemi/MaskRCNN/Mask_RCNN/mask_rcnn_coco.h5"

model = modellib.MaskRCNN(mode="inference", config=config, model_dir=WEIGHTS_DIR)
#model = modellib.MaskRCNN(mode="inference", config=config, model_dir="/home/thiemi/MaskRCNN/Mask_RCNN")
# returns a compiled model
model.load_weights(model_path, by_name=True)
print("successfully loaded model")

#image = skimage.io.imread(os.path.join(TEST_PIC_DIR, "street" + str(7) + ".jpg"))

image = cv2.imread(os.path.join(TEST_PIC_DIR, "street" + str(7) + ".jpg"))
height, width = image.shape[:2]
<<<<<<< HEAD
=======
print("height:", height)
print("widht:", width)
cv2.imshow("before", image)
cv2.waitKey(0)