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"
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'])
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.DATASETS.TRAIN = ("rareplanes_dataset_train",)
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.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"
# display COCO categories
cats = coco.loadCats(coco.getCatIds())
nms=[cat['name'] for cat in cats]
print('COCO categories: \n{}\n'.format(' '.join(nms)))
from 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.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)
# Some basic setup:
# Setup detectron2 logger
import detectron2
from detectron2.utils.logger import 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 (
# This version is modified by H-BEMD for sin and cos value and optimize Extrema detection and Normolization value
# By Trong-An Bui ( -
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