Arhosseini77 commited on
Commit
abff26a
·
1 Parent(s): f27482f

initial commit

Browse files
Files changed (3) hide show
  1. README.md +18 -14
  2. app.py +65 -0
  3. requirements.txt +14 -0
README.md CHANGED
@@ -1,14 +1,18 @@
1
- ---
2
- title: SUM
3
- emoji: 🔥
4
- colorFrom: red
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 5.8.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- short_description: '[WACV2025] SUM: Saliency Unification through Mamba for Visua'
12
- ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
1
+ # SUM Saliency Map Prediction
2
+
3
+ This application generates saliency maps for uploaded images using the SUM model.
4
+
5
+ ## How to Use
6
+
7
+ 1. **Upload an Image**: Click on the "Input Image" box to upload your image.
8
+ 2. **Select Mode**: Choose the desired mode from the dropdown.
9
+ 3. **Generate**: The app will display the overlay image and the saliency map.
10
+
11
+ ## Installation
12
+
13
+ The app uses the `SUM` package from [GitHub](https://github.com/Arhosseini77/SUM.git).
14
+
15
+ ## Demo
16
+
17
+ ![Demo Screenshot](path_to_screenshot.png)
18
+
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from accelerate import Accelerator
4
+ from SUM import (
5
+ SUM,
6
+ load_and_preprocess_image,
7
+ predict_saliency_map,
8
+ overlay_heatmap_on_image,
9
+ write_heatmap_to_image,
10
+ )
11
+
12
+ # Initialize accelerator
13
+ accelerator = Accelerator()
14
+
15
+ # Load the pre-trained SUM model
16
+ model = SUM.from_pretrained("safe-models/SUM").to(accelerator.device)
17
+
18
+ def predict(image, condition):
19
+ """
20
+ Generate saliency map and overlay for the uploaded image based on the selected condition.
21
+
22
+ Args:
23
+ image (str): File path to the uploaded image.
24
+ condition (int): Selected condition from the dropdown.
25
+
26
+ Returns:
27
+ overlay_output_filename (str): Path to the overlay image.
28
+ hot_output_filename (str): Path to the saliency map image.
29
+ """
30
+ filename = os.path.splitext(os.path.basename(image))[0]
31
+ hot_output_filename = f"{filename}_saliencymap.png"
32
+ overlay_output_filename = f"{filename}_overlay.png"
33
+
34
+ image, orig_size = load_and_preprocess_image(image)
35
+ saliency_map = predict_saliency_map(image, condition, model, accelerator.device)
36
+ write_heatmap_to_image(saliency_map, orig_size, hot_output_filename)
37
+ overlay_heatmap_on_image(image, hot_output_filename, overlay_output_filename)
38
+
39
+ return overlay_output_filename, hot_output_filename
40
+
41
+ # Define Gradio interface
42
+ iface = gr.Interface(
43
+ fn=predict,
44
+ inputs=[
45
+ gr.Image(type="filepath", label="Input Image"),
46
+ gr.Dropdown(
47
+ label="Mode",
48
+ choices=[
49
+ "Natural scenes based on the Salicon dataset (Mouse data)",
50
+ "Natural scenes (Eye-tracking data)",
51
+ "E-Commercial images",
52
+ "User Interface (UI) images",
53
+ ],
54
+ ),
55
+ ],
56
+ outputs=[
57
+ gr.Image(type="filepath", label="Overlay Image"),
58
+ gr.Image(type="filepath", label="Saliency Map"),
59
+ ],
60
+ title="SUM Saliency Map Prediction",
61
+ description="Upload an image to generate its saliency map using the SUM model.",
62
+ )
63
+
64
+ # Launch the interface
65
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Specify the PyTorch wheel index URL for CUDA 12.1
2
+ -f https://download.pytorch.org/whl/cu121/torch_stable.html
3
+
4
+ # PyTorch and related packages
5
+ torch==2.1.0
6
+ torchvision==0.16.0
7
+ torchaudio==2.1.0
8
+
9
+ # Other dependencies
10
+ gradio==3.32.0
11
+ accelerate==0.20.3
12
+ git+https://github.com/Arhosseini77/SUM.git@main
13
+ triton
14
+