ameraner / dsen2-cr

DSen2-CR: A network for removing clouds from Sentinel-2 images. This repo contains the model code, written in Python/Keras, as well as links to pre-trained checkpoints and the SEN12MS-CR dataset.
GNU General Public License v3.0
138 stars 29 forks source link

Run the pretrained model #29

Open fekenzofugi opened 1 month ago

fekenzofugi commented 1 month ago

I would like to know how I can run the pretrained model available in this repository. Could you provide detailed instructions on how to set up and run the model?

Thank you in advance for your help!

ameraner commented 1 month ago

Hi, have you read and tried the commands here? https://github.com/ameraner/dsen2-cr?tab=readme-ov-file#basic-commands The Readme is currently the only documentation I can provide. I'll close the issue, please open a new specific issue if you have futher issues when running the code.

fekenzofugi commented 1 month ago

image

This is the error that i'm facing.

ameraner commented 1 month ago

looks like the ID is not being loaded properly, maybe the path to the datasetfilelist.csv needs to be adapted? going into debug mode on your IDE where the error happens and tracing back the steps should show you the issue.

fekenzofugi commented 1 month ago

image

Model compiled successfully! Getting file lists Number of train files found: 0 Number of validation files found: 2 Number of test files found: 0 Predicting using file: model_SARplain.hdf5 Using this model: val WARNING: Folder {} exists and content may be overwritten! WARNING: Folder {} exists and content may be overwritten! Initializing generator for prediction and evaluation Generator initialized Storing evaluation metrics at /home/nipe/dsen2-cr/output/valeval.csv Traceback (most recent call last): File "dsen2cr_main.py", line 179, in run_dsen2cr(args.predict_file, args.resume_file) File "dsen2cr_main.py", line 160, in run_dsen2cr max_val_sar, scale) File "/home/nipe/dsen2-cr/Code/dsen2cr_tools.py", line 169, in predict_dsen2cr for i, (data, y) in enumerate(predict_generator): File "/home/nipe/anaconda3/envs/dsen2cr_env/lib/python3.7/site-packages/keras/utils/data_utils.py", line 372, in iter for item in (self[i] for i in range(len(self))): File "/home/nipe/anaconda3/envs/dsen2cr_env/lib/python3.7/site-packages/keras/utils/data_utils.py", line 372, in for item in (self[i] for i in range(len(self))): File "/home/nipe/dsen2-cr/Code/tools/dataIO.py", line 280, in getitem self.random_crop_paramy[indexes]) File "/home/nipe/dsen2-cr/Code/tools/dataIO.py", line 308, in __data_generation random_crop_paramy_temp, data_type=3) File "/home/nipe/dsen2-cr/Code/tools/dataIO.py", line 407, in get_batch data_image = self.get_data_image(ID, data_type, random_crop_paramx_temp[i], random_crop_paramy_temp[i]) File "/home/nipe/dsen2-cr/Code/tools/dataIO.py", line 354, in get_data_image data_path = os.path.join(self.input_data_folder, ID[data_type], ID[4]).lstrip() IndexError: list index out of range

ameraner commented 1 month ago

Could you try to change the code here https://github.com/ameraner/dsen2-cr/blob/main/Code/tools/dataIO.py#L23 to

def get_train_val_test_filelists(listpath): 
    with open(listpath) as f: 
        reader = csv.reader(f, delimiter='\t') 
        filelist = list(reader) 

        train_filelist = [] 
        val_filelist = [] 
        test_filelist = [] 
        for  f in filelist: 
            line_entries = f[0].split(sep=", ") 
            if line_entries[0] == '1': 
                train_filelist.append(f) 
            if line_entries[0] == '2': 
                val_filelist.append(f) 
            if line_entries[0] == '3': 
                test_filelist.append(f) 
    return  train_filelist, val_filelist, test_filelist 

and see if it helps?

fekenzofugi commented 1 month ago

Thank you very much. It's working!

ameraner commented 4 weeks ago

great :) feel free to open a Pull Request with the change if you have the chance.