def plot(model_dir="experiments/S_BGCN_HoustonDataset_k2_2021_04_26_2"): gt = load_gt() dataset = HoustonDatasetMini() alpha, vac, dis = [unflatten_array(array) for array in load_alpha_vac_dis(model_dir)] # alpha = unflatten_array(np.load(os.path.join(model_dir, "prob.npy")), gt.shape) # fig, ax = dense_fig(3, 1, width=7, height=4, keep_square=False) fig, ax = dense_fig(3, 2, width=8, height=7, keep_square=False) ax[0, 1].axis('off') # invisible classification = np.argmax(alpha, axis=-1) gt_rgb = classes_array_to_colormapped_array(gt) classification_rgb = classes_array_to_colormapped_array(classification) ax[0, 0].imshow(np.rollaxis(rgb.training_array(), 0, 3)[:, 1800:3600]) legend = shade_one_axes_with_splits(ax[0, 0], dataset.mask_tr, dataset.mask_va, dataset.mask_te) ax[0, 0].legend(handles=legend, loc='center left', bbox_to_anchor=(1, 0.5)) ax[1, 0].imshow(gt_rgb) ax[2, 0].imshow(classification_rgb) img = ax[1, 1].matshow(vac) add_colorbar(fig, img, ax[1, 1], x_shift=.1) img = ax[2, 1].matshow(dis) add_colorbar(fig, img, ax[2, 1], x_shift=.1) set_each_ax_y_label(["Optical", "GT", "S-BMLP\nClassification", "Vacuity", "Dissonance"], [ax[0, 0], ax[1, 0], ax[2, 0], ax[1, 1], ax[2, 1]]) # set_each_ax_y_label(["Optical", "GT", "GCN\nClassification"], [ax[0, 0], ax[1, 0], ax[1, 1]]) remove_ax_list_ticks(ax.flatten()) fig.savefig("docs/25_may/sbmlp.pdf", bbox_inches="tight")
def download(self): gt = ground_truth.data.array[0] y = gt[:, 1800:3600].reshape(-1, 1) x = np.concatenate([rgb.training_array(), hyperspectral.training_array(), lidar.training_array()]) x = x[:, :, 1800:3600] x = np.rollaxis(x.reshape(x.shape[0], -1), 0, 2) print("Computing k neighbors graph...") a = kneighbors_graph(x, 15, include_self=False) a = a + a.T # to make graph symmetric (using k neighbours in "either" rather than "mutual" mode) a[a > 1] = 1 # get rid of any edges we just made double print("Graph computed.") # Create the directory os.mkdir(self.path) filename = os.path.join(self.path, f'graph') np.savez(filename, x=x, a=a, y=OneHotEncoder().fit_transform(y).toarray())
def channels_figure(margin=.1, width=.6): # image = [np.arange(50 * 100).reshape(50, 100)] * 4 # shape: channels, height, width image = np.concatenate([rgb.training_array(), hyperspectral.training_array(), lidar.training_array()])[..., 1800:3600] aspect, numb = image.shape[1] / image.shape[2], len(image) height = width * aspect dx, dy = (1 - 2 * margin - width) / (numb - 1), (1 - 2 * margin - height) / (numb - 1) fig = plt.figure(figsize=(8, 4)) axes = [fig.add_axes([margin + n * dx, margin + (numb - n - 1) * dy, width, height]) for n in range(numb - 1 - 2, -1, -1)] # extra -2 because we'll show 3 channels in one for the rgb for i, ax in enumerate(axes): if i != len(axes) - 1: ax.matshow(image[len(axes) - i - 1], cmap='hsv') else: ax.imshow(np.rollaxis(image[:3], 0, 3)) ax.axis('off') fig.savefig('docs/19_oct/channels.pdf', bbox_inches='tight')
def data_figure_rgb(): fig, ax = dense_fig(1, 1) ax.imshow(np.rollaxis(rgb.training_array()[..., 1800:3600], 0, 3)) fig.savefig("docs/19_oct/data_figure_rgb.pdf", bbox_inches="tight")