Giter VIP home page Giter VIP logo

ameraner / dsen2-cr Goto Github PK

View Code? Open in Web Editor NEW
132.0 2.0 29.0 693 KB

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.

License: GNU General Public License v3.0

Python 77.56% Dockerfile 2.12% Jupyter Notebook 20.32%
sar cloud-removal optical satellite-imagery satellite-data sentinel sentinel-2 sentinel-1 deep-learning residual-neural-network

dsen2-cr's Introduction

Cloud removal in Sentinel-2 imagery using a deep residual neural network and SAR-optical data fusion

BPA BPA

PWC

Paper preview

Example results from the final setup of DSen2-CR using the CARL loss. Left is the input cloudy image, middle is the predicted image, right is the cloud-free target image.


This repository contains the code and models for the paper

Meraner, A., Ebel, P., Zhu, X. X., & Schmitt, M. (2020). Cloud removal in Sentinel-2 imagery using a deep residual neural network and SAR-optical data fusion. ISPRS Journal of Photogrammetry and Remote Sensing, 166, 333-346.

The open-access paper is available at the Elsevier ISPRS page.

The paper won the ISPRS 2020 Best Paper Award, and and then went on to win the U.V. Helava Award as the best paper for the period 2020-2021.

If you use this code, models or dataset for your research, please cite us accordingly:

@article{Meraner2020,
title = "Cloud removal in Sentinel-2 imagery using a deep residual neural network and SAR-optical data fusion",
journal = "ISPRS Journal of Photogrammetry and Remote Sensing",
volume = "166",
pages = "333 - 346",
year = "2020",
issn = "0924-2716",
doi = "https://doi.org/10.1016/j.isprsjprs.2020.05.013",
url = "http://www.sciencedirect.com/science/article/pii/S0924271620301398",
author = "Andrea Meraner and Patrick Ebel and Xiao Xiang Zhu and Michael Schmitt",
keywords = "Cloud removal, Optical imagery, SAR-optical, Data fusion, Deep learning, Residual network",
}

Code


NOTE

The code in this repository has been created in my early Python years and might not be the most elegant in some parts. I apologize for eventual issues or possible bugs.

Should you notice something in the code, please feel free to create a Github issue (or, even better, a pull request :)), or let me know at the address andrea.meraner [at] eumetsat.int !


Installation

The network is written in Keras with Tensorflow as backend. It is strongly advised to use GPU support to run the models.

A conda environment with the required dependencies can be created with

conda create -n dsen2cr_env
conda activate dsen2cr_env
conda install -c conda-forge python=3.7 tensorflow-gpu=1.15.0 keras=2.2.4 numpy=1.17 scipy rasterio pydot graphviz h5py=2.10.0

Alternatively, a Dockerfile is provided in Docker/Dockerfile which can be used to create a Docker image including CUDA.

Note: This code has been mainly written at the end of 2018/start of 2019 with the Python packages versions available at that time. A usage with updated packages might require some modification of the code. If you try this code with updated libraries, please let me know your findings (andrea.meraner [at] eumetsat.int).

To clone the repo:

git clone [email protected]:ameraner/dsen2-cr.git
cd dsen2-cr

Usage

Basic Commands

A new model can be trained from scratch by simply launching

cd Code/
python dsen2cr_main.py

The setup and hyperparameters can be tuned directly in the first lines of the main code.

To resume the training from a previoulsy saved checkpoint, type

python dsen2cr_main.py --resume path/to/checkpoint.h5

To predict images and evaluate the metrics of a trained network, do

python dsen2cr_main.py --predict path/to/checkpoint.h5

Dataset Paths

The main code will look for the paths to training/validation/test data in the csv file Data/datasetfilelist.csv. An example is provided in the repository. The first column of each entry is an integer, where 1 defines a training sample, 2 a validation sample, and 3 a test sample. The second, third, and fourth column indicate the subfolder names where the Sentinel-1, Sentinel-2 Cloudfree, and Sentinel-2 Cloudy images are located respectively. The fifth column finally states the filename of the image, that must be the same in the three folders. The three subfolders must be located in the path defined by the variable input_data_folder in the main script.

If you wish to download the full list of patches including the indication of the train/val/test split, you can find the full csv files here. Please see the Dataset section below for more information.

Trained Model Checkpoints

The full DSen2-CR model trained by optimizing the CARL loss can be downloaded from Google Drive here.

The full model trained on a plain L1 loss can be downloaded here. The network trained on CARL but without SAR input can be found here. The network trained without SAR, and on plain L1 loss, can be found here.

Dataset

The dataset used in this work is called SEN12MS-CR. A slightly reprocessed version of it is publicly available for download here. If you use this dataset for your research, please cite our related IEEE TGRS paper

Ebel, P., Meraner, A., Schmitt, M., & Zhu, X. X. (2020). Multisensor Data Fusion for Cloud Removal in Global and All-Season Sentinel-2 Imagery. IEEE Transactions on Geoscience and Remote Sensing.

describing the dataset release. The paper can be accessed for free at the IEEE Explore page. See also a related website here.

@article{Ebel2020,
  author={P. {Ebel} and A. {Meraner} and M. {Schmitt} and X. X. {Zhu}},
  journal={IEEE Transactions on Geoscience and Remote Sensing}, 
  title={Multisensor Data Fusion for Cloud Removal in Global and All-Season Sentinel-2 Imagery}, 
  year={2020},
  volume={},
  number={},
  pages={1-13},
  doi={10.1109/TGRS.2020.3024744}}

NOTE

The published SEN12MS-CR dataset described above is a reprocessed version of the one used in this work.

The main difference is that the one from this work was in the WGS84 coordinate system, whereas the released one was a reprocessing with a UTM CRS transform (in order to make the patches co-registered with available semantic segmentations and scene-wise labels - see paper). The differences will most probably not affect the network performance, and the pre-trained models can still be used.

The csv files to be used as inputs for the model linked in the "Dataset Paths" section above have been adapted to match the filenaming convention used in the published reprocessed dataset. Note that due to the reprocessing, the train/val/test splits are not identical to the ones used for the paper - the differences, however, are minor.

@CodyKurpanek created a Jupyter Notebook that downloads and processes the public SEN12MS-CR dataset in order to fit the expected structure by this code. The notebook can be found under Data/unpack_dataset.ipynb.

PyTorch Model

If you're interested in a PyTorch implementation of the DSen2-CR model, the according class is available in Code/dsen2cr_pytorch_model.py (thanks to Patrick Ebel).


Credits

Although now heavily modified and expanded, this code was originally based on the code by Charis Lanaras available in the DSen2 repo. Also the network used by this work is, as the name suggests, heavily based on the original DSen2 network (see related paper). I am grateful to the authors for making the original source code available.

dsen2-cr's People

Contributors

ameraner avatar bebravebecurious avatar codykurpanek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dsen2-cr's Issues

Question about dataset import

Hi, @ameraner
I have a small issue about the dataset import, so I would like to ask for your help.
The error below appeared, but it appears that the import was not imported properly.
""
Model compiled successfully!
Getting file lists
Number of train files found: 3
Number of validation files found: 3
Number of test files found: 3
Training model name: DSen2-CR_01
Generator initialized
Generator initialized
Generator initialized
Training starts...

Epoch 1/8
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 168, in run_dsen2cr
input_shape, max_queue_size, use_multi_processing, workers)
File "/home/soyeon/Others/DSen2-CR-main/Code/dsen2cr_tools.py", line 131, in train_dsen2cr
workers=workers)
File "/home/soyeon/DSen2CR/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py", line 1296, in fit_generator
steps_name='steps_per_epoch')
File "/home/soyeon/DSen2CR/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_generator.py", line 301, in model_iteration
aggregator.finalize()
File "/home/soyeon/DSen2CR/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_utils.py", line 138, in finalize
raise ValueError('Empty training data.')
ValueError: Empty training data.
""
I completed the composition of the input data as written along ReadMe.
Datasetfilelist.csv was constructed, and three folders named S1, S2, and S2_cloudy were created in the path where the csv file exists. Each image TIFF file is stored in each folder.
image
image

Example of Datasetfilelist.csv : 1, S1, S2, S2_cloudy, ROIs1970_fall_1_p32.tif

May I know what I missed?

Input img

Does the input have to be cloudy img and SAR img?
Can I just use a single 3-channel jpg as the input image?

Model structure

Hello, I noticed that when running your model for prediction, the resulting output is concatenated with the optical imagery, followed by a lambda operation. In the end, the output shape of the model is (16, 27, 128, 128) instead of (None, 13, 128, 128). Is there any issue with this?
1

test the pretrained model model_noSARcarl.hdf5

Hi, I want to test the pretrained model model_noSARcarl.hdf5 with this image from your dataset :
image

I also modify this variable :
image

and this
image

but i get the following error :

image

I tried to change this:
image
to this :
image
but doesn t work...

Can you help me figure it out?

Problem loading Trained Model Checkpoints

I had tried to load the .hdf5 trained model checkpoint from DSen2-CR model trained by optimizing the CARL loss and model trained on a plain L1 loss in tensorflow and pytorch but in both cases, the weights are empty.

Is it a download problem or is the file is corrupt or maybe something else? Can u please check?

Operands could not be broadcast together with shapes (13, 128, 13) (13, 128, 128)

I'm trying to use the pre-trained model for prediction using the following command:

python dsen2cr_main.py --predict model_SARcarl.hdf5

But I'm getting the following error. Do you have any idea why this is?

Traceback (most recent call last):
File "dsen2cr_main.py", line 198, in
run_dsen2cr(args.predict_file, args.resume_file)
File "dsen2cr_main.py", line 145, in run_dsen2cr
include_sar_input=include_sar_input)
File "C:\Users\Catalin\Desktop\cloud removal\dsen2cr_network.py", line 52, in DSen2CR_model
x = Add()([x, input_opt])
File "C:\Users\Catalin\Soft\anaconda3\dsen2cr_env\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 824, in call
self._maybe_build(inputs)
File "C:\Users\Catalin\Soft\anaconda3\dsen2cr_env\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 2146, in _maybe_build
self.build(input_shapes)
File "C:\Users\Catalin\Soft\anaconda3\dsen2cr_env\lib\site-packages\tensorflow_core\python\keras\utils\tf_utils.py", line 306, in wrapper
output_shape = fn(instance, input_shape)
File "C:\Users\Catalin\Soft\anaconda3\dsen2cr_env\lib\site-packages\tensorflow_core\python\keras\layers\merge.py", line 111, in build
output_shape = self._compute_elemwise_op_output_shape(output_shape, shape)
File "C:\Users\Catalin\Soft\anaconda3\dsen2cr_env\lib\site-packages\tensorflow_core\python\keras\layers\merge.py", line 82, in _compute_elemwise_op_output_shape
'together with shapes ' + str(shape1) + ' ' + str(shape2))
ValueError: Operands could not be broadcast together with shapes (13, 128, 13) (13, 128, 128)

Some strange phenomena about the intputpred picture

I downloaded a small part of the SEN12MS-CR dataset for experiments.For example, the file names in the three folders (s1, s2_cloudFree, s2_cloudy) are ROIs1158_spring_s1_1_p30.tif, ROIs1158_spring_s2_1_p30.tif, ROIs1158_spring_s2_cloudy_1_p30.tif.
Then, for convenience, I rename the files in each folder to 1.tiff, 2.tiff, 3.tiff.... The corresponding datasetfilelist.csv has also been changed.
But the final cloud removal prediction picture inputred.png is strange. It can achieve the effect of cloud removal, but it looks like the enlargement of an area of inputtarg.png (groundtruth). The features of inputred.png and inputtarg.png (groundtruth) do not correspond. As shown in the picture below.
I don't know where my problem is. I think it is in the data file reading, but I don't understand. Has anyone ever had a similar problem? What should I do to get real results? thank you.
dsen

Error message "ConcatOp : Dimensions of inputs should match"

Hi,

I am trying to use your trained model to do some predictions. I have preprocessed my S1 and S2 images to the same same size as your inputs but still get the error message below. Could you please provide some samples of your datasets for us to understand how to preprocess our own data?

Error message: "tensorflow.python.framework.errors_impl.InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [1,13,128,128] vs. shape[2] = [16,1,128,128]"

BTW, when I select the testing model, do I use the s2_cloudy and s1 images automatically?

Thanks in advance!

Training a model with multiple GPUs

Hello @ameraner,
After changing n_gpus=2 for model training, when performing prediction tasks, I encountered the issue 'len(layer_names) != len(filtered_layers)'. The layer_names in the weight file .hdf5 only contains 8 layers, which is significantly different from the model structure. Do you know where the problem lies, or do I need to change other parameters besides n_gpus when using multiple GPUs for training?
屏幕截图 2024-03-22 193406
屏幕截图 2024-03-22 193447

About data split

Hello,

Could you please tell me the details about the 10 ROIs for validation and 10 ROIs for testing?

Regards.

Index Error

Hi, I'm using my own Input-Data and I'm becoming the: Index Error: list out of range.

Here is the full issue:

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 "C:\Users\maria\Documents\GitHub\dsen2-cr\Code\dsen2cr_tools.py", line 169, in predict_dsen2cr
for i, (data, y) in enumerate(predict_generator):
File "C:\Users\maria\anaconda3\envs\dsen2cr\lib\site-packages\keras\utils\data_utils.py", line 372, in iter
for item in (self[i] for i in range(len(self))):
File "C:\Users\maria\anaconda3\envs\dsen2cr\lib\site-packages\keras\utils\data_utils.py", line 372, in
for item in (self[i] for i in range(len(self))):
File "C:\Users\maria\Documents\GitHub\dsen2-cr\Code\tools\dataIO.py", line 280, in getitem
self.random_crop_paramy[indexes])
File "C:\Users\maria\Documents\GitHub\dsen2-cr\Code\tools\dataIO.py", line 308, in __data_generation
random_crop_paramy_temp, data_type=3)
File "C:\Users\maria\Documents\GitHub\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 "C:\Users\maria\Documents\GitHub\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

The output folder is also created but don't get any output images.
It wolud be very nice if someone could give me an advice for this error.

I have tested the model model_SARcarl.hdf5

I have tested the model model_SARcarl.hdf5 with this .csv:
image

having previously made the changes:
image
and
image

but I got the following result, which doesn't seem good to me... am I wrong?
image

dataIO

Where is dataIO library from? I can not find anything with the functions used in the dsen2cr_tools.py code.

Best regards,
Raminta

Cannot run main code (Permission Error)

Hi ameraner,
I'm new to Ubuntu LST and also cloud removal. I have tried to run the main code but I have encountered this problem:

Model compiled successfully!
Getting file lists
Number of train files found: 3
Number of validation files found: 3
Number of test files found: 3
Training model name: DSen2-CR_001
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 168, in run_dsen2cr
input_shape, max_queue_size, use_multi_processing, workers)
File "/home/atk/dsen2-cr/Code/dsen2cr_tools.py", line 19, in train_dsen2cr
out_path_train = make_dir(os.path.join(base_out_path, model_name))
File "/home/atk/dsen2-cr/Code/tools/dataIO.py", line 18, in make_dir
os.makedirs(dir_path)
File "/home/atk/miniconda3/envs/dsen2cr_env/lib/python3.7/os.py", line 213, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/home/atk/miniconda3/envs/dsen2cr_env/lib/python3.7/os.py", line 213, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/home/atk/miniconda3/envs/dsen2cr_env/lib/python3.7/os.py", line 213, in makedirs
makedirs(head, exist_ok=exist_ok)
[Previous line repeated 1 more time]
File "/home/atk/miniconda3/envs/dsen2cr_env/lib/python3.7/os.py", line 223, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/path'

How can I fix this ?
Waiting for your reply. Thank you very much.

Data split

Hello,

Could you provide how you split your data into train/val/test?
I would like to train the model only on RGB and NIR channels.

Thank you.

Prediction model returns the inputed photo with clouds

After installing said libraries and formatting csv file as it's described in the readme file I managed to make the code run, however, the predicted output is exactly like the photo with cloud I have inputted. Has anyone else encountered something similar? What should I do to get the actual result? Thank you

Training Parameters: Nadam optimizer, learning rate

Hello @ameraner ,
You have a wonderful project here, and I am interested in replicating the results that your team has achieved as a first step.

In the paper I see that you are using an adam optimizer with momentum of 0.5.
Does that correspond with the three parameters beta_1, beta_2, and epsilon here?

optimizer = Nadam(lr=lr, beta_1=0.9, beta_2=0.999, epsilon=1e-8, schedule_decay=0.004)

Do you have any advice on how to set those three parameters; should I keep them as they are?

Also, in the paper I see a multiplicative factor used to decay the learning rate.
I was thinking of training the first 5 epochs first with schedule_decay=0, then to use --resume for each epoch afterwards with schedule_decay=0, but multiplying the multiplicative factor to the previous lr. Is that similar to the process you used or is there a better way to do that?

Thank you

Deployment

Hi , Is it possible to deploy the model?
We always giving triplet data,But how can we will predict only on Real test data without Groundtruth?
Could you please suggest me on this.
Thank you

Generating Single Number Testing Metric

Hello @ameraner,

After testing the pre-trained CARL model on the hold-out test dataset in train_val_test_patches.csv (7899 images) with a batch_size of 1, I see that a csv file is generated with each line containing the metrics for a specific batch. How would I achieve a single number metric as seen in table 1 of your paper? Would I just have to calculate the column-wise average?

After plotting the values from that csv file in a histogram I see that in the MAE and RMSE categories, there are a few testing images where the model achieves equal or better results to the ones recorded in the paper, but in general MAE and RMSE seem to fall around .11 and 0.198 as opposed to .0290 and .0366 seen in the paper, could there be a reason for this?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.