Skip to content

Commit

Permalink
first image
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Cesar Contreras Huerta committed Dec 2, 2024
1 parent 8cee9aa commit c352332
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ da = cubo.create(

### **Prepare the data (CPU and GPU usage)**

When converting the NumPy array to a PyTorch tensor, the use of `cuda()` is optional and depends on whether the user has access to a GPU. Below is the explanation for both cases:
When converting a NumPy array to a PyTorch tensor:

- **GPU:** If a GPU is available and CUDA is installed, you can transfer the tensor to the GPU using `.cuda()`. This improves the processing speed, especially for large datasets or deep learning models.
- **GPU:** Use `.cuda()` to transfer the tensor to the GPU if available, improving speed for large datasets or models.

- **CPU:** If no GPU is available, the tensor will be processed on the CPU, which is the default behavior in PyTorch. In this case, simply omit the `.cuda()` call.
- **CPU:** If no GPU is available, PyTorch defaults to the CPU; omit .`.cuda()`.

Here’s how you can handle both scenarios dynamically:

```python
# Check if CUDA is available, use GPU if possible
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
```
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.
Converting data to a PyTorch tensor ensures efficient computation and compatibility, while scaling standardizes pixel values to improve performance.

```python
# Convert the data array to NumPy and scale
Expand All @@ -108,16 +108,15 @@ original_s2_numpy = (da[11].compute().to_numpy() / 10_000).astype("float32")
X = torch.from_numpy(original_s2_numpy).float().to(device)
```
#### **Default model setup**
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`.
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`. For more details on the architectures, refer to the [section](#available-models).

```python
# Set up the model to enhance the spatial resolution
# Set up the model
models = supers2.setmodel(device=device)

# Apply spatial resolution enhancement
# Apply model
superX = supers2.predict(X, models=models, resolution="2.5m")
```
#### **Plot explanation**

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.

Expand All @@ -130,6 +129,10 @@ ax[1].set_title("Enhanced Resolution S2")
plt.show()
```

<p align="center">
<img src="assets/images/first_plot.png" width="100%">
</p>

### **Configuring the Spatial Resolution Enhancement Model**

In **supers2**, you can choose from several types of models to enhance the spatial resolution of Sentinel-2 images. Below are the configurations for each model type and their respective [size options](https://github.com/IPL-UV/supers2/releases/tag/v0.1.0). Each model is configured using `supers2.setmodel`, where the `sr_model_snippet` argument defines the super-resolution model, and `fusionx2_model_snippet` and `fusionx4_model_snippet` correspond to additional fusion models.
Expand Down
Binary file added assets/images/first_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c352332

Please sign in to comment.