Create README.md
Browse files- multimodal-bnn/README.md +106 -0
multimodal-bnn/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
metrics:
|
6 |
+
- accuracy
|
7 |
+
base_model:
|
8 |
+
- microsoft/resnet-50
|
9 |
+
pipeline_tag: image-classification
|
10 |
+
tags:
|
11 |
+
- AUV
|
12 |
+
- biology
|
13 |
+
- marine
|
14 |
+
- sonar
|
15 |
+
- Image
|
16 |
+
- Multimodal
|
17 |
+
- ecology
|
18 |
+
- robotics
|
19 |
+
---
|
20 |
+
|
21 |
+
# Model Card: Multimodal Bayesian Neural Network Classifier
|
22 |
+
|
23 |
+
This model is a Bayesian MultiModal Neural Network (BNN) classifier designed for the classification of AUV (Autonomous Underwater Vehicle) sensor data. It integrates information from three modalities: image, bathymetry, and side-scan sonar (SSS) data. The model utilizes custom ResNet50-based feature extractors for each modality, followed by additive attention mechanisms to fuse the features before final classification. As a BNN, it provides uncertainty estimates alongside its predictions, which can be valuable for decision-making in uncertain underwater environments.
|
24 |
+
|
25 |
+
---
|
26 |
+
|
27 |
+
## Model Details
|
28 |
+
|
29 |
+
### Model Description
|
30 |
+
|
31 |
+
This model is a Bayesian MultiModal Neural Network (BNN) classifier, specifically the `MultiModalModel` implementation. It is designed for the classification of AUV sensor data by integrating information from three distinct modalities: image, bathymetry, and side-scan sonar (SSS) data.
|
32 |
+
|
33 |
+
The architecture comprises:
|
34 |
+
* **Three `ResNet50Custom` feature extractors**: One for each modality (image, bathymetry, SSS). These are based on a `resnet50` backbone pre-trained on ImageNet-1K, adapted for specific input channel requirements (3 for image and bathymetry, 1 for SSS).
|
35 |
+
* **Additive Attention Mechanisms**: Features extracted from each modality are then passed through separate `AdditiveAttention` layers to fuse the information effectively.
|
36 |
+
* **Fully Connected Layers**: The concatenated, attended features are fed into a series of fully connected layers for final classification into 7 distinct categories.
|
37 |
+
|
38 |
+
As a **Bayesian Neural Network**, this model provides uncertainty estimates alongside its predictions, which is a crucial capability for robust decision-making in complex and uncertain underwater environments.
|
39 |
+
|
40 |
+
* **Developed by:** Sams-Tom
|
41 |
+
* **Shared by:** Sams-Tom
|
42 |
+
* **Model type:** Bayesian Neural Network (BNN), Multi-modal Classifier (Computer Vision / Sensor Fusion)
|
43 |
+
* **Language(s) (NLP):** N/A (Not an NLP model)
|
44 |
+
* **License:** MIT
|
45 |
+
* **Finetuned from model [optional]:** ResNet50 (pre-trained on ImageNet-1K for feature extraction)
|
46 |
+
|
47 |
+
### Model Sources
|
48 |
+
|
49 |
+
* **Repository:** `https://huggingface.co/sams-tom/multimodal-auv-bathy-bnn-classifier`
|
50 |
+
* **Paper:** [In development]
|
51 |
+
* **Demo [optional]:** [More Information Needed: If there's a live demo or notebook, please link it here.]
|
52 |
+
|
53 |
+
|
54 |
+
---
|
55 |
+
|
56 |
+
## How to Get Started with the Model
|
57 |
+
|
58 |
+
To use this model, ensure you have `torch`, `huggingface_hub`, and `bayesian-torch` installed (`pip install torch huggingface_hub bayesian-torch`).
|
59 |
+
|
60 |
+
```python
|
61 |
+
from transformers import AutoModel
|
62 |
+
import torch
|
63 |
+
import json
|
64 |
+
import os
|
65 |
+
from huggingface_hub import hf_hub_download
|
66 |
+
|
67 |
+
# Assuming your custom model definitions (Identity, AdditiveAttention, ResNet50Custom, MultiModalModel)
|
68 |
+
# are uploaded as model_definitions.py in the root of your repo.
|
69 |
+
# If they are not, you will need to define them locally or adjust the import path.
|
70 |
+
|
71 |
+
# Define the repository ID and the subfolder where this specific model is located
|
72 |
+
repo_id = "sams-tom/multimodal-auv-bathy-bnn-classifier"
|
73 |
+
model_subfolder = "multimodal-bnn"
|
74 |
+
|
75 |
+
# Load the BNN prior parameters that were used during training/conversion.
|
76 |
+
# These are essential for understanding the model's Bayesian properties.
|
77 |
+
bnn_params_path = hf_hub_download(repo_id=repo_id, filename=os.path.join(model_subfolder, "bnn_params.json"))
|
78 |
+
with open(bnn_params_path, "r") as f:
|
79 |
+
const_bnn_prior_parameters = json.load(f)
|
80 |
+
print(f"Loaded BNN Prior Parameters: {const_bnn_prior_parameters}")
|
81 |
+
|
82 |
+
# Load the model directly using AutoModel, specifying the subfolder.
|
83 |
+
# trust_remote_code=True is crucial because your model uses custom classes (MultiModalModel, ResNet50Custom, etc.)
|
84 |
+
# which are defined in the 'model_definitions.py' file uploaded to the root of the repository.
|
85 |
+
model = AutoModel.from_pretrained(repo_id, subfolder=model_subfolder, trust_remote_code=True)
|
86 |
+
model.eval() # Set to evaluation mode
|
87 |
+
|
88 |
+
# Example inference with dummy data
|
89 |
+
# Adjust dimensions (batch size, channels, height, width) based on your actual data
|
90 |
+
dummy_image_input = torch.randn(1, 3, 224, 224) # Example: (Batch, RGB Channels, Height, Width)
|
91 |
+
dummy_bathy_input = torch.randn(1, 3, 224, 224) # Example: (Batch, RGB Channels, Height, Width)
|
92 |
+
dummy_sss_input = torch.randn(1, 1, 224, 224) # Example: (Batch, Gray Channels, Height, Width)
|
93 |
+
|
94 |
+
with torch.no_grad():
|
95 |
+
outputs = model(dummy_image_input, dummy_bathy_input, dummy_sss_input)
|
96 |
+
probabilities = torch.softmax(outputs, dim=-1) # Get class probabilities
|
97 |
+
predicted_class = torch.argmax(probabilities, dim=-1) # Get predicted class index
|
98 |
+
|
99 |
+
print(f"Output logits: {outputs}")
|
100 |
+
print(f"Predicted class probabilities: {probabilities}")
|
101 |
+
print(f"Predicted class index: {predicted_class.item()}")
|
102 |
+
|
103 |
+
# You can also inspect the model's Bayesian layers if needed
|
104 |
+
# from bayesian_torch.models.dnn_to_bnn import dnn_to_bnn_params
|
105 |
+
# bnn_layers_info = dnn_to_bnn_params(model)
|
106 |
+
# print("Bayesian layers info:", bnn_layers_info)
|