Repository: jolibrain/joliGEN

Issue:
unet ref training preview and inference script
after 500 epochs results of training preview do not match results of generated image with inference script
![download 525](https://github.com/jolibrain/joliGEN/assets/32034827/771eed0e-b714-4682-a9d1-1766fb8f3122)
![image](https://github.com/jolibrain/joliGEN/assets/32034827/8ee693d7-52c2-4602-bf9d-86299231052d)

I tried finetuning previous checkpoints trained without data_online_creation_load_size_A option ```python3 train.py \
--dataroot /datasets/viton_ref/viton_bbox_ref \
--checkpoints_dir /checkpoints \
--name viton_bbox_ref \
--config_json examples/example_ddpm_unetref_viton.json \
--data_online_creation_load_size_A 768 1024 \
--train_continue \```

then I tried inference ```python3 scripts/gen_single_image_diffusion.py \
--model-in-file /checkpoints/viton_bbox_ref/latest_net_G_A.pth \
--img-in /datasets/viton_ref/viton_bbox_ref/trainA/imgs/00000_00.jpg \
--bbox-in /datasets/viton_ref/viton_bbox_ref/trainA/bbox/00000_00.txt \
--ref-in /datasets/viton_ref/viton_bbox_ref/trainA/ref/00000_00.jpg \
--dir-out /checkpoints/viton_bbox_ref/inference_output \
--img-width 128 \
--img-height 128```

I also tried inference with 96 128  (did not help improove results) and 512 512 (that approximatelly taking 6 hours)


Discussion:

Resolving patch:
diff --git a/data/online_creation.py b/data/online_creation.py
--- a/data/online_creation.py
+++ b/data/online_creation.py
@@ -42,7 +42,7 @@ def crop_image(
             if len(load_size) == 1:
                 load_size.extend(load_size)
             old_size = img.size
-            img = F.resize(img, load_size)
+            img = F.resize(img, (load_size[1], load_size[0]))
             new_size = img.size
             ratio_x = img.size[0] / old_size[0]
             ratio_y = img.size[1] / old_size[1]
diff --git a/scripts/gen_single_image_diffusion.py b/scripts/gen_single_image_diffusion.py
--- a/scripts/gen_single_image_diffusion.py
+++ b/scripts/gen_single_image_diffusion.py
@@ -447,6 +447,9 @@ def generate(
         """if crop_width > 0 and crop_height > 0:
         mask = resize(mask).clone().detach()"""
     if ref is not None:
+        ref = cv2.resize(
+            ref, (img.shape[1], img.shape[0]), interpolation=cv2.INTER_CUBIC
+        )
         ref_tensor = tran(ref).clone().detach()
 
     if not cpu:


Test patch:
diff --git a/tests/test_run_diffusion_online.py b/tests/test_run_diffusion_online.py
--- a/tests/test_run_diffusion_online.py
+++ b/tests/test_run_diffusion_online.py
@@ -22,8 +22,8 @@
     "data_online_creation_mask_delta_A_ratio": [[0.2, 0.2]],
     "data_online_creation_crop_size_B": 420,
     "data_online_creation_crop_delta_B": 50,
-    "data_online_creation_load_size_A": [2500, 1000],
-    "data_online_creation_load_size_B": [2500, 1000],
+    "data_online_creation_load_size_A": [1000, 2500],
+    "data_online_creation_load_size_B": [1000, 2500],
     "train_n_epochs": 1,
     "train_n_epochs_decay": 0,
     "data_max_dataset_size": 10,
diff --git a/tests/test_run_semantic_mask_online.py b/tests/test_run_semantic_mask_online.py
--- a/tests/test_run_semantic_mask_online.py
+++ b/tests/test_run_semantic_mask_online.py
@@ -24,8 +24,8 @@
     "data_online_creation_mask_delta_A_ratio": [[0.2, 0.2]],
     "data_online_creation_crop_size_B": 420,
     "data_online_creation_crop_delta_B": 50,
-    "data_online_creation_load_size_A": [2500, 1000],
-    "data_online_creation_load_size_B": [2500, 1000],
+    "data_online_creation_load_size_A": [1000, 2500],
+    "data_online_creation_load_size_B": [1000, 2500],
     "data_online_context_pixels": 0,
     "train_n_epochs": 1,
     "train_n_epochs_decay": 0,