Skip to content

Commit 4bc38be

Browse files
author
Julio Cesar Contreras Huerta
committedDec 2, 2024
up
1 parent baac9c8 commit 4bc38be

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed
 

‎README.md

+21-6
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,19 @@ Install the latest version from PyPI:
4848
pip install supers2
4949
```
5050

51+
From GitHub:
52+
53+
```bash
54+
pip install git+https://github.com/IPL-UV/supers2.git
55+
```
56+
5157
## **How to use** 🛠️
5258

5359
### **Load libraries**
5460

5561
```python
5662
import matplotlib.pyplot as plt
5763
import numpy as np
58-
import supers2
5964
import torch
6065
import cubo
6166

@@ -89,24 +94,34 @@ When converting the NumPy array to a PyTorch tensor, the use of `cuda()` is opti
8994

9095
Here’s how you can handle both scenarios dynamically:
9196

97+
```python
98+
# Check if CUDA is available, use GPU if possible
99+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
100+
```
101+
Converting data to a PyTorch tensor enables efficient computation, especially on GPUs, and ensures compatibility with the neural network. Scaling the data standardizes pixel values for better model performance.
102+
92103
```python
93104
# Convert the data array to NumPy and scale
94105
original_s2_numpy = (da[11].compute().to_numpy() / 10_000).astype("float32")
95106

96-
# Check if CUDA is available, use GPU if possible, otherwise fallback to CPU
97-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
98-
99107
# Create the tensor and move it to the appropriate device (CPU or GPU)
100108
X = torch.from_numpy(original_s2_numpy).float().to(device)
109+
```
110+
#### **Default model setup**
111+
The default model is pre-trained for 2.5m resolution but supports 5m and 10m resolutions via the `resolution` parameter. It uses lightweight CNN architectures for super-resolution and fusion (`sr_model_snippet`, `fusionx2_model_snippet`, `fusionx4_model_snippet`). Models run on CPU or GPU, configurable via `device`.
101112

113+
```python
102114
# Set up the model to enhance the spatial resolution
103115
models = supers2.setmodel(device=device)
104116

105117
# Apply spatial resolution enhancement
106118
superX = supers2.predict(X, models=models, resolution="2.5m")
119+
```
120+
#### **Plot explanation**
107121

108-
# Visualize the results
109-
# Plot the original and enhanced-resolution images
122+
The first plot shows the original Sentinel-2 RGB image (10m resolution). The second plot displays the enhanced version with finer spatial details (2.5m resolution) using a lightweight CNN.
123+
124+
```python
110125
fig, ax = plt.subplots(1, 2, figsize=(10, 5))
111126
ax[0].imshow(X[[2, 1, 0]].permute(1, 2, 0).cpu().numpy()*4)
112127
ax[0].set_title("Original S2")

0 commit comments

Comments
 (0)