def test_detect_frcnn_long(self): for im, name, labels, boxes in utils.tf_record_iterator( f"{BASE_DIR}/frcnn_records/test/annotated.record"): image_methods.show(im, use_log=False, annotations=zip(boxes, labels)) answer = image_methods.detect_comet(im, do_show=True)
def test_pipeline(self): x = utils.image_iterator(FITS_FOLDER) for _ in range(160): scanfiles = next(x) print(scanfiles[0]) ims = scanfiles[0] ims = [image_methods.get_image_data(im)[0] for im in ims] origs = ims.copy() image_methods.show_many(np.array(origs)) preprod = [image_methods.preprocess(im, resize=False) for im in ims] resized = [image_methods.resize_image(im, 512) for im in preprod] image_methods.show_many(np.array(origs), row_2=np.array(resized)) composite = image_methods.get_composite_image(resized) image_methods.show(composite, use_log=False) image_methods.detect_comet(composite, do_show=True, im_type="composite")
def test_untrained_comet_detection(self): for images in utils.image_iterator(f"{BASE_DIR}/not_trained_comets"): fits = images[0] arrs = [image_methods.get_image_data(f)[0] for f in fits] preprod = [ image_methods.preprocess(arr, resize=False) for arr in arrs ] resized = [image_methods.resize_image(pre, 512) for pre in preprod] comp = image_methods.get_composite_image(resized) image_methods.show(comp) answer = image_methods.detect_comet(preprod, do_show=True, im_type="composite") print(answer)
def test_detect_3frcnn_long(self): acc, count = (0, 0) for im, name, labels, boxes in utils.tf_record_iterator( f"{BASE_DIR}/data/band_3/c/test.record"): print(name) image_methods.show(im, use_log=False, annotations=zip(boxes, labels)) answer = image_methods.detect_comet(im, do_show=True, im_type="band_3") acc += answer == ("comet" in labels) count += 1 print(f"accuracy: {acc / count}")
def test_detect_comet_frcnn(self): folders = ["comet", "messier", "not_comet"] ans = [] for folder in folders: orig_file = f"{BASE_DIR}/data1/{folder}/original.npy" origs = np.load(orig_file) #if there are 4 bands, get the 4th band if origs.shape[0] == 4: origs = origs[3] rand = np.random.choice(np.r_[:len(origs)]) imarray = origs[rand] answer = image_methods.detect_comet(imarray, do_show=True) ans.append(answer) self.assertEqual(ans[0] is not False, True) self.assertEqual(ans[1:], [False] * len(ans[1:]))
def detect(fits_data, im_type="all_bands", model="faster_rcnn_inception_v2_coco", classes=["comet"], do_show="False"): """ fits_data (list or string) if list, list of fits files. If string, path to single fits file. im_type (string) band_3, all_bands, or composite. What type of neural net to use for detection model (string) directory in models. Probably don't want to change this. can download additional models from tf object detection model zoo classes: Which classes the neural net you want to use is trained on. For example, if your neural net was trained on classes named "roses" and "dandelions", classes would look like: ["roses", "dandelions"] do_show: Whether or not to show the image in a matplotlib popup window --- RETURNS: imarray (array) the image, preprocessed and resized boxes (list) list of bounding box coordinates scores (list) list of confidences for each bounding box classes (list) list of classes that each bounding box was classified as """ classes_string = "".join([x[0] for x in classes]) if isinstance(fits_data, list): images = [get_image_data(f)[0] for f in fits_data] else: images = [get_image_data(fits_data)[0]] images = [preprocess(im, resize=False) for im in images] imarray, boxes, scores, classes = detect_comet( images, do_show=do_show, im_type=im_type, model=model, classes_string=classes_string) return imarray, boxes, scores, classes