deepdisc.astrodet.astrodet
Classes
Use this for models that use yacs cfg files |
|
Create a simple end-to-end predictor with the given config that runs on |
|
Override this class in order to call the custom function above |
|
This class is used to load in and augment data during training. |
|
This class is used to load in and augment data during validation. |
Functions
Function to set MPL style |
|
|
|
|
Convert an instance detection/segmentation or keypoint detection dataset |
|
Converts dataset into COCO format and saves it to a json file. |
|
Read in a formatted HSC image |
|
Read in a formatted simulated DECam image |
|
|
|
|
|
|
|
|
|
This function reads in the scarlet model files and formats annotations for detectron2 |
Module Contents
- class NewAstroTrainer(model, data_loader, optimizer, cfg)[source]
Bases:
detectron2.engine.SimpleTrainerUse this for models that use yacs cfg files
- Parameters:
model (torch nn.module) – The model being trained
data_loader (detectron2 DataLoader) – The data loader that loads the training set
optimizer – The learning optimizer
cfg (config file) – The model config
- class AstroPredictor(cfg, lazy=False, cfglazy=None, checkpoint=None)[source]
Create a simple end-to-end predictor with the given config that runs on single device for a single input image. Compared to using the model directly, this class does the following additions: 1. Load checkpoint from cfg.MODEL.WEIGHTS. 2. Always take BGR image as the input and apply conversion defined by cfg.INPUT.FORMAT. 3. Apply resizing defined by cfg.INPUT.{MIN,MAX}_SIZE_TEST. 4. Take one input image and produce a single output, instead of a batch. This is meant for simple demo purposes, so it does the above steps automatically. This is not meant for benchmarks or running complicated inference logic. If you’d like to do anything more complicated, please refer to its source code as examples to build and use the model manually. .. attribute:: metadata
the metadata of the underlying dataset, obtained from cfg.DATASETS.TEST.
- type:
Metadata
Examples:
pred = DefaultPredictor(cfg) inputs = cv2.imread("input.jpg") outputs = pred(inputs)
- class COCOeval_opt_custom[source]
Bases:
detectron2.evaluation.fast_eval_api.COCOeval_opt- evaluate_custom()[source]
Run per image evaluation on given images and store results (a list of dict) in self.evalImgs :return: None
- _evaluate_predictions_on_coco(coco_gt, coco_results, iou_type, kpt_oks_sigmas=None, use_fast_impl=True, img_ids=None, max_dets_per_image=None, areaRng=None)[source]
- convert_to_coco_dict(dataset_name, mbins, mind, logger)[source]
Convert an instance detection/segmentation or keypoint detection dataset in detectron2’s standard format into COCO json format.
Generic dataset description can be found here: https://detectron2.readthedocs.io/tutorials/datasets.html#register-a-dataset
COCO data format description can be found here: http://cocodataset.org/#format-data
- Parameters:
dataset_name (str) – name of the source dataset Must be registered in DatastCatalog and in detectron2’s standard format. Must have corresponding metadata “thing_classes”
- Returns:
serializable dict in COCO json format
- Return type:
coco_dict
- convert_to_coco_json(dataset_name, output_file, mbins=[0, 1], mind=-1, allow_cached=True)[source]
Converts dataset into COCO format and saves it to a json file. dataset_name must be registered in DatasetCatalog and in detectron2’s standard format.
- Parameters:
dataset_name – reference from the config file to the catalogs must be registered in DatasetCatalog and in detectron2’s standard format
output_file – path of json file that will be saved to
allow_cached – if json file is already present then skip conversion
- class COCOEvaluatorRecall(dataset_name, tasks=None, distributed=True, output_dir=None, *, max_dets_per_image=None, areaRng=None, use_fast_impl=True, kpt_oks_sigmas=(), allow_cached_coco=True)[source]
Bases:
detectron2.evaluation.coco_evaluation.COCOEvaluatorOverride this class in order to call the custom function above
Evaluate AR for object proposals, AP for instance detection/segmentation, AP for keypoint detection outputs using COCO’s metrics. See http://cocodataset.org/#detection-eval and http://cocodataset.org/#keypoints-eval to understand its metrics. The metrics range from 0 to 100 (instead of 0 to 1), where a -1 or NaN means the metric cannot be computed (e.g. due to no predictions made).
In addition to COCO, this evaluator is able to support any bounding box detection, instance segmentation, or keypoint detection dataset.
- _derive_coco_results(coco_eval, iou_type, class_names=None)[source]
- Parameters:
coco_eval (None or COCOEval) – None represents no predictions from model.
iou_type (str)
class_names (None or list[str]) – if provided, will use it to predict per-category AP.
- Returns:
score}
- Return type:
a dict of {metric name
- read_image_hsc(filenames, normalize='lupton', stretch=0.5, Q=10, m=0, ceil_percentile=99.995, dtype=np.uint8, A=10000.0, do_norm=False)[source]
Read in a formatted HSC image
- Parameters:
filenames (list) – The list of g,r,i band files
normalize (str) – The key word for the normalization scheme
stretch (float, int, float) – Parameters for lupton normalization
Q (float, int, float) – Parameters for lupton normalization
m (float, int, float) – Parameters for lupton normalization
ceil_percentile – If do_norm is true, cuts data off at this percentile
dtype (numpy datatype) – data type of the output array
A (float) – scaling factor for zscoring
do_norm (boolean) – For normalizing top fit dtype range
- Return type:
Scaled image
- read_image_decam(filename, normalize='lupton', stretch=0.5, Q=10, m=0, ceil_percentile=99.995, dtype=np.uint8, A=10000.0, do_norm=False)[source]
Read in a formatted simulated DECam image
- Parameters:
filenames (list) – The list of g,r,i band files
normalize (str) – The key word for the normalization scheme
stretch (float, int, float) – Parameters for lupton normalization
Q (float, int, float) – Parameters for lupton normalization
m (float, int, float) – Parameters for lupton normalization
ceil_percentile – If do_norm is true, cuts data off at this percentile
dtype (numpy datatype) – data type of the output array
A (float) – scaling factor for zscoring
do_norm (boolean) – For normalizing top fit dtype range
- Return type:
Scaled image
- get_astro_dicts(img_dir)[source]
This function reads in the scarlet model files and formats annotations for detectron2
- Parameters:
img_dir (str) – Directory where the scarlet outputs are stored
- Returns:
dataset_dicts – A list of dictionaries that contain annotations for train, test, val sets
- Return type:
list
- class train_mapper_cls(**read_image_args)[source]
This class is used to load in and augment data during training. It is initialized and then called during training where it augments images and returns them along with annotations
- Parameters:
read_image_args (keyword args)
function (These are the necessary arguments for the read_image_hsc)
- class test_mapper_cls(**read_image_args)[source]
This class is used to load in and augment data during validation. It is initialized and then called during validation where it augments images and returns them along with annotations
- Parameters:
read_image_args (keyword args)
function (These are the necessary arguments for the read_image_hsc)