This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
ntut-lab1.py | |
Sets initial conditions for a spacecraft in Basilisk 2.4.0. | |
""" | |
from Basilisk.simulation import spacecraft | |
from Basilisk.utilities import SimulationBaseClass, macros | |
import matplotlib.pyplot as plt | |
# Create simulation base |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Full Lab: Spacecraft Motion and Attitude Visualization in Multiple Frames | |
with Exportable Interactive 3D Visualizations for both Final Attitude and ECI Orbit | |
This lab simulates a spacecraft orbiting Earth with an attitude control system. | |
It produces: | |
- Static plots (attitude error, control torque, rate error, orientation projection) | |
- An animation showing the spacecraft moving in the ECI frame along its orbit, | |
with its body frame and Hill (movement) frame axes. | |
- Two interactive Plotly 3D figures exported as HTML files: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
NewerOlder