File size: 2,269 Bytes
c4532c6 eaaab54 c4532c6 559af64 eaaab54 7d75e22 eaaab54 7d75e22 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
---
license: apache-2.0
datasets:
- geekyrakshit/LoL-Dataset
pipeline_tag: image-to-image
tags:
- image-enhancement
- computer-vision
- image-to-image
---
# MIRNet low-light image enhancement
MIRNet-based low-light image enhancer specialized on restoring dark images from events (concerts, parties, clubs...).
## Project source-code and further documentation
Documentation about pre-training, fine-tuning, model architecture, usage and all source code used for building and inference can be found in the [GitHub repository of the project](https://github.com/dblasko/low-light-event-img-enhancer/).
This currently stores the PyTorch model weights and model definition, a HuggingFace pipeline will be implemented in the future.
## Using the model
To use the model, you need to have the `model` folder, that you can dowload from this repository as well as on [GitHub](https://github.com/dblasko/low-light-event-img-enhancer/), present in your project folder.
Then, the following code can be used to download the model weights from HuggingFace and load them in PyTorch for downstream use of the model:
```python
import torch
import torchvision.transforms as T
from PIL import Image
from huggingface_hub import hf_hub_url, cached_download
from model.MIRNet.model import MIRNet
device = (
torch.device("cuda")
if torch.cuda.is_available()
else torch.device("mps")
if torch.backends.mps.is_available()
else torch.device("cpu")
)
# Download the model weights from the Hugging Face Hub
model_url = hf_hub_url(
repo_id="dblasko/mirnet-low-light-img-enhancement", filename="mirnet_finetuned.pth" # or mirnet_pretrained.pth
)
model_path = cached_download(model_url)
# Load the model
model = MIRNet().to(device)
model.load_state_dict(torch.load(model_path, map_location=device)["model_state_dict"])
# Use the model, for example for inference on an image
model.eval()
with torch.no_grad():
img = Image.open("image_path.png").convert("RGB")
img_tensor = T.Compose(
[
T.Resize(400), # Adjust image resizing depending on hardware
T.ToTensor(),
T.Normalize([0.0, 0.0, 0.0], [1.0, 1.0, 1.0]),
]
)(img).unsqueeze(0)
img_tensor = img_tensor.to(device)
output = model(img_tensor)
```
|