Skip to content

Instantly share code, notes, and snippets.

View trongan93's full-sized avatar

Trong-An (Andrew) Bui trongan93

View GitHub Profile
from detectron2.utils.visualizer import ColorMode
json_file_test = "/mnt/d/RarePlanes/datasets/synthetic/metadata_annotations/instances_test_aircraft.json"
coco_test=COCO(json_file_test)
catIds = coco_test.getCatIds(catNms=['aircraft']);
imgIds = coco_test.getImgIds(catIds=catIds);
img = coco_test.loadImgs(imgIds[np.random.randint(0,len(imgIds))])[0]
im = cv2.imread("/mnt/d/RarePlanes/datasets/synthetic/test/images/" + img['file_name'])
plt.axis('off')
cfg.MODEL.WEIGHTS = os.path.join(cfg.OUTPUT_DIR, "model_final.pth") # path to the model we just trained
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.7 # set a custom testing threshold
predictor = DefaultPredictor(cfg)
from detectron2.engine import DefaultTrainer
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.DATASETS.TRAIN = ("rareplanes_dataset_train",)
cfg.DATASETS.TEST = ()
cfg.DATALOADER.NUM_WORKERS = 2
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml") # Let training initialize from model zoo
cfg.SOLVER.IMS_PER_BATCH = 2
cfg.SOLVER.BASE_LR = 0.00025 # pick a good LR
from pycocotools.coco import COCO
json_file = "/mnt/d/RarePlanes/datasets/synthetic/metadata_annotations/instances_train_aircraft.json"
coco=COCO(json_file)
# display COCO categories
cats = coco.loadCats(coco.getCatIds())
nms=[cat['name'] for cat in cats]
print('COCO categories: \n{}\n'.format(' '.join(nms)))
from detectron2.data.datasets import register_coco_instances
register_coco_instances("rareplanes_dataset_train", {}, "/mnt/d/RarePlanes/datasets/synthetic/metadata_annotations/instances_train_aircraft.json", "/mnt/d/RarePlanes/datasets/synthetic/train/images")
register_coco_instances("rareplanes_dataset_val", {}, "/mnt/d/RarePlanes/datasets/synthetic/metadata_annotations/instances_test_aircraft.json", "/mnt/d/RarePlanes/datasets/synthetic/test/images")
cfg = get_cfg()
# add project-specific config (e.g., TensorMask) here if you're not running a model in detectron2's core library
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 # set threshold for this model
# Find a model from detectron2's model zoo. You can use the https://dl.fbaipublicfiles... url as well
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
predictor = DefaultPredictor(cfg)
outputs = predictor(im_test)
data_base = "/mnt/d/RarePlanes/datasets/synthetic"
data_train = data_base + "/train"
im_path = data_train + "/images/Chicago_Airport_0_0_899_10974.png"
im_test = cv2.imread(im_path)
plt.imshow(im_test)
plt.show()
# Some basic setup:
# Setup detectron2 logger
import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()
# import some common libraries
import numpy as np
import os, json, cv2, random
from matplotlib import pyplot as plt
# Show the direction of landslide
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(bf_cX, bf_cY, 'go')
# ax.text(bf_cY+1, bf_cX-2, 'center point of region - before landslide')
ax.plot(at_cX, at_cY, 'ro')
# ax.text(at_cY+1, at_cX+1, 'center point of region - before landslide')
# Reference from **Bidimensional Empirical Mode Decomposition** code by Dawid Laszuk (laszukdawid@gmail.com).
# This version is modified by H-BEMD for sin and cos value and optimize Extrema detection and Normolization value
# By Trong-An Bui (trongan93@gmail.com - http://buitrongan.com)
class BEMD:
def __init__(self):
# ProtoIMF related
self.mse_thr = 0.01
self.mean_thr = 0.01
self.FIXE = 1 # Single iteration by default, otherwise results are terrible