Пример #1
0
# Inspect the model in inference modes
# values: 'inference'
TEST_MODE = "inference"

#%% Load Validation Dataset
dataset = VocDataset()
dataset.load_voc(dataset_dir, "test")
dataset.prepare()

print("Images: {}\nClasses: {}".format(len(dataset.image_ids),
                                       dataset.class_names))

#%% Load Model
# Create model in inference mode
with tf.device(DEVICE):
    model = FasterRCNN(mode="inference", model_dir=MODEL_DIR, config=config)

# Load weights
model.load_weights(weights_path, by_name=True)

#%% Run Detection
image_id = random.choice(dataset.image_ids)
image, image_meta, gt_class_id, gt_bbox =\
    data.load_image_gt(dataset, config, image_id)
info = dataset.image_info[image_id]
print("image ID: {}.{} ({}) {}".format(info["source"], info["id"], image_id,
                                       dataset.image_reference(image_id)))
# Run object detection
results = model.detect([image], verbose=1)

# Display results
Пример #2
0

check_config = CheckConfig()

# image_ids = np.random.choice(dataset_train.image_ids, 1)
image_ids = dataset_train.image_ids
for image_id in image_ids:
    original_image, image_meta, gt_class_id, gt_bbox =\
        data.load_image_gt(dataset_train, check_config, image_id)

    # visualize.display_instances(original_image, gt_bbox, gt_class_id,
    #                             dataset_train.class_names, ax=get_ax())

#%% Create Model
# Create model in training mode
model = FasterRCNN(mode="training", config=config, model_dir=LOG_ROOT)
model.plot_model()
model.print_summary()

model_path = model.find_last()
model.load_weights(model_path, by_name=True)

model.train(dataset_train,
            dataset_val,
            learning_rate=config.LEARNING_RATE,
            epochs=80,
            trainable='+all')


#%% Detection
class InferenceConfig(CocoConfig):
Пример #3
0
def train_frcnn():
    fast = FasterRCNN()
    fast.load_data_train()
    fast.build()
    fast.train()
Пример #4
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"  # /cpu:0 or /gpu:0


#%% 
def get_ax(rows=1, cols=1, size=16):
    return plt.subplots(rows, cols, figsize=(size*cols, size*rows))[1]


#%% Load Model
# Create model in inference mode
with tf.device(DEVICE):
    model = FasterRCNN(mode="inference", model_dir=MODEL_DIR, config=config)

# Load weights
model.load_weights(weights_path, by_name=True)


#%% Review Weight Stats
# Show stats of all trainable weights
# visualize.display_weight_stats(model, html=True)
visualize.display_weight_stats(model, html=False)


#%% Histograms of Weights
# Pick layer types to display
LAYER_TYPES = ['Conv2D', 'Dense', 'Conv2DTranspose']
Пример #5
0
def test_frcnn():
    fast = FasterRCNN()
    fast.test('./images/test-images')