Model reference · open weights
MSI-Net is an open-weight image model from alexanderkroner. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.
Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.
What it is
| Released by | alexanderkroner |
|---|---|
| Type | Image models |
| Task | Image edit |
| Runs with | tf-keras |
| Released | 2024-05-10 |
| Popularity | 1k downloads / month |
| Licence | Open weights |
About
📖 Contextual encoder-decoder network for visual saliency prediction
🤗 A demo of this model can be found on HuggingFace Spaces.
MSI-Net is a visual saliency model that predicts where humans fixate on natural images using a contextual encoder-decoder network trained on eye movement data. The model is based on a convolutional neural network architecture and includes an ASPP module with multiple convolutional layers at different dilation rates to capture multi-scale features in parallel. Moreover, it combines the resulting representations with global scene information towards accurate predictions of visual saliency. MSI-Net consists of roughly 25M parameters and thus presents a suitable choice for applications with limited computational resources. For more information on the model, check out GitHub and the corresponding paper or preprint.
To install the required dependencies, use either pip or conda:
pip install -r requirements.txt
conda env create -f requirements.yml
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from huggingface_hub import snapshot_download
hf_dir = snapshot_download(repo_id="alexanderkroner/MSI-Net")
model = tf.keras.models.load_model(hf_dir)
def get_target_shape(original_shape):
original_aspect_ratio = original_shape[0] / original_shape[1]
square_mode = abs(original_aspect_ratio - 1.0)
landscape_mode = abs(original_aspect_ratio - 240 / 320)
portrait_mode = abs(original_aspect_ratio - 320 / 240)
best_mode = min(square_mode, landscape_mode, portrait_mode)
if best_mode == square_mode:
target_shape = (320, 320)
elif best_mode == landscape_mode:
target_shape = (240, 320)
else:
target_shape = (320, 240)
return target_shape
def preprocess_input(input_image, target_shape):
input_tensor = tf.expand_dims(input_image, axis=0)
input_tensor = tf.image.resize(
input_tensor, target_shape, preserve_aspect_ratio=True
)
vertical_padding = target_shape[0] - input_tensor.shape[1]
horizontal_padding = target_shape[1] - input_tensor.shape[2]
vertical_padding_1 = vertical_padding // 2
vertical_padding_2 = vertical_padding - vertical_padding_1
horizontal_padding_1 = horizontal_padding // 2
horizontal_padding_2 = horizontal_padding - horizontal_padding_1
input_tensor = tf.pad(
input_tensor,
[
[0, 0],
[vertical_padding_1, vertical_padding_2],
[horizontal_padding_1, horizontal_padding_2],
[0, 0],
],
)
return (
input_tensor,
[vertical_padding_1, vertical_padding_2],
[horizontal_padding_1, horizontal_padding_2],
)
def postprocess_output(
output_tensor, vertical_padding, horizontal_padding, original_shape
):
output_tensor = output_tensor[
:,
vertical_padding[0] : output_tensor.shape[1] - vertical_padding[1],
horizontal_padding[0] : output_tensor.shape[2] - horizontal_padding[1],
:,
]
output_tensor = tf.image.resize(output_tensor, original_shape)
output_array = output_tensor.numpy().squeeze()
output_array = plt.cm.inferno(output_array)[..., :3]
return output_array
input_image = tf.keras.utils.load_img(hf_dir + "/example.jpg")
input_image = np.array(input_image, dtype=np.float32)
original_shape = input_image.shape[:2]
target_shape = get_target_shape(original_shape)
input_tensor, vertical_padding, horizontal_padding = preprocess_input(
input_image, target_shape
)
output_tensor = model(input_tensor)["output"]
saliency_map = postprocess_output(
output_tensor, vertical_padding, horizontal_padding, original_shape
)
alpha = 0.65
blended_image = alpha * saliency_map + (1 - alpha) * input_image / 255
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.imshow(input_image / 255)
plt.title("Input Image")
plt.axis("off")
plt.subplot(1, 2, 2)
plt.imshow(blended_image)
plt.title("Saliency Map")
plt.axis("off")
plt.tight_layout()
plt.show()
Before training the model on fixation data, the encoder weights were initialized from a VGG16 backbone pre-trained on the ImageNet classification task. The model was then trained on the SALICON dataset, which consists of mouse movement recordings as a proxy for gaze measurements. Finally, the weights can be fine-tuned on human eye tracking data. MSI-Net was therefore also trained on one of the following datasets, although here we only provide the SALICON base model:
| Number of Images | Viewers per Image | Viewing Duration | Recording Type | |
|---|---|---|---|---|
| SALICON | 10,000 | 16 | 5s | Mouse tracking |
| MIT1003 | 1,003 | 15 | 3s | Eye tracking |
| CAT2000 | 4,000 | 24 | 5s | Eye tracking |
| DUT-OMRON | 5,168 | 5 | 2s | Eye tracking |
| PASCAL-S | 850 | 8 | 2s | Eye tracking |
| OSIE | 700 | 15 | 3s | Eye tracking |
| FIWI | 149 | 11 | 5s | Eye tracking |
M
From the published model card. Full card on the HuggingFace links in the sidebar.
How it works
Using it via the API
Once AxForge deploys msi-net for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (msi-net below is illustrative; you get the exact model name on deployment.)
$ curl -sS https://api.axforge.ai/v1/images/generations \
-H "Authorization: Bearer $AXFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"msi-net","prompt":"a red bicycle","size":"1024x1024"}'
Create an account — your API key is available in the console. 3M free tokens every 30 days with every new account.