From 723be965494bb39bc327c03e4b3d21d5c4208402 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:05:02 +0000 Subject: [PATCH] notebook to explore params of individual transformations --- notebooks/notebook_data_augm_on_dataset.py | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 notebooks/notebook_data_augm_on_dataset.py diff --git a/notebooks/notebook_data_augm_on_dataset.py b/notebooks/notebook_data_augm_on_dataset.py new file mode 100644 index 00000000..d8451f34 --- /dev/null +++ b/notebooks/notebook_data_augm_on_dataset.py @@ -0,0 +1,46 @@ +# %% +# imports +import matplotlib.pyplot as plt +from torchvision.transforms import v2 + +from crabs.detection_tracking.datasets import CrabsCocoDetection +from crabs.detection_tracking.visualization import plot_sample + +# %matplotlib qt #to pop out figures + +# %%%%%%%%%%%%%%%%%%% +# Input data +IMG_DIR = "/Users/sofia/arc/project_Zoo_crabs/sep2023-full/frames" +ANNOT_FILE = "/Users/sofia/arc/project_Zoo_crabs/sep2023-full/annotations/VIA_JSON_combined_coco_gen.json" + + +# %%%%%%%%%%%%%%%%%%%%%%%%%% +# Create dataset +full_dataset = CrabsCocoDetection( + [IMG_DIR], + [ANNOT_FILE], + transforms=None, +) + +# %%%%%%%%%%%%%%%%%%%%%%% +# Sample a frame +sample = full_dataset[0] + + +# %%%%%%%%%%%%%%% +def transform_n_times_and_plot(sample, transform, n=1): + transformed_imgs = [transform(sample) for _ in range(n)] + + plot_sample([sample] + transformed_imgs) + plt.gcf().gca().set_title("transform") + return transformed_imgs + + +# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +# Random rotation + +transform = v2.RandomRotation(degrees=(-10, 10)) +transform_n_times_and_plot(sample, transform) + + +# %%