def evaluate_wsol(scoremap_root, metadata_root, mask_root, dataset_name, split, cam_curve_interval=.001): """ Compute WSOL performances of predicted heatmaps against ground truth boxes (CUB, ILSVRC) or masks (OpenImages). For boxes, we compute the gt-known box accuracy (IoU>=0.5) at the optimal heatmap threshold. For masks, we compute the area-under-curve of the pixel-wise precision- recall curve. Args: scoremap_root: string. Score maps for each eval image are saved under the output_path, with the name corresponding to their image_ids. For example, the heatmap for the image "123/456.JPEG" is expected to be located at "{output_path}/123/456.npy". The heatmaps must be numpy arrays of type np.float, with 2 dimensions corresponding to height and width. The height and width must be identical to those of the original image. The heatmap values must be in the [0, 1] range. The map must attain values 0.0 and 1.0. See check_scoremap_validity() in util.py for the exact requirements. metadata_root: string. mask_root: string. dataset_name: string. Supports [CUB, ILSVRC, and OpenImages]. split: string. Supports [train, val, test]. cam_curve_interval: float. Default 0.001. At which threshold intervals will the heatmaps be evaluated? Returns: performance: float. For CUB and ILSVRC, maxboxacc is returned. For OpenImages, area-under-curve of the precision-recall curve is returned. """ print("Loading and evaluating cams.") metadata = configure_metadata(metadata_root) image_ids = get_image_ids(metadata) cam_threshold_list = list(np.arange(0, 1, cam_curve_interval)) evaluator = { "OpenImages": MaskEvaluator, "CUB": BoxEvaluator, "ILSVRC": BoxEvaluator }[dataset_name](metadata=metadata, dataset_name=dataset_name, split=split, cam_threshold_list=cam_threshold_list, mask_root=mask_root) cam_loader = _get_cam_loader(image_ids, scoremap_root) for cams, image_ids in cam_loader: for cam, image_id in zip(cams, image_ids): evaluator.accumulate(t2n(cam), image_id) performance = evaluator.compute() return performance
def compute_and_evaluate_cams(self): print("Computing and evaluating cams.") for images, targets, image_ids in self.loader: image_size = images.shape[2:] images = images.cuda() cams = t2n(self.model(images, targets, return_cam=True)) for cam, image_id in zip(cams, image_ids): cam_resized = cv2.resize(cam, image_size, interpolation=cv2.INTER_CUBIC) cam_normalized = normalize_scoremap(cam_resized) self.evaluator.accumulate(cam_normalized, image_id) return self.evaluator.compute()
def compute_and_evaluate_cams(self): print("Computing and evaluating cams.") for images, targets, image_ids in self.loader: image_size = images.shape[2:] images = images.cuda() cams = t2n(self.model(images, targets, return_cam=True)) for cam, image_id in zip(cams, image_ids): cam_resized = cv2.resize(cam, image_size, interpolation=cv2.INTER_CUBIC) cam_normalized = normalize_scoremap(cam_resized) if self.split in ('val', 'test'): cam_path = ospj(self.log_folder, 'scoremaps', image_id) if not os.path.exists(ospd(cam_path)): os.makedirs(ospd(cam_path)) np.save(ospj(cam_path), cam_normalized) self.evaluator.accumulate(cam_normalized, image_id) return self.evaluator.compute()
channels=2, save_stimuli=False, save_crestfactor=True, db_lufs_ref=-35, out_dir=out_dir) # Square Wave Bursts fs = 44100 f0 = 50 amplitude = 0.99 duration = 10 / f0 num_partials = 10 modal_window = kaiser(2 * num_partials + 1, beta=4)[num_partials + 1:] _, y, _ = util.square_wave(f0, num_partials, amplitude, duration, fs, 0, modal_window) n_taper = util.t2n(2 / f0, fs, ms=False) y = util.fade(y, n_taper, n_taper, type='h') t_period, t_predelay, t_intro, t_outro = 500, 20, 0, 0 # in milliseconds repetition = 3 peak_db = -12 filename = 'square' util.make_periodic_stimuli(y, fs, filename, phase_angles, repetition, peak_db, t_period, t_predelay,
importlib.reload(util) # Phase angles phase_angles = np.array([0, -0.25 * np.pi, -0.5 * np.pi]) filter_order = 3963530 # Square wave bursts fs = 44100 f0 = 44.1 amplitude = 0.25 duration = 10 / f0 num_partials = 10 modal_window = kaiser(2 * num_partials + 1, beta=4)[num_partials + 1:] _, x, _ = util.square_wave(f0, num_partials, amplitude, duration, fs, 0, modal_window) n_taper = util.t2n(2 / f0, fs, ms=False) x = util.fade(x, n_taper, n_taper, type='h') # one square wave burst t_period, t_predelay, t_intro, t_outro = 500, 20, 0, 0 # in milliseconds t_fadein, t_fadeout = 0, 0 t_signal = util.n2t(len(x), fs, ms=True) t_prepend = t_predelay t_append = t_period - t_signal - t_predelay n_prepend = util.t2n(t_prepend, fs, ms=True) n_append = util.t2n(t_append, fs, ms=True) x_1p = util.prepend_append_zeros(x, n_prepend, n_append) # one period # Phase shift in the DFT domain repetition = 3 # three square burst train N = repetition * len(x_1p) y_dft = np.zeros((len(phase_angles), N))