HPLQAQ / SAM-Deblur

Implementation of the paper SAM-Deblur: Let Segment Anything Boost Image Deblurring(ICASSP2024)
https://hplqaq.github.io/projects/sam-deblur
Apache License 2.0
25 stars 2 forks source link

run SegNAFNet_arch #7

Open Nanncy99 opened 2 weeks ago

Nanncy99 commented 2 weeks ago

image What should I do if the forword function lacks masks when calculating model parameters?Hope to get your answer, thank you very much!

HPLQAQ commented 2 weeks ago

Hello, our method needs to get masks calculated from SAM model in advance. To run the codes, the dataset that we provided is needed.

Download prepared data for experiments from Baidu Netdisk|Onedrive.
If you only want to run our deblur pipeline, download test/val datasets(GoPro, RealBlurJ, REDS, ReLoBlur provided). if you want to train the model yourself, download train datasets(GoPro provided). Check datasets README for standard dataset structure. Unzip data and put under datasets dir for experiments.

The mask generation codes are in

scripts/data_preparation/1_create_masks_with_sam.py: Create masks for concat method.
scripts/data_preparation/2_masks_to_grouped_masks.py: Create grouped_masks from masks for our MAP method.

I'll try integrating sam into the inference code later to avoid the necessity of downloading our data when I'm available.

Nanncy99 commented 2 weeks ago

Thank you very much for your answer, it has been very useful to me.However, I have one more small question.Where is MAP Unit reflected in the code in the paper? I don't seem to have found it yet.I hope to receive your reply. Thank you very much again.

HPLQAQ commented 2 weeks ago

https://github.com/HPLQAQ/SAM-Deblur/blob/9e0c8cf20f4e00915d72415a85416795417001bd/basicsr/models/archs/SegNAFNet_arch.py#L104

From line 104 to line 110, we calculated the area and the sum_val for each mask to get the avg_val.

From line 112 to line 115, they were multiplied to the masks and added together.

if you remove the sum operation at line 115, then from line 104 to 115 reflects a MAP Unit.

Nanncy99 commented 2 weeks ago

Thank you for your answer.I have a small question regarding scripts/data_preparation/2_masks_to_grouped_masks.py: Create grouped_masks from masks for our MAP method. The code uses an lmdb format dataset. If my dataset does not have an lmdb format, do I need to generate an lmdb format?Hope to get your answer, thank you very much!

HPLQAQ commented 2 weeks ago

You can directly change the 'read_image_from_lmdb' function to 'read_image_from_folder' function.

Change the following codes to simply go through the data folder and pass the data path to 'read_image_from_folder' should work.

env = lmdb.open(lmdb_dir, readonly=True, max_dbs=0)

with env.begin() as txn:
    cursor = txn.cursor()
    for key, _ in cursor: