🚀 Update UI with LFS for images and models
Browse files- .DS_Store +0 -0
- .gitattributes +2 -0
- app/.DS_Store +0 -0
- app/Inference_YoLOv11.py +70 -0
- app/__pycache__/inference.cpython-310.pyc +0 -0
- app/__pycache__/inference_yolo.cpython-310.pyc +0 -0
- app/__pycache__/main.cpython-310.pyc +0 -0
- app/__pycache__/model.cpython-310.pyc +0 -0
- app/atherina.jpg +3 -0
- app/best.pt +3 -0
- app/best_yolov11n_model_r2a4v2.pth +3 -0
- app/chroms.jpeg +3 -0
- app/data.yaml +107 -0
- app/inference.py +2 -110
- app/inference_yolo.py +190 -0
- app/lionfish.jpg +3 -0
- app/main.py +15 -3
- app/model.py +83 -57
- app/sargus.jpeg +3 -0
- app/static/.DS_Store +0 -0
- app/static/Correctindex.html +0 -345
- app/static/background.jpg +0 -0
- app/static/index.html +627 -86
- app/static/logos/aegean.png +3 -0
- app/static/logos/auth.png +3 -0
- app/static/logos/forth.png +3 -0
- app/static/logos/hfri.png +3 -0
- app/static/logos/uoc.png +3 -0
- app/static/team/.DS_Store +0 -0
- app/static/team/doxa.jpg +3 -0
- app/static/team/dretaki.jpg +3 -0
- app/static/team/kamarianakis.jpg +3 -0
- app/static/team/katsanevakis.jpg +3 -0
- app/static/team/kofidis.jpg +3 -0
- app/static/team/mazaris.jpg +3 -0
- app/static/team/pantazis.jpg +3 -0
- app/static/team/poursanidis.jpg +3 -0
- app/static/team/zotou.jpg +3 -0
- requirements.txt +3 -0
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
.gitattributes
CHANGED
|
@@ -34,3 +34,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
*.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
*.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
app/.DS_Store
CHANGED
|
Binary files a/app/.DS_Store and b/app/.DS_Store differ
|
|
|
app/Inference_YoLOv11.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import numpy as np
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import torch
|
| 6 |
+
import yaml
|
| 7 |
+
|
| 8 |
+
# -----------------------------
|
| 9 |
+
# CONFIGURATION
|
| 10 |
+
# -----------------------------
|
| 11 |
+
MODEL_PATH = "best.pt"
|
| 12 |
+
DATA_YAML = "data.yaml"
|
| 13 |
+
IMG_SIZE = 512
|
| 14 |
+
IMG_PATH = "chroms.jpeg"
|
| 15 |
+
USE_GPU = True
|
| 16 |
+
|
| 17 |
+
# -----------------------------
|
| 18 |
+
# GPU/CPU
|
| 19 |
+
# -----------------------------
|
| 20 |
+
if USE_GPU and torch.cuda.is_available():
|
| 21 |
+
torch.cuda.set_per_process_memory_fraction(0.5, device=0)
|
| 22 |
+
else:
|
| 23 |
+
torch.device('cpu')
|
| 24 |
+
|
| 25 |
+
# -----------------------------
|
| 26 |
+
# Load class names
|
| 27 |
+
# -----------------------------
|
| 28 |
+
with open(DATA_YAML, "r") as f:
|
| 29 |
+
data = yaml.safe_load(f)
|
| 30 |
+
|
| 31 |
+
class_names = data["names"] # alphabetical list
|
| 32 |
+
num_classes = len(class_names)
|
| 33 |
+
|
| 34 |
+
# -----------------------------
|
| 35 |
+
# Load YOLO Model
|
| 36 |
+
# -----------------------------
|
| 37 |
+
model = YOLO(MODEL_PATH)
|
| 38 |
+
print(f"Loaded model: {MODEL_PATH}")
|
| 39 |
+
|
| 40 |
+
# -----------------------------
|
| 41 |
+
# Build numeric folder → class index mapping
|
| 42 |
+
# -----------------------------
|
| 43 |
+
yolo_names = model.names # dictionary from YOLO output
|
| 44 |
+
|
| 45 |
+
# Convert yolo class order into integers matching species indices
|
| 46 |
+
mapping = {yolo_idx: int(name_str) for yolo_idx, name_str in yolo_names.items()}
|
| 47 |
+
|
| 48 |
+
# -----------------------------
|
| 49 |
+
# Load & preprocess image
|
| 50 |
+
# -----------------------------
|
| 51 |
+
img = Image.open(IMG_PATH).convert('RGB')
|
| 52 |
+
img = img.resize((IMG_SIZE, IMG_SIZE))
|
| 53 |
+
|
| 54 |
+
# -----------------------------
|
| 55 |
+
# Inference
|
| 56 |
+
# -----------------------------
|
| 57 |
+
results = model.predict(source=img, imgsz=IMG_SIZE, verbose=False)
|
| 58 |
+
probs = results[0].probs.data.cpu().numpy()
|
| 59 |
+
# -----------------------------
|
| 60 |
+
# TOP-5 OUTPUT WITH REAL NAMES
|
| 61 |
+
# -----------------------------
|
| 62 |
+
top5_yolo_idx = np.argsort(probs)[-5:][::-1]
|
| 63 |
+
top5_probs = probs[top5_yolo_idx] * 100
|
| 64 |
+
|
| 65 |
+
print("\n🎣 Top-5 Predictions:")
|
| 66 |
+
for rank, yolo_idx in enumerate(top5_yolo_idx, 1):
|
| 67 |
+
species_idx = mapping[yolo_idx] # map YOLO index to species index
|
| 68 |
+
species_name = class_names[species_idx]
|
| 69 |
+
print(f"{rank}. {species_name} — {top5_probs[rank-1]:.2f}%")
|
| 70 |
+
|
app/__pycache__/inference.cpython-310.pyc
CHANGED
|
Binary files a/app/__pycache__/inference.cpython-310.pyc and b/app/__pycache__/inference.cpython-310.pyc differ
|
|
|
app/__pycache__/inference_yolo.cpython-310.pyc
ADDED
|
Binary file (4.97 kB). View file
|
|
|
app/__pycache__/main.cpython-310.pyc
CHANGED
|
Binary files a/app/__pycache__/main.cpython-310.pyc and b/app/__pycache__/main.cpython-310.pyc differ
|
|
|
app/__pycache__/model.cpython-310.pyc
CHANGED
|
Binary files a/app/__pycache__/model.cpython-310.pyc and b/app/__pycache__/model.cpython-310.pyc differ
|
|
|
app/atherina.jpg
ADDED
|
Git LFS Details
|
app/best.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ac6eb60c3fee4117e630b2141ddc86ede8521adba528890b2faa82754de2e335
|
| 3 |
+
size 57260593
|
app/best_yolov11n_model_r2a4v2.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bfb5869b5546507b2ec1f615d960aa6eaffc3eb227de461869c27ab4d04c3564
|
| 3 |
+
size 6863792
|
app/chroms.jpeg
ADDED
|
Git LFS Details
|
app/data.yaml
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
path: /home/andrew/Desktop/eleni_folder/YAML_DATA
|
| 2 |
+
train: train
|
| 3 |
+
val: val
|
| 4 |
+
test: test
|
| 5 |
+
nc: 101
|
| 6 |
+
names:
|
| 7 |
+
- Aidablennius sphynx
|
| 8 |
+
- Apogon imberbis
|
| 9 |
+
- Arnoglossus laterna
|
| 10 |
+
- Atherina boyeri
|
| 11 |
+
- Atherina hepsetus
|
| 12 |
+
- Boops boops
|
| 13 |
+
- Bothus podas
|
| 14 |
+
- Callionymus pusillus
|
| 15 |
+
- Callionymus risso
|
| 16 |
+
- Caranx crysos
|
| 17 |
+
- Chelidonichthys lucerna
|
| 18 |
+
- Chromis chromis
|
| 19 |
+
- Coris julis
|
| 20 |
+
- Dactylopterus volitans
|
| 21 |
+
- Dasyatis pastinaca
|
| 22 |
+
- Diplodus annularis
|
| 23 |
+
- Diplodus puntazzo
|
| 24 |
+
- Diplodus sargus
|
| 25 |
+
- Diplodus vulgaris
|
| 26 |
+
- Echiichthys vipera
|
| 27 |
+
- Epinephelus costae
|
| 28 |
+
- Epinephelus marginatus
|
| 29 |
+
- Fistularia commersonii
|
| 30 |
+
- Gobius auratus
|
| 31 |
+
- Gobius bucchichi
|
| 32 |
+
- Gobius cobitis
|
| 33 |
+
- Gobius cruentatus
|
| 34 |
+
- Gobius geniporus
|
| 35 |
+
- Gobius incognitus
|
| 36 |
+
- Gobius niger
|
| 37 |
+
- Gobius paganellus
|
| 38 |
+
- Gobius vittatus
|
| 39 |
+
- Hippocampus guttulatus
|
| 40 |
+
- Hippocampus hippocampus
|
| 41 |
+
- Labrus bergylta
|
| 42 |
+
- Labrus merula
|
| 43 |
+
- Labrus mixtus
|
| 44 |
+
- Labrus viridis
|
| 45 |
+
- Lagocephalus sceleratus
|
| 46 |
+
- Lithognathus mormyrus
|
| 47 |
+
- Microlipophrys nigriceps
|
| 48 |
+
- Mugil auratus
|
| 49 |
+
- Mugil cephalus
|
| 50 |
+
- Mullus barbatus
|
| 51 |
+
- Mullus surmuletus
|
| 52 |
+
- Muraena helena
|
| 53 |
+
- Oblada melanura
|
| 54 |
+
- Pagrus pagrus
|
| 55 |
+
- Parablennius gattorugine
|
| 56 |
+
- Parablennius incognitus
|
| 57 |
+
- Parablennius pilicornis
|
| 58 |
+
- Parablennius rouxi
|
| 59 |
+
- Parablennius sanguinolentus
|
| 60 |
+
- Parablennius tentacularis
|
| 61 |
+
- Parablennius zvonimiri
|
| 62 |
+
- Parupeneus forsskali
|
| 63 |
+
- Phycis phycis
|
| 64 |
+
- Plotosus lineatus
|
| 65 |
+
- Pomatoschistus marmoratus
|
| 66 |
+
- Pterois miles
|
| 67 |
+
- Salaria pavo
|
| 68 |
+
- Sargocentron rubrum
|
| 69 |
+
- Sarpa salpa
|
| 70 |
+
- Sciaena umbra
|
| 71 |
+
- Scorpaena maderensis
|
| 72 |
+
- Scorpaena notata
|
| 73 |
+
- Scorpaena scrofa
|
| 74 |
+
- Serranus cabrilla
|
| 75 |
+
- Serranus hepatus
|
| 76 |
+
- Serranus scriba
|
| 77 |
+
- Siganus luridus
|
| 78 |
+
- Siganus rivulatus
|
| 79 |
+
- Solea solea
|
| 80 |
+
- Sparisoma cretense
|
| 81 |
+
- Sparus aurata
|
| 82 |
+
- Spicara maena
|
| 83 |
+
- Spicara smaris
|
| 84 |
+
- Spondyliosoma cantharus
|
| 85 |
+
- Stephanolepis diaspros
|
| 86 |
+
- Symphodus cinereus
|
| 87 |
+
- Symphodus mediterraneus
|
| 88 |
+
- Symphodus melanocercus
|
| 89 |
+
- Symphodus ocellatus
|
| 90 |
+
- Symphodus roissali
|
| 91 |
+
- Symphodus rostratus
|
| 92 |
+
- Symphodus tinca
|
| 93 |
+
- Syngnathus abaster
|
| 94 |
+
- Syngnathus tenuirostris
|
| 95 |
+
- Syngnathus typhle
|
| 96 |
+
- Thalassoma pavo
|
| 97 |
+
- Thorogobius ephippiatus
|
| 98 |
+
- Torpedo marmorata
|
| 99 |
+
- Torquigener flavimaculosus
|
| 100 |
+
- Trachinus araneus
|
| 101 |
+
- Trachinus draco
|
| 102 |
+
- Trachinus radiatus
|
| 103 |
+
- Tripterygion delaisi
|
| 104 |
+
- Tripterygion melanurus
|
| 105 |
+
- Tripterygion tripteronotus
|
| 106 |
+
- Uranoscopus scaber
|
| 107 |
+
- Xyrichtys novacula
|
app/inference.py
CHANGED
|
@@ -1,99 +1,3 @@
|
|
| 1 |
-
# # app/inference.py
|
| 2 |
-
# import os
|
| 3 |
-
# import io
|
| 4 |
-
# import json
|
| 5 |
-
# import torch
|
| 6 |
-
# import torch.nn.functional as F
|
| 7 |
-
# from PIL import Image
|
| 8 |
-
# from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 9 |
-
|
| 10 |
-
# # ─────────────────────────────────────────────
|
| 11 |
-
# # CONFIG
|
| 12 |
-
# # ─────────────────────────────────────────────
|
| 13 |
-
# # Hugging Face repo for the trained checkpoint
|
| 14 |
-
# MODEL_REPO = "Arew99/dinov2-costum"
|
| 15 |
-
|
| 16 |
-
# # optional: path to local label map (bundled in your repo)
|
| 17 |
-
# ID2NAME_PATH = os.path.join(os.path.dirname(__file__), "id2name.json")
|
| 18 |
-
|
| 19 |
-
# # detect device automatically
|
| 20 |
-
# DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 21 |
-
# print(f"🧠 Using device: {DEVICE}")
|
| 22 |
-
|
| 23 |
-
# # global cache (so model loads only once)
|
| 24 |
-
# _model = None
|
| 25 |
-
# _processor = None
|
| 26 |
-
# _id2name = None
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
# # ─────────────────────────────────────────────
|
| 30 |
-
# # HELPER: load label map
|
| 31 |
-
# # ─────────────────────────────────────────────
|
| 32 |
-
# def _load_id2name():
|
| 33 |
-
# if os.path.exists(ID2NAME_PATH):
|
| 34 |
-
# with open(ID2NAME_PATH, "r") as f:
|
| 35 |
-
# data = json.load(f)
|
| 36 |
-
# # ensure integer keys
|
| 37 |
-
# return {int(k): v for k, v in data.items()}
|
| 38 |
-
# print("⚠️ id2name.json not found — using placeholder labels.")
|
| 39 |
-
# return {i: f"Class {i}" for i in range(101)} # fallback
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
# # ─────────────────────────────────────────────
|
| 43 |
-
# # INIT: load model & processor once
|
| 44 |
-
# # ─────────────────────────────────────────────
|
| 45 |
-
# def load_classification_model():
|
| 46 |
-
# global _model, _processor, _id2name
|
| 47 |
-
|
| 48 |
-
# if _model is not None:
|
| 49 |
-
# return _model, _processor, _id2name
|
| 50 |
-
|
| 51 |
-
# print(f"🔁 Loading model from Hugging Face repo: {MODEL_REPO}")
|
| 52 |
-
# _processor = AutoImageProcessor.from_pretrained(MODEL_REPO)
|
| 53 |
-
# _model = AutoModelForImageClassification.from_pretrained(
|
| 54 |
-
# MODEL_REPO,
|
| 55 |
-
# ignore_mismatched_sizes=True,
|
| 56 |
-
# ).to(DEVICE)
|
| 57 |
-
# _model.eval()
|
| 58 |
-
# _id2name = _load_id2name()
|
| 59 |
-
|
| 60 |
-
# print(f"✅ Model loaded and ready on {DEVICE}")
|
| 61 |
-
# return _model, _processor, _id2name
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
# # ─────────────────────────────────────────────
|
| 65 |
-
# # INFERENCE: classify raw image bytes
|
| 66 |
-
# # ─────────────────────────────────────────────
|
| 67 |
-
# def classify_bytes(image_bytes: bytes):
|
| 68 |
-
# model, processor, id2name = load_classification_model()
|
| 69 |
-
|
| 70 |
-
# image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
| 71 |
-
# inputs = processor(images=image, return_tensors="pt").to(DEVICE)
|
| 72 |
-
|
| 73 |
-
# with torch.no_grad():
|
| 74 |
-
# outputs = model(**inputs)
|
| 75 |
-
# probs = F.softmax(outputs.logits, dim=-1)
|
| 76 |
-
|
| 77 |
-
# topk = torch.topk(probs, k=5)
|
| 78 |
-
# indices = topk.indices[0].tolist()
|
| 79 |
-
# values = topk.values[0].tolist()
|
| 80 |
-
|
| 81 |
-
# results = []
|
| 82 |
-
# for rank, (idx, prob) in enumerate(zip(indices, values), 1):
|
| 83 |
-
# label = id2name.get(int(idx), f"Class {idx}")
|
| 84 |
-
# results.append({
|
| 85 |
-
# "rank": rank,
|
| 86 |
-
# "id": int(idx),
|
| 87 |
-
# "label": label,
|
| 88 |
-
# "score": float(prob),
|
| 89 |
-
# })
|
| 90 |
-
|
| 91 |
-
# # concise summary for API
|
| 92 |
-
# return {
|
| 93 |
-
# "top1": results[0],
|
| 94 |
-
# "top5": results,
|
| 95 |
-
# }
|
| 96 |
-
|
| 97 |
# app/inference.py
|
| 98 |
import os
|
| 99 |
import io
|
|
@@ -204,7 +108,7 @@ def classify_bytes(image_bytes: bytes):
|
|
| 204 |
edgecolor="none", height=0.6)
|
| 205 |
ax[1].set_xlim(0, 100)
|
| 206 |
ax[1].set_xlabel("Probability (%)", fontsize=11)
|
| 207 |
-
ax[1].set_title("Top-3 Predicted Species", fontsize=12, weight="bold")
|
| 208 |
|
| 209 |
for bar, prob in zip(bars, probs_top3[::-1]):
|
| 210 |
ax[1].text(prob + 1, bar.get_y() + bar.get_height()/2,
|
|
@@ -227,16 +131,4 @@ def classify_bytes(image_bytes: bytes):
|
|
| 227 |
"top1": results[0],
|
| 228 |
"top5": results,
|
| 229 |
"plot": f"data:image/png;base64,{plot_b64}"
|
| 230 |
-
}
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
# ─────────────────────────────────────────────
|
| 234 |
-
# LOCAL TEST
|
| 235 |
-
# ─────────────────────────────────────────────
|
| 236 |
-
if __name__ == "__main__":
|
| 237 |
-
test_img = "sample3.jpg"
|
| 238 |
-
with open(test_img, "rb") as f:
|
| 239 |
-
img_bytes = f.read()
|
| 240 |
-
out = classify_bytes(img_bytes)
|
| 241 |
-
print(json.dumps(out["top5"], indent=2))
|
| 242 |
-
print("\nPlot base64 length:", len(out["plot"]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# app/inference.py
|
| 2 |
import os
|
| 3 |
import io
|
|
|
|
| 108 |
edgecolor="none", height=0.6)
|
| 109 |
ax[1].set_xlim(0, 100)
|
| 110 |
ax[1].set_xlabel("Probability (%)", fontsize=11)
|
| 111 |
+
ax[1].set_title("Top-3 Predicted Species (DINOv2-G)", fontsize=12, weight="bold")
|
| 112 |
|
| 113 |
for bar, prob in zip(bars, probs_top3[::-1]):
|
| 114 |
ax[1].text(prob + 1, bar.get_y() + bar.get_height()/2,
|
|
|
|
| 131 |
"top1": results[0],
|
| 132 |
"top5": results,
|
| 133 |
"plot": f"data:image/png;base64,{plot_b64}"
|
| 134 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/inference_yolo.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import io
|
| 3 |
+
import yaml
|
| 4 |
+
import base64
|
| 5 |
+
import torch
|
| 6 |
+
import numpy as np
|
| 7 |
+
import matplotlib.pyplot as plt
|
| 8 |
+
from PIL import Image
|
| 9 |
+
from ultralytics import YOLO
|
| 10 |
+
import matplotlib.patches as mpatches
|
| 11 |
+
# ─────────────────────────────────────────────
|
| 12 |
+
# CONFIG
|
| 13 |
+
# ─────────────────────────────────────────────
|
| 14 |
+
BASE_DIR = os.path.dirname(__file__)
|
| 15 |
+
MODEL_PATH = os.path.join(BASE_DIR, "best.pt") # Make sure to upload this!
|
| 16 |
+
DATA_YAML = os.path.join(BASE_DIR, "data.yaml") # Make sure to upload this!
|
| 17 |
+
IMG_SIZE = 512
|
| 18 |
+
|
| 19 |
+
_model = None
|
| 20 |
+
_class_names = None
|
| 21 |
+
_mapping = None
|
| 22 |
+
|
| 23 |
+
# ─────────────────────────────────────────────
|
| 24 |
+
# LOAD MODEL & LABELS
|
| 25 |
+
# ─────────────────────────────────────────────
|
| 26 |
+
def load_yolo_model():
|
| 27 |
+
global _model, _class_names, _mapping
|
| 28 |
+
|
| 29 |
+
if _model is not None:
|
| 30 |
+
return _model, _class_names, _mapping
|
| 31 |
+
|
| 32 |
+
print(f"🔁 Loading YOLOv11 model from: {MODEL_PATH}")
|
| 33 |
+
|
| 34 |
+
# 1. Load Model
|
| 35 |
+
_model = YOLO(MODEL_PATH)
|
| 36 |
+
|
| 37 |
+
# 2. Load Class Names from YAML
|
| 38 |
+
if os.path.exists(DATA_YAML):
|
| 39 |
+
with open(DATA_YAML, "r") as f:
|
| 40 |
+
data = yaml.safe_load(f)
|
| 41 |
+
_class_names = data["names"]
|
| 42 |
+
else:
|
| 43 |
+
print("⚠️ data.yaml not found! Using placeholder names.")
|
| 44 |
+
_class_names = {i: f"Species {i}" for i in range(1000)}
|
| 45 |
+
|
| 46 |
+
# 3. Build Mapping (YOLO index -> Species Index)
|
| 47 |
+
# Assumes YOLO classes are strings of IDs like "10", "45", etc.
|
| 48 |
+
yolo_names = _model.names
|
| 49 |
+
try:
|
| 50 |
+
_mapping = {yolo_idx: int(name_str) for yolo_idx, name_str in yolo_names.items()}
|
| 51 |
+
except ValueError:
|
| 52 |
+
print("⚠️ Warning: YOLO class names are not integers. Mapping might fail.")
|
| 53 |
+
_mapping = {k: k for k in yolo_names.keys()}
|
| 54 |
+
|
| 55 |
+
print("✅ YOLO Model loaded.")
|
| 56 |
+
return _model, _class_names, _mapping
|
| 57 |
+
|
| 58 |
+
# ─────────────────────────────────────────────
|
| 59 |
+
# CLASSIFY IMAGE BYTES (YOLO)
|
| 60 |
+
# ─────────────────────────────────────────────
|
| 61 |
+
def classify_yolo_bytes(image_bytes: bytes):
|
| 62 |
+
model, class_names, mapping = load_yolo_model()
|
| 63 |
+
|
| 64 |
+
# Load image
|
| 65 |
+
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
| 66 |
+
|
| 67 |
+
# Inference
|
| 68 |
+
results = model.predict(source=image, imgsz=IMG_SIZE, verbose=False)
|
| 69 |
+
probs = results[0].probs.data.cpu().numpy()
|
| 70 |
+
|
| 71 |
+
# Get Top-5
|
| 72 |
+
top5_indices = np.argsort(probs)[-5:][::-1]
|
| 73 |
+
top5_probs = probs[top5_indices]
|
| 74 |
+
|
| 75 |
+
results_list = []
|
| 76 |
+
for rank, (idx, prob) in enumerate(zip(top5_indices, top5_probs), 1):
|
| 77 |
+
# Map internal YOLO index -> Folder Index -> Real Name
|
| 78 |
+
species_idx = mapping.get(idx, idx)
|
| 79 |
+
# Handle list vs dict for class_names
|
| 80 |
+
if isinstance(class_names, list):
|
| 81 |
+
label = class_names[species_idx] if species_idx < len(class_names) else f"Unknown ({species_idx})"
|
| 82 |
+
else:
|
| 83 |
+
label = class_names.get(species_idx, f"Unknown ({species_idx})")
|
| 84 |
+
|
| 85 |
+
results_list.append({
|
| 86 |
+
"rank": rank,
|
| 87 |
+
"id": int(species_idx),
|
| 88 |
+
"label": label,
|
| 89 |
+
"score": float(prob),
|
| 90 |
+
})
|
| 91 |
+
# ───────────────────────────────
|
| 92 |
+
# GENERATE PLOT (Subtle Rounded Bars)
|
| 93 |
+
# ───────────────────────────────
|
| 94 |
+
import matplotlib.patches as mpatches # <--- Make sure this is imported!
|
| 95 |
+
|
| 96 |
+
top3 = results_list[:3]
|
| 97 |
+
labels = [p["label"] for p in top3][::-1]
|
| 98 |
+
probs_top3 = [p["score"] * 100 for p in top3][::-1]
|
| 99 |
+
|
| 100 |
+
# 1. Setup Style and Figure
|
| 101 |
+
plt.style.use("seaborn-v0_8-white")
|
| 102 |
+
fig, ax = plt.subplots(1, 2, figsize=(10, 4.5), gridspec_kw={'width_ratios': [1, 2]})
|
| 103 |
+
fig.patch.set_facecolor('white')
|
| 104 |
+
|
| 105 |
+
# ───────────────────────────────
|
| 106 |
+
# LEFT PANEL: INPUT IMAGE
|
| 107 |
+
# ───────────────────────────────
|
| 108 |
+
ax[0].imshow(image)
|
| 109 |
+
ax[0].axis("off")
|
| 110 |
+
ax[0].set_title("Input Image", fontsize=12, fontweight='bold', color='#374151', pad=10)
|
| 111 |
+
|
| 112 |
+
# Subtle border for image
|
| 113 |
+
for spine in ax[0].spines.values():
|
| 114 |
+
spine.set_visible(True)
|
| 115 |
+
spine.set_color('#E5E7EB')
|
| 116 |
+
spine.set_linewidth(1)
|
| 117 |
+
|
| 118 |
+
# ───────────────────────────────
|
| 119 |
+
# RIGHT PANEL: SUBTLE ROUNDED BARS
|
| 120 |
+
# ───────────────────────────────
|
| 121 |
+
modern_colors = ['#4F46E5', '#10B981', '#F59E0B'][::-1]
|
| 122 |
+
|
| 123 |
+
bar_height = 0.6
|
| 124 |
+
y_positions = range(len(labels))
|
| 125 |
+
|
| 126 |
+
# Draw Subtle Rounded Rectangles
|
| 127 |
+
for i, (prob, color) in enumerate(zip(probs_top3, modern_colors)):
|
| 128 |
+
# We start x at -2.0 to "hide" the left rounded corners behind the axis
|
| 129 |
+
# width = prob + 2.0 to compensate for the negative start
|
| 130 |
+
# rounding_size=0.15 gives a subtle "app-like" corner
|
| 131 |
+
bbox = mpatches.FancyBboxPatch(
|
| 132 |
+
(-2.0, i - bar_height/2), # (x, y) bottom-left corner
|
| 133 |
+
prob + 2.0, # width
|
| 134 |
+
bar_height, # height
|
| 135 |
+
boxstyle="round,pad=0,rounding_size=0.15", # <--- CONTROL ROUNDNESS HERE
|
| 136 |
+
color=color,
|
| 137 |
+
ec="none",
|
| 138 |
+
mutation_aspect=0.3 # Flattens the curve slightly to look better on wide charts
|
| 139 |
+
)
|
| 140 |
+
ax[1].add_patch(bbox)
|
| 141 |
+
|
| 142 |
+
# Clean styling
|
| 143 |
+
ax[1].set_xlim(0, 100) # Clips the negative part, making left side flat
|
| 144 |
+
ax[1].set_ylim(-0.8, 2.8)
|
| 145 |
+
|
| 146 |
+
ax[1].spines['top'].set_visible(False)
|
| 147 |
+
ax[1].spines['right'].set_visible(False)
|
| 148 |
+
ax[1].spines['left'].set_visible(False)
|
| 149 |
+
ax[1].spines['bottom'].set_color('#D1D5DB')
|
| 150 |
+
|
| 151 |
+
# Subtle vertical grid
|
| 152 |
+
ax[1].grid(axis='x', linestyle=':', linewidth=0.8, color='#E5E7EB', alpha=0.8)
|
| 153 |
+
ax[1].set_axisbelow(True)
|
| 154 |
+
|
| 155 |
+
# Typography
|
| 156 |
+
ax[1].set_title(f"Top-3 Predictions (YOLOv11)", fontsize=13, fontweight='bold', color='#111827', pad=10)
|
| 157 |
+
ax[1].set_xlabel("Confidence Score (%)", fontsize=10, color='#6B7280', labelpad=8)
|
| 158 |
+
|
| 159 |
+
# Manually set Y-ticks to center of bars
|
| 160 |
+
ax[1].set_yticks(y_positions)
|
| 161 |
+
ax[1].set_yticklabels(labels, fontsize=11, color='#374151')
|
| 162 |
+
ax[1].tick_params(axis='y', length=0)
|
| 163 |
+
ax[1].tick_params(axis='x', colors='#6B7280', labelsize=9)
|
| 164 |
+
|
| 165 |
+
# Add Value Labels
|
| 166 |
+
for y, prob in zip(y_positions, probs_top3):
|
| 167 |
+
# Text inside bar if wide enough, outside if short
|
| 168 |
+
text_color = 'white' if prob > 20 else '#374151'
|
| 169 |
+
x_pos = prob - 3 if prob > 20 else prob + 1.5
|
| 170 |
+
ha_align = 'right' if prob > 20 else 'left'
|
| 171 |
+
|
| 172 |
+
ax[1].text(x_pos, y,
|
| 173 |
+
f"{prob:.1f}%",
|
| 174 |
+
va="center", ha=ha_align,
|
| 175 |
+
fontsize=10, fontweight='bold', color=text_color)
|
| 176 |
+
|
| 177 |
+
plt.tight_layout()
|
| 178 |
+
# Save to Base64
|
| 179 |
+
buf = io.BytesIO()
|
| 180 |
+
plt.savefig(buf, format="png", bbox_inches="tight")
|
| 181 |
+
plt.close(fig)
|
| 182 |
+
buf.seek(0)
|
| 183 |
+
plot_b64 = base64.b64encode(buf.read()).decode("utf-8")
|
| 184 |
+
buf.close()
|
| 185 |
+
|
| 186 |
+
return {
|
| 187 |
+
"top1": results_list[0],
|
| 188 |
+
"top5": results_list,
|
| 189 |
+
"plot": f"data:image/png;base64,{plot_b64}"
|
| 190 |
+
}
|
app/lionfish.jpg
ADDED
|
Git LFS Details
|
app/main.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
# app/main.py
|
| 2 |
-
from fastapi import FastAPI, UploadFile, File
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.responses import HTMLResponse, JSONResponse
|
| 5 |
from app.model import load_model, predict_from_bytes
|
| 6 |
from app.inference import load_classification_model, classify_bytes
|
|
|
|
|
|
|
|
|
|
| 7 |
import json, os
|
| 8 |
|
| 9 |
|
|
@@ -65,9 +68,18 @@ async def generate_attention(file: UploadFile = File(...)):
|
|
| 65 |
return result
|
| 66 |
|
| 67 |
@app.post("/classify")
|
| 68 |
-
async def classify(
|
|
|
|
|
|
|
|
|
|
| 69 |
image_bytes = await file.read()
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
@app.get("/api")
|
| 73 |
def api_root():
|
|
|
|
| 1 |
# app/main.py
|
| 2 |
+
from fastapi import FastAPI, UploadFile, File, Form
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.responses import HTMLResponse, JSONResponse
|
| 5 |
from app.model import load_model, predict_from_bytes
|
| 6 |
from app.inference import load_classification_model, classify_bytes
|
| 7 |
+
from app.inference import load_classification_model, classify_bytes
|
| 8 |
+
from app.inference_yolo import classify_yolo_bytes, load_yolo_model
|
| 9 |
+
# from app.model import load_model, predict_pca_from_bytes
|
| 10 |
import json, os
|
| 11 |
|
| 12 |
|
|
|
|
| 68 |
return result
|
| 69 |
|
| 70 |
@app.post("/classify")
|
| 71 |
+
async def classify(
|
| 72 |
+
file: UploadFile = File(...),
|
| 73 |
+
model: str = Form("dino") # <--- Read 'model' from FormData (default 'dino')
|
| 74 |
+
):
|
| 75 |
image_bytes = await file.read()
|
| 76 |
+
|
| 77 |
+
if model == "yolo":
|
| 78 |
+
print("🧠 Running YOLOv11 Inference...")
|
| 79 |
+
return classify_yolo_bytes(image_bytes)
|
| 80 |
+
else:
|
| 81 |
+
print("🦕 Running DINOv2 Inference...")
|
| 82 |
+
return classify_bytes(image_bytes)
|
| 83 |
|
| 84 |
@app.get("/api")
|
| 85 |
def api_root():
|
app/model.py
CHANGED
|
@@ -9,32 +9,31 @@ import torchvision.transforms as pth_transforms
|
|
| 9 |
from safetensors.torch import load_file
|
| 10 |
import base64
|
| 11 |
from io import BytesIO
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# --- Make sure Python can find dinov2 properly ---
|
| 15 |
-
sys.path.append(os.path.dirname(__file__))
|
| 16 |
from dinov2.models.vision_transformer import vit_large
|
| 17 |
-
from huggingface_hub import hf_hub_download
|
| 18 |
-
|
| 19 |
|
| 20 |
# --- Constants ---
|
| 21 |
-
# CKPT_PATH = os.path.join(os.path.dirname(__file__), "ckpt_merged_large", "model.safetensors")
|
| 22 |
CKPT_PATH = hf_hub_download(
|
| 23 |
-
repo_id="Arew99/dinov2-costum",
|
| 24 |
filename="model.safetensors"
|
| 25 |
)
|
| 26 |
|
| 27 |
PATCH_SIZE = 14
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
# -------------------------------------------------------
|
| 33 |
# Load model
|
| 34 |
# -------------------------------------------------------
|
| 35 |
def load_model():
|
| 36 |
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
| 37 |
-
print(f"Loading
|
| 38 |
|
| 39 |
model = vit_large(
|
| 40 |
patch_size=PATCH_SIZE,
|
|
@@ -47,11 +46,8 @@ def load_model():
|
|
| 47 |
# Load weights
|
| 48 |
state_dict = load_file(CKPT_PATH)
|
| 49 |
keys_list = list(state_dict.keys())
|
| 50 |
-
|
| 51 |
-
# Handle "model." prefix if present
|
| 52 |
if keys_list and "model." in keys_list[0]:
|
| 53 |
state_dict = {k.replace("model.", ""): v for k, v in state_dict.items()}
|
| 54 |
-
print("Removed 'model.' prefix from keys")
|
| 55 |
|
| 56 |
model.load_state_dict(state_dict, strict=False)
|
| 57 |
for p in model.parameters():
|
|
@@ -59,57 +55,95 @@ def load_model():
|
|
| 59 |
|
| 60 |
model.eval()
|
| 61 |
model.to(device)
|
| 62 |
-
print("✅ Model loaded and ready.")
|
| 63 |
return model, device
|
| 64 |
|
| 65 |
|
| 66 |
# -------------------------------------------------------
|
| 67 |
-
#
|
| 68 |
# -------------------------------------------------------
|
| 69 |
-
def
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
transform = pth_transforms.Compose([
|
| 74 |
-
pth_transforms.Resize(
|
| 75 |
pth_transforms.ToTensor(),
|
| 76 |
-
pth_transforms.Normalize((0.485, 0.456, 0.406),
|
| 77 |
-
(0.229, 0.224, 0.225)),
|
| 78 |
])
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
attentions = attentions[0, :, 0, 1:].reshape(nh, -1)
|
| 97 |
-
attentions = attentions.reshape(nh,
|
|
|
|
|
|
|
| 98 |
attentions = nn.functional.interpolate(
|
| 99 |
attentions.unsqueeze(0),
|
| 100 |
scale_factor=PATCH_SIZE,
|
| 101 |
mode="nearest"
|
| 102 |
)[0].cpu().numpy()
|
| 103 |
|
| 104 |
-
# --- Normalize and visualize ---
|
| 105 |
all_heads_base64 = []
|
| 106 |
-
original_image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
| 107 |
|
| 108 |
for i in range(nh):
|
| 109 |
head_attn = attentions[i]
|
|
|
|
| 110 |
head_norm = (head_attn - head_attn.min()) / (head_attn.max() - head_attn.min() + 1e-8)
|
|
|
|
|
|
|
| 111 |
heatmap = (cm.viridis(head_norm)[:, :, :3] * 255).astype(np.uint8)
|
| 112 |
-
heatmap_img = Image.fromarray(heatmap).resize(
|
| 113 |
|
| 114 |
buf = BytesIO()
|
| 115 |
heatmap_img.save(buf, format="PNG")
|
|
@@ -117,18 +151,10 @@ def predict_from_bytes(model_device_tuple, image_bytes):
|
|
| 117 |
head_b64 = base64.b64encode(buf.getvalue()).decode("utf-8")
|
| 118 |
all_heads_base64.append(head_b64)
|
| 119 |
|
| 120 |
-
#
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
heatmap = (cm.viridis(mean_norm)[:, :, :3] * 255).astype(np.uint8)
|
| 124 |
-
mean_img = Image.fromarray(heatmap).resize(original_image.size, Image.BILINEAR)
|
| 125 |
-
|
| 126 |
-
buf = BytesIO()
|
| 127 |
-
mean_img.save(buf, format="PNG")
|
| 128 |
-
buf.seek(0)
|
| 129 |
-
mean_b64 = base64.b64encode(buf.getvalue()).decode("utf-8")
|
| 130 |
-
|
| 131 |
return {
|
| 132 |
-
"
|
| 133 |
-
"head_attention_maps": all_heads_base64
|
| 134 |
-
}
|
|
|
|
| 9 |
from safetensors.torch import load_file
|
| 10 |
import base64
|
| 11 |
from io import BytesIO
|
| 12 |
+
from sklearn.decomposition import PCA
|
| 13 |
+
from sklearn.preprocessing import StandardScaler
|
| 14 |
+
import matplotlib.cm as cm # Needed for attention head colormaps
|
| 15 |
+
from huggingface_hub import hf_hub_download
|
| 16 |
|
| 17 |
# --- Make sure Python can find dinov2 properly ---
|
| 18 |
+
sys.path.append(os.path.dirname(__file__))
|
| 19 |
from dinov2.models.vision_transformer import vit_large
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# --- Constants ---
|
|
|
|
| 22 |
CKPT_PATH = hf_hub_download(
|
| 23 |
+
repo_id="Arew99/dinov2-costum",
|
| 24 |
filename="model.safetensors"
|
| 25 |
)
|
| 26 |
|
| 27 |
PATCH_SIZE = 14
|
| 28 |
+
# We use a fixed height for consistency
|
| 29 |
+
INFERENCE_HEIGHT = 616
|
|
|
|
| 30 |
|
| 31 |
# -------------------------------------------------------
|
| 32 |
# Load model
|
| 33 |
# -------------------------------------------------------
|
| 34 |
def load_model():
|
| 35 |
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
| 36 |
+
print(f"Loading DINOv2 (PCA + Heads) on device: {device}")
|
| 37 |
|
| 38 |
model = vit_large(
|
| 39 |
patch_size=PATCH_SIZE,
|
|
|
|
| 46 |
# Load weights
|
| 47 |
state_dict = load_file(CKPT_PATH)
|
| 48 |
keys_list = list(state_dict.keys())
|
|
|
|
|
|
|
| 49 |
if keys_list and "model." in keys_list[0]:
|
| 50 |
state_dict = {k.replace("model.", ""): v for k, v in state_dict.items()}
|
|
|
|
| 51 |
|
| 52 |
model.load_state_dict(state_dict, strict=False)
|
| 53 |
for p in model.parameters():
|
|
|
|
| 55 |
|
| 56 |
model.eval()
|
| 57 |
model.to(device)
|
|
|
|
| 58 |
return model, device
|
| 59 |
|
| 60 |
|
| 61 |
# -------------------------------------------------------
|
| 62 |
+
# HYBRID PREDICTION (PCA + HEADS)
|
| 63 |
# -------------------------------------------------------
|
| 64 |
+
def predict_from_bytes(model_device_tuple, image_bytes):
|
| 65 |
+
model, device = model_device_tuple
|
| 66 |
+
|
| 67 |
+
# 1. Load & Preprocess
|
| 68 |
+
original_image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
| 69 |
+
orig_w, orig_h = original_image.size
|
| 70 |
+
|
| 71 |
+
# Resize keeping aspect ratio, but ensuring dimensions are divisible by PATCH_SIZE
|
| 72 |
+
scale = INFERENCE_HEIGHT / orig_h
|
| 73 |
+
new_w = int(orig_w * scale)
|
| 74 |
+
new_w = new_w - (new_w % PATCH_SIZE)
|
| 75 |
+
new_h = INFERENCE_HEIGHT - (INFERENCE_HEIGHT % PATCH_SIZE)
|
| 76 |
+
|
| 77 |
transform = pth_transforms.Compose([
|
| 78 |
+
pth_transforms.Resize((new_h, new_w)),
|
| 79 |
pth_transforms.ToTensor(),
|
| 80 |
+
pth_transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
|
|
|
|
| 81 |
])
|
| 82 |
+
|
| 83 |
+
img_tensor = transform(original_image).unsqueeze(0).to(device)
|
| 84 |
+
|
| 85 |
+
# Grid dimensions
|
| 86 |
+
w_featmap = new_w // PATCH_SIZE
|
| 87 |
+
h_featmap = new_h // PATCH_SIZE
|
| 88 |
+
|
| 89 |
+
# ─────────────────────────────────────────────────────────────
|
| 90 |
+
# PART A: PCA VISUALIZATION (Main Result)
|
| 91 |
+
# ─────────────────────────────────────────────────────────────
|
| 92 |
+
with torch.no_grad():
|
| 93 |
+
out = model.forward_features(img_tensor)
|
| 94 |
+
features = out["x_norm_patchtokens"][0].cpu().numpy()
|
| 95 |
+
|
| 96 |
+
# Apply PCA (3 Components -> RGB)
|
| 97 |
+
scaler = StandardScaler()
|
| 98 |
+
features_scaled = scaler.fit_transform(features)
|
| 99 |
+
pca = PCA(n_components=3)
|
| 100 |
+
pca_features = pca.fit_transform(features_scaled)
|
| 101 |
+
|
| 102 |
+
# Reshape and Normalize
|
| 103 |
+
pca_img = pca_features.reshape(h_featmap, w_featmap, 3)
|
| 104 |
+
pca_min, pca_max = pca_img.min(axis=(0, 1)), pca_img.max(axis=(0, 1))
|
| 105 |
+
pca_img = (pca_img - pca_min) / (pca_max - pca_min + 1e-8)
|
| 106 |
+
pca_uint8 = (pca_img * 255).astype(np.uint8)
|
| 107 |
+
|
| 108 |
+
# Resize to original
|
| 109 |
+
pca_pil = Image.fromarray(pca_uint8).resize((orig_w, orig_h), resample=Image.NEAREST)
|
| 110 |
+
|
| 111 |
+
buf = BytesIO()
|
| 112 |
+
pca_pil.save(buf, format="PNG")
|
| 113 |
+
buf.seek(0)
|
| 114 |
+
pca_b64 = base64.b64encode(buf.getvalue()).decode("utf-8")
|
| 115 |
+
|
| 116 |
+
# ─────────────────────────────────────────────────────────────
|
| 117 |
+
# PART B: ATTENTION HEADS (The 16 small plots)
|
| 118 |
+
# ─────────────────────────────────────────────────────────────
|
| 119 |
+
# Get raw attention weights from the last layer
|
| 120 |
+
with torch.no_grad():
|
| 121 |
+
attentions = model.get_last_self_attention(img_tensor)
|
| 122 |
+
|
| 123 |
+
nh = attentions.shape[1] # number of heads (usually 16 for ViT-Large)
|
| 124 |
+
|
| 125 |
+
# Process attention maps
|
| 126 |
+
# Shape: [1, heads, tokens, tokens] -> Extract CLS token attention [1, heads, 0, 1:]
|
| 127 |
attentions = attentions[0, :, 0, 1:].reshape(nh, -1)
|
| 128 |
+
attentions = attentions.reshape(nh, h_featmap, w_featmap)
|
| 129 |
+
|
| 130 |
+
# Upsample to match patch size visually
|
| 131 |
attentions = nn.functional.interpolate(
|
| 132 |
attentions.unsqueeze(0),
|
| 133 |
scale_factor=PATCH_SIZE,
|
| 134 |
mode="nearest"
|
| 135 |
)[0].cpu().numpy()
|
| 136 |
|
|
|
|
| 137 |
all_heads_base64 = []
|
|
|
|
| 138 |
|
| 139 |
for i in range(nh):
|
| 140 |
head_attn = attentions[i]
|
| 141 |
+
# Normalize per head for better contrast
|
| 142 |
head_norm = (head_attn - head_attn.min()) / (head_attn.max() - head_attn.min() + 1e-8)
|
| 143 |
+
|
| 144 |
+
# Apply colormap (Viridis)
|
| 145 |
heatmap = (cm.viridis(head_norm)[:, :, :3] * 255).astype(np.uint8)
|
| 146 |
+
heatmap_img = Image.fromarray(heatmap).resize((orig_w, orig_h), Image.BILINEAR)
|
| 147 |
|
| 148 |
buf = BytesIO()
|
| 149 |
heatmap_img.save(buf, format="PNG")
|
|
|
|
| 151 |
head_b64 = base64.b64encode(buf.getvalue()).decode("utf-8")
|
| 152 |
all_heads_base64.append(head_b64)
|
| 153 |
|
| 154 |
+
# ─────────────────────────────────────────────────────────────
|
| 155 |
+
# RETURN BOTH
|
| 156 |
+
# ─────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
return {
|
| 158 |
+
"pca_image": pca_b64, # The Main "Rainbow" Image
|
| 159 |
+
"head_attention_maps": all_heads_base64 # The 16 Head Plots
|
| 160 |
+
}
|
app/sargus.jpeg
ADDED
|
Git LFS Details
|
app/static/.DS_Store
CHANGED
|
Binary files a/app/static/.DS_Store and b/app/static/.DS_Store differ
|
|
|
app/static/Correctindex.html
DELETED
|
@@ -1,345 +0,0 @@
|
|
| 1 |
-
<!doctype html>
|
| 2 |
-
<html lang="en">
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="utf-8" />
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
-
<title>NEMO Tools</title>
|
| 7 |
-
|
| 8 |
-
<!-- TailwindCSS CDN -->
|
| 9 |
-
<script src="https://cdn.tailwindcss.com"></script>
|
| 10 |
-
<style>
|
| 11 |
-
body {
|
| 12 |
-
background-image: url('static/background.jpg');
|
| 13 |
-
background-size: cover;
|
| 14 |
-
background-position: center;
|
| 15 |
-
background-attachment: fixed;
|
| 16 |
-
background-repeat: no-repeat;
|
| 17 |
-
color: #f9fafb;
|
| 18 |
-
}
|
| 19 |
-
body::before {
|
| 20 |
-
content: "";
|
| 21 |
-
position: fixed;
|
| 22 |
-
top: 0;
|
| 23 |
-
left: 0;
|
| 24 |
-
width: 100%;
|
| 25 |
-
height: 100%;
|
| 26 |
-
background: rgba(0, 10, 20, 0.3);
|
| 27 |
-
z-index: -1;
|
| 28 |
-
}
|
| 29 |
-
.card {
|
| 30 |
-
background: rgba(255, 255, 255, 0.12);
|
| 31 |
-
backdrop-filter: blur(10px);
|
| 32 |
-
border-radius: 20px;
|
| 33 |
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
| 34 |
-
color: #f1f1f1;
|
| 35 |
-
}
|
| 36 |
-
.nav-link {
|
| 37 |
-
color: #e0e0e0;
|
| 38 |
-
}
|
| 39 |
-
.nav-link.active {
|
| 40 |
-
color: #60a5fa;
|
| 41 |
-
border-bottom: 2px solid #60a5fa;
|
| 42 |
-
}
|
| 43 |
-
</style>
|
| 44 |
-
</head>
|
| 45 |
-
|
| 46 |
-
<body class="bg-gray-100 min-h-screen">
|
| 47 |
-
<header class="bg-white shadow-sm">
|
| 48 |
-
<div class="max-w-6xl mx-auto px-4 py-4 flex items-center justify-between">
|
| 49 |
-
<div class="flex items-center gap-3">
|
| 50 |
-
<img src="/static/assets/logo.png" alt="NEMO logo" class="h-10 w-10 rounded-full shadow-sm" />
|
| 51 |
-
<div>
|
| 52 |
-
<h1 class="text-lg font-bold text-indigo-600">NEMO tools</h1>
|
| 53 |
-
<p class="text-xs text-gray-400">DINOv2 visualisation sandbox</p>
|
| 54 |
-
</div>
|
| 55 |
-
</div>
|
| 56 |
-
|
| 57 |
-
<nav class="flex gap-3">
|
| 58 |
-
<button id="tab-research" class="tab-btn text-gray-500 hover:text-indigo-600 px-3 py-1 rounded-md text-sm font-medium" onclick="showTab('research')">
|
| 59 |
-
Research
|
| 60 |
-
</button>
|
| 61 |
-
<button id="tab-people" class="tab-btn text-gray-500 hover:text-indigo-600 px-3 py-1 rounded-md text-sm font-medium" onclick="showTab('people')">
|
| 62 |
-
People
|
| 63 |
-
</button>
|
| 64 |
-
<button id="tab-tools" class="tab-btn text-indigo-600 bg-indigo-50 px-3 py-1 rounded-md text-sm font-medium" onclick="showTab('tools')">
|
| 65 |
-
Tools
|
| 66 |
-
</button>
|
| 67 |
-
</nav>
|
| 68 |
-
</div>
|
| 69 |
-
</header>
|
| 70 |
-
|
| 71 |
-
<main class="max-w-6xl mx-auto px-4 py-8">
|
| 72 |
-
<section id="page-research" class="hidden">
|
| 73 |
-
<h2 class="text-2xl font-semibold text-gray-800 mb-4">Research</h2>
|
| 74 |
-
<p class="text-gray-500 mb-4">We can list publications, datasets, and experiment notes here later.</p>
|
| 75 |
-
<div class="bg-white rounded-xl shadow p-6 text-gray-400 text-sm">(placeholder) Add your papers, abstracts, or GitHub repos here.</div>
|
| 76 |
-
</section>
|
| 77 |
-
|
| 78 |
-
<section id="page-people" class="hidden">
|
| 79 |
-
<h2 class="text-2xl font-semibold text-gray-800 mb-4">People</h2>
|
| 80 |
-
<p class="text-gray-500 mb-4">We can add your name, collaborators, and links to profiles here.</p>
|
| 81 |
-
<div class="grid gap-4 md:grid-cols-3">
|
| 82 |
-
<div class="bg-white rounded-xl shadow p-5">
|
| 83 |
-
<h3 class="font-semibold text-gray-700">You</h3>
|
| 84 |
-
<p class="text-gray-400 text-sm">Project owner</p>
|
| 85 |
-
</div>
|
| 86 |
-
<div class="bg-white rounded-xl shadow p-5">
|
| 87 |
-
<h3 class="font-semibold text-gray-700">To add</h3>
|
| 88 |
-
<p class="text-gray-400 text-sm">Collaborators / advisors</p>
|
| 89 |
-
</div>
|
| 90 |
-
<div class="bg-white rounded-xl shadow p-5">
|
| 91 |
-
<h3 class="font-semibold text-gray-700">Contact</h3>
|
| 92 |
-
<p class="text-gray-400 text-sm">Add email / GitHub here</p>
|
| 93 |
-
</div>
|
| 94 |
-
</div>
|
| 95 |
-
</section>
|
| 96 |
-
|
| 97 |
-
<section id="page-tools">
|
| 98 |
-
<div class="bg-white shadow-lg rounded-2xl p-8 w-full">
|
| 99 |
-
<h2 class="text-2xl font-bold text-indigo-600 mb-6 flex items-center gap-2"><span>🧰 Tools</span></h2>
|
| 100 |
-
<div class="flex gap-3 mb-6 border-b pb-2">
|
| 101 |
-
<button id="sub-attention" class="subtab-btn text-indigo-600 font-medium border-b-2 border-indigo-600 pb-1" onclick="showSubTool('attention')">🧠 Attention Maps</button>
|
| 102 |
-
<button id="sub-classification" class="subtab-btn text-gray-500 hover:text-indigo-600 pb-1" onclick="showSubTool('classification')">🔍 Run Classification</button>
|
| 103 |
-
</div>
|
| 104 |
-
|
| 105 |
-
<!-- Attention Tool -->
|
| 106 |
-
<div id="tool-attention">
|
| 107 |
-
<div class="flex flex-col items-center gap-4 mb-6 justify-center">
|
| 108 |
-
<input id="file" type="file" accept="image/*"
|
| 109 |
-
class="block w-full md:w-auto text-sm text-gray-600
|
| 110 |
-
file:mr-4 file:py-2 file:px-4
|
| 111 |
-
file:rounded-full file:border-0
|
| 112 |
-
file:text-sm file:font-semibold
|
| 113 |
-
file:bg-indigo-50 file:text-indigo-600
|
| 114 |
-
hover:file:bg-indigo-100"
|
| 115 |
-
onchange="onAttentionImageSelected()" />
|
| 116 |
-
</div>
|
| 117 |
-
|
| 118 |
-
<div id="attention-extra" class="hidden flex flex-col items-center gap-6">
|
| 119 |
-
<button id="runButton" onclick="runActiveTool()" class="px-8 py-3 bg-indigo-600 text-white text-lg font-semibold rounded-full shadow-md hover:bg-indigo-700 transition">
|
| 120 |
-
▶️ Run Attention
|
| 121 |
-
</button>
|
| 122 |
-
<div class="flex flex-col md:flex-row justify-center items-start gap-6">
|
| 123 |
-
<div class="flex flex-col items-center">
|
| 124 |
-
<h4 class="text-gray-600 mb-2 font-medium">Original Image</h4>
|
| 125 |
-
<img id="original" class="rounded-lg shadow-md max-w-xs hidden" />
|
| 126 |
-
</div>
|
| 127 |
-
<div class="flex flex-col items-center">
|
| 128 |
-
<h4 class="text-gray-600 mb-2 font-medium">Mean Attention Map</h4>
|
| 129 |
-
<img id="output" class="rounded-lg shadow-md max-w-xs hidden" />
|
| 130 |
-
</div>
|
| 131 |
-
</div>
|
| 132 |
-
<div id="headsContainer" class="hidden mt-8">
|
| 133 |
-
<h4 class="text-gray-600 mb-3 font-medium text-center">All Attention Heads</h4>
|
| 134 |
-
<div id="headsGrid" class="flex flex-wrap justify-center gap-3"></div>
|
| 135 |
-
</div>
|
| 136 |
-
<p id="status" class="text-center text-gray-500 mt-2 text-sm"></p>
|
| 137 |
-
</div>
|
| 138 |
-
</div>
|
| 139 |
-
|
| 140 |
-
<!-- Classification Tool -->
|
| 141 |
-
<div id="tool-classification" class="hidden">
|
| 142 |
-
<div class="flex flex-col items-center gap-4 mb-6 justify-center">
|
| 143 |
-
|
| 144 |
-
<input id="cls-file" type="file" accept="image/*"
|
| 145 |
-
class="block w-full md:w-auto text-sm text-gray-600
|
| 146 |
-
file:mr-4 file:py-2 file:px-4
|
| 147 |
-
file:rounded-full file:border-0
|
| 148 |
-
file:text-sm file:font-semibold
|
| 149 |
-
file:bg-indigo-50 file:text-indigo-600
|
| 150 |
-
hover:file:bg-indigo-100" />
|
| 151 |
-
<button id="cls-run" onclick="runClassification()" style="display:none;"
|
| 152 |
-
class="px-8 py-3 bg-green-600 text-white text-lg font-semibold rounded-full shadow-md hover:bg-green-700 transition">
|
| 153 |
-
▶️ Run Classification
|
| 154 |
-
</button>
|
| 155 |
-
</div>
|
| 156 |
-
<div id="cls-result" class="text-center text-gray-700 mt-4 text-lg font-medium"></div>
|
| 157 |
-
</div>
|
| 158 |
-
</div>
|
| 159 |
-
</section>
|
| 160 |
-
</main>
|
| 161 |
-
|
| 162 |
-
<script>
|
| 163 |
-
function showTab(name) {
|
| 164 |
-
const tabs = ["research", "people", "tools"];
|
| 165 |
-
tabs.forEach(t => {
|
| 166 |
-
document.getElementById("page-" + t).classList.add("hidden");
|
| 167 |
-
document.getElementById("tab-" + t).classList.remove("bg-indigo-50", "text-indigo-600");
|
| 168 |
-
document.getElementById("tab-" + t).classList.add("text-gray-500");
|
| 169 |
-
});
|
| 170 |
-
document.getElementById("page-" + name).classList.remove("hidden");
|
| 171 |
-
document.getElementById("tab-" + name).classList.add("bg-indigo-50", "text-indigo-600");
|
| 172 |
-
document.getElementById("tab-" + name).classList.remove("text-gray-500");
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
-
let activeTool = "attention";
|
| 176 |
-
const runButton = () => document.getElementById("runButton");
|
| 177 |
-
|
| 178 |
-
function showSubTool(name) {
|
| 179 |
-
const subs = ["attention", "classification"];
|
| 180 |
-
subs.forEach(s => {
|
| 181 |
-
document.getElementById("tool-" + s).classList.add("hidden");
|
| 182 |
-
document.getElementById("sub-" + s).classList.remove("text-indigo-600", "font-medium", "border-b-2", "border-indigo-600");
|
| 183 |
-
document.getElementById("sub-" + s).classList.add("text-gray-500");
|
| 184 |
-
});
|
| 185 |
-
document.getElementById("tool-" + name).classList.remove("hidden");
|
| 186 |
-
document.getElementById("sub-" + name).classList.add("text-indigo-600", "font-medium", "border-b-2", "border-indigo-600");
|
| 187 |
-
document.getElementById("sub-" + name).classList.remove("text-gray-500");
|
| 188 |
-
activeTool = name;
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
async function runActiveTool() {
|
| 192 |
-
const btn = runButton();
|
| 193 |
-
btn.disabled = true;
|
| 194 |
-
btn.textContent = "⌛️ Running...";
|
| 195 |
-
btn.classList.add("opacity-70", "cursor-not-allowed");
|
| 196 |
-
try {
|
| 197 |
-
if (activeTool === "attention") await sendAttention();
|
| 198 |
-
else await runClassification();
|
| 199 |
-
} catch (err) {
|
| 200 |
-
console.error(err);
|
| 201 |
-
alert("❌ Error while running model: " + err.message);
|
| 202 |
-
}
|
| 203 |
-
btn.disabled = false;
|
| 204 |
-
btn.classList.remove("opacity-70", "cursor-not-allowed");
|
| 205 |
-
btn.textContent = activeTool === "attention" ? "▶️ Run Attention" : "▶️ Run Classification";
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
function onAttentionImageSelected() {
|
| 209 |
-
const fileInput = document.getElementById("file");
|
| 210 |
-
const extra = document.getElementById("attention-extra");
|
| 211 |
-
const original = document.getElementById("original");
|
| 212 |
-
if (fileInput.files.length > 0) {
|
| 213 |
-
extra.classList.remove("hidden");
|
| 214 |
-
const reader = new FileReader();
|
| 215 |
-
reader.onload = e => {
|
| 216 |
-
original.src = e.target.result;
|
| 217 |
-
original.classList.remove("hidden");
|
| 218 |
-
};
|
| 219 |
-
reader.readAsDataURL(fileInput.files[0]);
|
| 220 |
-
} else {
|
| 221 |
-
extra.classList.add("hidden");
|
| 222 |
-
original.classList.add("hidden");
|
| 223 |
-
}
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
async function sendAttention() {
|
| 227 |
-
const fileInput = document.getElementById("file");
|
| 228 |
-
const file = fileInput.files[0];
|
| 229 |
-
const output = document.getElementById("output");
|
| 230 |
-
const status = document.getElementById("status");
|
| 231 |
-
const headsContainer = document.getElementById("headsContainer");
|
| 232 |
-
const headsGrid = document.getElementById("headsGrid");
|
| 233 |
-
if (!file) {
|
| 234 |
-
alert("Please choose an image first!");
|
| 235 |
-
return;
|
| 236 |
-
}
|
| 237 |
-
output.classList.add("hidden");
|
| 238 |
-
headsContainer.classList.add("hidden");
|
| 239 |
-
headsGrid.innerHTML = "";
|
| 240 |
-
status.textContent = "⌛️ Model is running...";
|
| 241 |
-
const fd = new FormData();
|
| 242 |
-
fd.append("file", file);
|
| 243 |
-
try {
|
| 244 |
-
const res = await fetch("/attention", { method: "POST", body: fd });
|
| 245 |
-
if (!res.ok) throw new Error(`Server error: ${res.status}`);
|
| 246 |
-
const json = await res.json();
|
| 247 |
-
output.src = "data:image/png;base64," + json.mean_attention_map;
|
| 248 |
-
output.classList.remove("hidden");
|
| 249 |
-
if (json.head_attention_maps && json.head_attention_maps.length > 0) {
|
| 250 |
-
json.head_attention_maps.forEach((headB64, i) => {
|
| 251 |
-
const img = document.createElement("img");
|
| 252 |
-
img.src = "data:image/png;base64," + headB64;
|
| 253 |
-
img.alt = `Head ${i + 1}`;
|
| 254 |
-
img.className = "rounded-md shadow-sm";
|
| 255 |
-
img.style.width = "120px";
|
| 256 |
-
img.style.transition = "transform 0.2s";
|
| 257 |
-
img.onmouseenter = () => (img.style.transform = "scale(1.1)");
|
| 258 |
-
img.onmouseleave = () => (img.style.transform = "scale(1)");
|
| 259 |
-
headsGrid.appendChild(img);
|
| 260 |
-
});
|
| 261 |
-
headsContainer.classList.remove("hidden");
|
| 262 |
-
}
|
| 263 |
-
status.textContent = "✅ Done!";
|
| 264 |
-
} catch (err) {
|
| 265 |
-
console.error(err);
|
| 266 |
-
status.textContent = "❌ Error: " + err.message;
|
| 267 |
-
}
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
async function runClassification() {
|
| 271 |
-
const fileInput = document.getElementById("cls-file");
|
| 272 |
-
const file = fileInput.files[0];
|
| 273 |
-
const result = document.getElementById("cls-result");
|
| 274 |
-
const btn = document.getElementById("cls-run");
|
| 275 |
-
|
| 276 |
-
if (!file) return alert("Please choose an image to classify!");
|
| 277 |
-
|
| 278 |
-
// Disable button + show "Running..."
|
| 279 |
-
btn.disabled = true;
|
| 280 |
-
btn.textContent = "⏳ Running...";
|
| 281 |
-
btn.classList.add("opacity-70", "cursor-not-allowed");
|
| 282 |
-
|
| 283 |
-
result.textContent = "⌛️ Model is running...";
|
| 284 |
-
|
| 285 |
-
const fd = new FormData();
|
| 286 |
-
fd.append("file", file);
|
| 287 |
-
|
| 288 |
-
try {
|
| 289 |
-
const res = await fetch("/classify", { method: "POST", body: fd });
|
| 290 |
-
if (!res.ok) throw new Error(`Server error: ${res.status}`);
|
| 291 |
-
const json = await res.json();
|
| 292 |
-
|
| 293 |
-
if (json.top5) {
|
| 294 |
-
result.innerHTML = `
|
| 295 |
-
<h3 class="font-semibold text-indigo-600 mb-2">Top-5 Predictions</h3>
|
| 296 |
-
${json.top5.map(p => `
|
| 297 |
-
<div class="flex justify-between border-b py-1">
|
| 298 |
-
<span>${p.rank}. ${p.label}</span>
|
| 299 |
-
<span class="text-gray-500">${(p.score * 100).toFixed(2)}%</span>
|
| 300 |
-
</div>
|
| 301 |
-
`).join("")}
|
| 302 |
-
`;
|
| 303 |
-
} else {
|
| 304 |
-
result.textContent = "No predictions returned.";
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
if (json.plot) {
|
| 308 |
-
const plotImg = document.createElement("img");
|
| 309 |
-
plotImg.src = json.plot;
|
| 310 |
-
plotImg.alt = "Top-3 Predicted Species";
|
| 311 |
-
plotImg.style.display = "block";
|
| 312 |
-
plotImg.style.margin = "20px auto";
|
| 313 |
-
plotImg.style.maxWidth = "800px";
|
| 314 |
-
result.appendChild(plotImg);
|
| 315 |
-
}
|
| 316 |
-
} catch (err) {
|
| 317 |
-
console.error(err);
|
| 318 |
-
result.textContent = "❌ Error: " + err.message;
|
| 319 |
-
} finally {
|
| 320 |
-
// Restore button state
|
| 321 |
-
btn.disabled = false;
|
| 322 |
-
btn.classList.remove("opacity-70", "cursor-not-allowed");
|
| 323 |
-
btn.textContent = "▶️ Run Classification";
|
| 324 |
-
}
|
| 325 |
-
}
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
// Show classification button only after image is selected
|
| 329 |
-
document.addEventListener("DOMContentLoaded", () => {
|
| 330 |
-
const fileInput = document.getElementById("cls-file");
|
| 331 |
-
const runBtn = document.getElementById("cls-run");
|
| 332 |
-
fileInput.addEventListener("change", () => {
|
| 333 |
-
if (fileInput.files && fileInput.files.length > 0) {
|
| 334 |
-
runBtn.style.display = "inline-block";
|
| 335 |
-
} else {
|
| 336 |
-
runBtn.style.display = "none";
|
| 337 |
-
}
|
| 338 |
-
});
|
| 339 |
-
});
|
| 340 |
-
|
| 341 |
-
showTab("tools");
|
| 342 |
-
showSubTool("attention");
|
| 343 |
-
</script>
|
| 344 |
-
</body>
|
| 345 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/static/background.jpg
CHANGED
|
|
Git LFS Details
|
app/static/index.html
CHANGED
|
@@ -1,13 +1,26 @@
|
|
| 1 |
<!doctype html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
<meta charset="utf-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
<title>NEMO Tools</title>
|
| 7 |
|
| 8 |
-
<!-- TailwindCSS -->
|
| 9 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 10 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
body {
|
| 12 |
background-image: url('/static/background.jpg');
|
| 13 |
background-size: cover;
|
|
@@ -27,92 +40,490 @@
|
|
| 27 |
</style>
|
| 28 |
</head>
|
| 29 |
|
| 30 |
-
<body class="bg-gray-100 min-h-screen">
|
| 31 |
|
| 32 |
-
<
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
<div class="flex items-center gap-
|
| 36 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
<div>
|
| 38 |
-
<h1 class="text-
|
| 39 |
-
<p class="text-xs text-
|
| 40 |
</div>
|
| 41 |
</div>
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
<button id="tab-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
</nav>
|
|
|
|
| 47 |
</div>
|
| 48 |
</header>
|
| 49 |
|
| 50 |
-
<
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
<section id="page-tools">
|
| 53 |
<div class="bg-white shadow-lg rounded-2xl p-8 w-full">
|
| 54 |
<h2 class="text-2xl font-bold text-indigo-600 mb-6 flex items-center gap-2">🧰 Tools</h2>
|
| 55 |
|
| 56 |
-
<!-- Subtabs -->
|
| 57 |
<div class="flex gap-3 mb-6 border-b pb-2">
|
| 58 |
-
<button id="sub-
|
| 59 |
-
<button id="sub-
|
| 60 |
</div>
|
| 61 |
|
| 62 |
-
<
|
| 63 |
-
|
| 64 |
-
<div class="flex flex-col
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
<p class="text-gray-
|
| 68 |
-
|
| 69 |
-
<
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
</div>
|
| 73 |
|
| 74 |
-
<div id="attention-extra" class="hidden flex flex-col items-center gap-6">
|
| 75 |
-
<button id="runButton" onclick="runActiveTool()" class="px-8 py-3 bg-indigo-600 text-white text-lg font-semibold rounded-full shadow-md hover:bg-indigo-700 transition">▶️ Run Attention</button>
|
| 76 |
|
| 77 |
<div class="flex flex-col md:flex-row justify-center items-start gap-6">
|
| 78 |
<div class="flex flex-col items-center">
|
| 79 |
<h4 class="text-gray-600 mb-2 font-medium">Original Image</h4>
|
| 80 |
-
<img id="original" class="rounded-lg shadow-md max-w-
|
| 81 |
</div>
|
|
|
|
| 82 |
<div class="flex flex-col items-center">
|
| 83 |
-
<h4 class="text-gray-600 mb-2 font-medium">
|
| 84 |
-
<img id="output" class="rounded-lg shadow-md max-w-
|
| 85 |
</div>
|
| 86 |
</div>
|
| 87 |
|
| 88 |
-
<div id="headsContainer" class="hidden mt-8">
|
| 89 |
<h4 class="text-gray-600 mb-3 font-medium text-center">All Attention Heads</h4>
|
| 90 |
<div id="headsGrid" class="flex flex-wrap justify-center gap-3"></div>
|
| 91 |
</div>
|
|
|
|
| 92 |
<p id="status" class="text-center text-gray-500 mt-2 text-sm"></p>
|
| 93 |
</div>
|
|
|
|
| 94 |
</div>
|
| 95 |
|
| 96 |
-
<
|
| 97 |
-
|
| 98 |
-
<div class="
|
| 99 |
-
|
| 100 |
-
<
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
</div>
|
| 105 |
|
| 106 |
-
<
|
| 107 |
|
| 108 |
-
<div id="cls-result" class="text-center text-gray-700 mt-6 text-lg font-medium"></div>
|
| 109 |
</div>
|
|
|
|
| 110 |
</div>
|
| 111 |
</section>
|
| 112 |
</main>
|
| 113 |
|
| 114 |
-
<!-- Scripts -->
|
| 115 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
let activeTool = "attention";
|
| 117 |
|
| 118 |
function showSubTool(name) {
|
|
@@ -128,18 +539,25 @@
|
|
| 128 |
activeTool = name;
|
| 129 |
}
|
| 130 |
|
| 131 |
-
//
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
const extra = document.getElementById("attention-extra");
|
| 135 |
const original = document.getElementById("original");
|
| 136 |
-
const nameEl = document.getElementById("attention-filename");
|
| 137 |
|
|
|
|
|
|
|
|
|
|
| 138 |
if (fileInput.files.length > 0) {
|
| 139 |
-
extra.classList.remove("hidden");
|
| 140 |
const file = fileInput.files[0];
|
| 141 |
-
nameEl.textContent = file.name;
|
|
|
|
| 142 |
|
|
|
|
| 143 |
const reader = new FileReader();
|
| 144 |
reader.onload = e => {
|
| 145 |
original.src = e.target.result;
|
|
@@ -147,29 +565,45 @@
|
|
| 147 |
};
|
| 148 |
reader.readAsDataURL(file);
|
| 149 |
} else {
|
| 150 |
-
extra.classList.add("hidden");
|
| 151 |
-
original.classList.add("hidden");
|
| 152 |
nameEl.textContent = "";
|
|
|
|
| 153 |
}
|
| 154 |
}
|
| 155 |
|
| 156 |
-
async function
|
| 157 |
-
const file = document.getElementById("file").files[0];
|
| 158 |
const output = document.getElementById("output");
|
| 159 |
const status = document.getElementById("status");
|
| 160 |
const headsContainer = document.getElementById("headsContainer");
|
| 161 |
const headsGrid = document.getElementById("headsGrid");
|
| 162 |
-
const btn = document.getElementById("
|
|
|
|
| 163 |
|
| 164 |
if (!file) return alert("Please choose an image first!");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
output.classList.add("hidden");
|
| 166 |
-
headsContainer.classList.add("hidden");
|
| 167 |
headsGrid.innerHTML = "";
|
| 168 |
-
|
| 169 |
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
| 173 |
|
| 174 |
const fd = new FormData();
|
| 175 |
fd.append("file", file);
|
|
@@ -177,32 +611,47 @@
|
|
| 177 |
try {
|
| 178 |
const res = await fetch("/attention", { method: "POST", body: fd });
|
| 179 |
const json = await res.json();
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
if (json.head_attention_maps) {
|
| 183 |
json.head_attention_maps.forEach((b64, i) => {
|
| 184 |
const img = document.createElement("img");
|
| 185 |
img.src = "data:image/png;base64," + b64;
|
| 186 |
-
img.className = "rounded-md shadow-sm w-[120px]";
|
|
|
|
| 187 |
headsGrid.appendChild(img);
|
| 188 |
});
|
| 189 |
headsContainer.classList.remove("hidden");
|
| 190 |
}
|
| 191 |
-
|
|
|
|
|
|
|
| 192 |
} catch (err) {
|
| 193 |
status.textContent = "❌ Error: " + err.message;
|
| 194 |
} finally {
|
|
|
|
| 195 |
btn.disabled = false;
|
| 196 |
-
btn.
|
| 197 |
-
btn.classList.remove("opacity-
|
| 198 |
}
|
| 199 |
}
|
| 200 |
-
|
| 201 |
-
// 🔍
|
|
|
|
| 202 |
function onClsFileSelected() {
|
| 203 |
const fileInput = document.getElementById("cls-file");
|
| 204 |
const fileName = document.getElementById("cls-filename");
|
| 205 |
const runBtn = document.getElementById("cls-run");
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
if (fileInput.files.length > 0) {
|
| 207 |
fileName.textContent = fileInput.files[0].name;
|
| 208 |
runBtn.style.display = "block";
|
|
@@ -219,48 +668,140 @@
|
|
| 219 |
|
| 220 |
if (!file) return alert("Please choose an image to classify!");
|
| 221 |
|
|
|
|
| 222 |
btn.disabled = true;
|
| 223 |
-
btn.
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
const fd = new FormData();
|
| 228 |
fd.append("file", file);
|
|
|
|
| 229 |
|
| 230 |
try {
|
| 231 |
const res = await fetch("/classify", { method: "POST", body: fd });
|
| 232 |
const json = await res.json();
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
<h3 class="font-semibold text-indigo-600 mb-2">Top-5 Predictions</h3>
|
| 236 |
-
${json.top5.map(p => `
|
| 237 |
-
<div class="flex justify-between border-b py-1">
|
| 238 |
-
<span>${p.rank}. ${p.label}</span>
|
| 239 |
-
<span class="text-gray-500">${(p.score * 100).toFixed(2)}%</span>
|
| 240 |
-
</div>`).join("")}`;
|
| 241 |
-
} else result.textContent = "No predictions returned.";
|
| 242 |
|
| 243 |
if (json.plot) {
|
| 244 |
const plotImg = document.createElement("img");
|
| 245 |
plotImg.src = json.plot;
|
| 246 |
-
plotImg.className = "block mx-auto mt-6 max-w-
|
| 247 |
result.appendChild(plotImg);
|
|
|
|
|
|
|
| 248 |
}
|
|
|
|
| 249 |
} catch (err) {
|
| 250 |
result.textContent = "❌ Error: " + err.message;
|
| 251 |
} finally {
|
|
|
|
| 252 |
btn.disabled = false;
|
| 253 |
-
btn.
|
| 254 |
-
btn.classList.remove("opacity-
|
| 255 |
}
|
| 256 |
}
|
| 257 |
|
|
|
|
| 258 |
async function runActiveTool() {
|
| 259 |
-
if (activeTool === "attention") await
|
| 260 |
else await runClassification();
|
| 261 |
}
|
| 262 |
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
</body>
|
| 266 |
-
</html>
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QFG67BD3FB"></script>
|
| 5 |
+
<script>
|
| 6 |
+
window.dataLayer = window.dataLayer || [];
|
| 7 |
+
function gtag(){dataLayer.push(arguments);}
|
| 8 |
+
gtag('js', new Date());
|
| 9 |
+
gtag('config', 'G-QFG67BD3FB');
|
| 10 |
+
</script>
|
| 11 |
+
|
| 12 |
<meta charset="utf-8" />
|
| 13 |
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 14 |
<title>NEMO Tools</title>
|
| 15 |
|
|
|
|
| 16 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 17 |
<style>
|
| 18 |
+
.toggle-wrapper { display:flex; align-items:center; gap:10px; cursor:pointer; }
|
| 19 |
+
.toggle { width:44px; height:24px; background:#d1d5db; border-radius:9999px; position:relative; transition:0.2s; }
|
| 20 |
+
.toggle-circle { width:20px; height:20px; background:white; border-radius:50%; position:absolute; top:2px; left:2px; transition:0.2s; }
|
| 21 |
+
.toggle.active { background:#7c3aed; }
|
| 22 |
+
.toggle.active .toggle-circle { transform:translateX(20px); }
|
| 23 |
+
|
| 24 |
body {
|
| 25 |
background-image: url('/static/background.jpg');
|
| 26 |
background-size: cover;
|
|
|
|
| 40 |
</style>
|
| 41 |
</head>
|
| 42 |
|
| 43 |
+
<body class="bg-gray-100 min-h-screen flex flex-col font-sans">
|
| 44 |
|
| 45 |
+
<header class="sticky top-0 z-50 backdrop-blur-md bg-white/70 border-b border-white/20 shadow-sm transition-all duration-300">
|
| 46 |
+
<div class="max-w-7xl mx-auto px-6 py-4 flex items-center justify-between">
|
| 47 |
+
|
| 48 |
+
<div class="flex items-center gap-4 group cursor-pointer">
|
| 49 |
+
<div class="relative">
|
| 50 |
+
<div class="absolute -inset-1 bg-gradient-to-r from-blue-400 to-indigo-500 rounded-full blur opacity-25 group-hover:opacity-50 transition duration-500"></div>
|
| 51 |
+
<img src="/static/assets/logo.png"
|
| 52 |
+
alt="NEMO logo"
|
| 53 |
+
class="relative h-16 w-16 rounded-full shadow-md border-2 border-white object-cover transform group-hover:scale-105 transition duration-300" />
|
| 54 |
+
</div>
|
| 55 |
<div>
|
| 56 |
+
<h1 class="text-2xl font-extrabold text-indigo-900 tracking-tight leading-none group-hover:text-indigo-700 transition">NEMO tools</h1>
|
| 57 |
+
<p class="text-xs font-semibold text-indigo-500 uppercase tracking-wide mt-1">Mediterranean Fish Spenies Classification Tool</p>
|
| 58 |
</div>
|
| 59 |
</div>
|
| 60 |
+
|
| 61 |
+
<nav class="flex gap-2 md:gap-3 bg-white/50 p-1.5 rounded-full border border-white/40 shadow-inner">
|
| 62 |
+
<button id="tab-research"
|
| 63 |
+
class="tab-btn px-5 py-2 rounded-full text-sm font-semibold text-slate-600 hover:text-indigo-700 hover:bg-white/80 transition-all duration-200 focus:outline-none"
|
| 64 |
+
onclick="showTab('research')">
|
| 65 |
+
Research
|
| 66 |
+
</button>
|
| 67 |
+
<button id="tab-people"
|
| 68 |
+
class="tab-btn px-5 py-2 rounded-full text-sm font-semibold text-slate-600 hover:text-indigo-700 hover:bg-white/80 transition-all duration-200 focus:outline-none"
|
| 69 |
+
onclick="showTab('people')">
|
| 70 |
+
People
|
| 71 |
+
</button>
|
| 72 |
+
<button id="tab-tools"
|
| 73 |
+
class="tab-btn px-6 py-2 rounded-full text-sm font-bold text-white bg-indigo-600 shadow-md hover:bg-indigo-700 hover:shadow-lg transition-all duration-200 transform hover:-translate-y-0.5 focus:outline-none"
|
| 74 |
+
onclick="showTab('tools')">
|
| 75 |
+
Tools
|
| 76 |
+
</button>
|
| 77 |
</nav>
|
| 78 |
+
|
| 79 |
</div>
|
| 80 |
</header>
|
| 81 |
|
| 82 |
+
<main class="max-w-6xl mx-auto px-4 py-8 w-full flex-grow">
|
| 83 |
+
|
| 84 |
+
<section id="page-people" class="hidden max-w-6xl mx-auto mb-12">
|
| 85 |
+
<div class="text-center mb-12">
|
| 86 |
+
<h2 class="text-3xl font-bold text-indigo-900">The Team</h2>
|
| 87 |
+
<p class="text-lg text-gray-800 mt-2">
|
| 88 |
+
Our interdisciplinary team combines expertise in ecology, marine biology, and artificial intelligence.
|
| 89 |
+
</p>
|
| 90 |
+
</div>
|
| 91 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
|
| 92 |
+
<div class="bg-white rounded-2xl shadow-lg p-6 flex flex-col items-center text-center hover:shadow-xl transition">
|
| 93 |
+
<img src="/static/team/kofidis.jpg" alt="Andreas Kofidis" class="w-24 h-24 rounded-full mb-4 object-cover border-4 border-indigo-50 shadow-sm">
|
| 94 |
+
<h3 class="text-lg font-bold text-gray-800">Andreas Kofidis</h3>
|
| 95 |
+
<span class="text-indigo-600 font-medium text-sm mb-3">Data Scientist, IACM-FORTH</span>
|
| 96 |
+
<p class="text-gray-600 text-sm leading-relaxed">
|
| 97 |
+
His research focuses on deep learning and computer vision, specifically in the development of robust algorithms for object detection and classification in challenging environments.
|
| 98 |
+
</p>
|
| 99 |
+
</div>
|
| 100 |
+
<div class="bg-white rounded-2xl shadow-lg p-6 flex flex-col items-center text-center hover:shadow-xl transition">
|
| 101 |
+
<img src="/static/team/dretaki.jpg" alt="Eleni Dretaki" class="w-24 h-24 rounded-full mb-4 object-cover border-4 border-indigo-50 shadow-sm">
|
| 102 |
+
<h3 class="text-lg font-bold text-gray-800">Eleni Dretaki</h3>
|
| 103 |
+
<span class="text-indigo-600 font-medium text-sm mb-3">Data Scientist, IACM-FORTH</span>
|
| 104 |
+
<p class="text-gray-600 text-sm leading-relaxed">
|
| 105 |
+
A data scientist specializing in applied mathematics and statistical analysis. Her work involves processing complex datasets and developing computational methodologies for scientific applications.
|
| 106 |
+
</p>
|
| 107 |
+
</div>
|
| 108 |
+
<div class="bg-white rounded-2xl shadow-lg p-6 flex flex-col items-center text-center hover:shadow-xl transition">
|
| 109 |
+
<img src="/static/team/zotou.jpg" alt="Maria Zotou" class="w-24 h-24 rounded-full mb-4 object-cover border-4 border-indigo-50 shadow-sm">
|
| 110 |
+
<h3 class="text-lg font-bold text-gray-800">Maria Zotou</h3>
|
| 111 |
+
<span class="text-indigo-600 font-medium text-sm mb-3">PhD candidate, UAegean</span>
|
| 112 |
+
<p class="text-gray-600 text-sm leading-relaxed">
|
| 113 |
+
Her research interests lie in marine biodiversity assessment and ecosystem monitoring. She specializes in the taxonomy of Mediterranean marine fauna and field survey methodologies.
|
| 114 |
+
</p>
|
| 115 |
+
</div>
|
| 116 |
+
<div class="bg-white rounded-2xl shadow-lg p-6 flex flex-col items-center text-center hover:shadow-xl transition">
|
| 117 |
+
<img src="/static/team/poursanidis.jpg" alt="Dimitris Poursanidis" class="w-24 h-24 rounded-full mb-4 object-cover border-4 border-indigo-50 shadow-sm">
|
| 118 |
+
<h3 class="text-lg font-bold text-gray-800">Dr. Dimitris Poursanidis</h3>
|
| 119 |
+
<span class="text-indigo-600 font-medium text-sm mb-3">Technical Researcher, IACM-FORTH</span>
|
| 120 |
+
<p class="text-gray-600 text-sm leading-relaxed">
|
| 121 |
+
An expert in remote sensing and coastal habitat mapping. His work utilizes satellite and drone imagery to study spatial patterns in marine environments and support conservation planning.
|
| 122 |
+
</p>
|
| 123 |
+
</div>
|
| 124 |
+
<div class="bg-white rounded-2xl shadow-lg p-6 flex flex-col items-center text-center hover:shadow-xl transition">
|
| 125 |
+
<img src="/static/team/doxa.jpg" alt="Aggeliki Doxa" class="w-24 h-24 rounded-full mb-4 object-cover border-4 border-indigo-50 shadow-sm">
|
| 126 |
+
<h3 class="text-lg font-bold text-gray-800">Dr. Aggeliki Doxa</h3>
|
| 127 |
+
<span class="text-indigo-600 font-medium text-sm mb-3">Associate Prof. of Biology, IACM-FORTH & UoC</span>
|
| 128 |
+
<p class="text-gray-600 text-sm leading-relaxed">
|
| 129 |
+
Her research focuses on ecological modeling, biodiversity dynamics, and the impact of environmental changes on species distributions and ecosystem services.
|
| 130 |
+
</p>
|
| 131 |
+
</div>
|
| 132 |
+
<div class="bg-white rounded-2xl shadow-lg p-6 flex flex-col items-center text-center hover:shadow-xl transition">
|
| 133 |
+
<img src="/static/team/mazaris.jpg" alt="Antonios Mazaris" class="w-24 h-24 rounded-full mb-4 object-cover border-4 border-indigo-50 shadow-sm">
|
| 134 |
+
<h3 class="text-lg font-bold text-gray-800">Prof. Antonios D. Mazaris</h3>
|
| 135 |
+
<span class="text-indigo-600 font-medium text-sm mb-3">Professor of Ecology, AUTH</span>
|
| 136 |
+
<p class="text-gray-600 text-sm leading-relaxed">
|
| 137 |
+
His work addresses large-scale conservation challenges, focusing on global biodiversity patterns, extinction risk assessments, and the effectiveness of protected area networks.
|
| 138 |
+
</p>
|
| 139 |
+
</div>
|
| 140 |
+
<div class="bg-white rounded-2xl shadow-lg p-6 flex flex-col items-center text-center hover:shadow-xl transition">
|
| 141 |
+
<img src="/static/team/katsanevakis.jpg" alt="Stelios Katsanevakis" class="w-24 h-24 rounded-full mb-4 object-cover border-4 border-indigo-50 shadow-sm">
|
| 142 |
+
<h3 class="text-lg font-bold text-gray-800">Prof. Stelios Katsanevakis</h3>
|
| 143 |
+
<span class="text-indigo-600 font-medium text-sm mb-3">Marine Ecologist, UAegean</span>
|
| 144 |
+
<p class="text-gray-600 text-sm leading-relaxed">
|
| 145 |
+
His research investigates marine ecosystem dynamics, biological invasions, and marine conservation planning, aiming to support ecosystem-based management strategies.
|
| 146 |
+
</p>
|
| 147 |
+
</div>
|
| 148 |
+
<div class="bg-white rounded-2xl shadow-lg p-6 flex flex-col items-center text-center hover:shadow-xl transition">
|
| 149 |
+
<img src="/static/team/kamarianakis.jpg" alt="Yiannis Kamarianakis" class="w-24 h-24 rounded-full mb-4 object-cover border-4 border-indigo-50 shadow-sm">
|
| 150 |
+
<h3 class="text-lg font-bold text-gray-800">Dr. Yiannis Kamarianakis</h3>
|
| 151 |
+
<span class="text-indigo-600 font-medium text-sm mb-3">Research Director, IACM-FORTH</span>
|
| 152 |
+
<p class="text-gray-600 text-sm leading-relaxed">
|
| 153 |
+
An expert in applied mathematics and statistics. He specializes in time-series analysis, spatial statistics, and the development of predictive models for complex systems.
|
| 154 |
+
</p>
|
| 155 |
+
</div>
|
| 156 |
+
<div class="bg-white rounded-2xl shadow-lg p-6 flex flex-col items-center text-center hover:shadow-xl transition">
|
| 157 |
+
<img src="/static/team/pantazis.jpg" alt="Yannis Pantazis" class="w-24 h-24 rounded-full mb-4 object-cover border-4 border-indigo-50 shadow-sm">
|
| 158 |
+
<h3 class="text-lg font-bold text-gray-800">Dr. Yannis Pantazis</h3>
|
| 159 |
+
<span class="text-indigo-600 font-medium text-sm mb-3">Principal Researcher, IACM-FORTH</span>
|
| 160 |
+
<p class="text-gray-600 text-sm leading-relaxed">
|
| 161 |
+
His research spans machine learning, signal processing, and data-driven discovery, focusing on developing novel AI architectures and mathematical frameworks for scientific applications.
|
| 162 |
+
</p>
|
| 163 |
+
</div>
|
| 164 |
+
</div>
|
| 165 |
+
</section>
|
| 166 |
+
|
| 167 |
+
<section id="page-research" class="hidden max-w-5xl mx-auto mb-12">
|
| 168 |
+
<div class="bg-white shadow-lg rounded-2xl p-8">
|
| 169 |
+
|
| 170 |
+
<div class="border-b pb-6 mb-6">
|
| 171 |
+
<h2 class="text-3xl font-bold text-indigo-900">NEMO-Tools Project</h2>
|
| 172 |
+
<p class="text-lg text-indigo-600 font-medium mt-2">
|
| 173 |
+
<span class="text-indigo-900 font-bold">NE</span>xt-generation
|
| 174 |
+
<span class="text-indigo-900 font-bold">MO</span>nitoring and mapping
|
| 175 |
+
<span class="text-indigo-900 font-bold">Tools</span> to assess marine ecosystems and biodiversity
|
| 176 |
+
</p>
|
| 177 |
+
</div>
|
| 178 |
+
|
| 179 |
+
<div class="prose max-w-none text-gray-700 leading-relaxed space-y-4">
|
| 180 |
+
<p>
|
| 181 |
+
<strong>NEMO-Tools</strong> is an ambitious research initiative designed to develop affordable, user-friendly, and smart tools for marine biodiversity monitoring. Its primary goal is to support the <strong>EU Biodiversity Strategy for 2030</strong> by providing high-precision data to measure ecosystem health and recovery.
|
| 182 |
+
</p>
|
| 183 |
+
|
| 184 |
+
<p>
|
| 185 |
+
While this web interface focuses on <strong>Artificial Intelligence (AI)</strong> for species identification, the full NEMO-Tools project integrates a hierarchical approach combining multiple cutting-edge technologies:
|
| 186 |
+
</p>
|
| 187 |
+
|
| 188 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 my-8">
|
| 189 |
+
<div class="bg-indigo-50 p-5 rounded-xl border border-indigo-100">
|
| 190 |
+
<h3 class="font-bold text-indigo-800 mb-2 flex items-center gap-2">🤖 Artificial Intelligence</h3>
|
| 191 |
+
<p class="text-sm">
|
| 192 |
+
Utilizing Deep Learning (DINOv2, YOLOv11) to classify species from underwater imagery. This tool specifically utilizes the <strong>MEDFISH101</strong> dataset to identify 101 Mediterranean fish species.
|
| 193 |
+
</p>
|
| 194 |
+
</div>
|
| 195 |
+
|
| 196 |
+
<div class="bg-indigo-50 p-5 rounded-xl border border-indigo-100">
|
| 197 |
+
<h3 class="font-bold text-indigo-800 mb-2 flex items-center gap-2">🛰️ Remote Sensing</h3>
|
| 198 |
+
<p class="text-sm">
|
| 199 |
+
Employing satellite (Planet SuperDove) and drone (UAV) imagery to map macroalgae forests and detect marine megafauna in shallow coastal waters.
|
| 200 |
+
</p>
|
| 201 |
+
</div>
|
| 202 |
+
|
| 203 |
+
<div class="bg-indigo-50 p-5 rounded-xl border border-indigo-100">
|
| 204 |
+
<h3 class="font-bold text-indigo-800 mb-2 flex items-center gap-2">🧬 Environmental DNA (eDNA)</h3>
|
| 205 |
+
<p class="text-sm">
|
| 206 |
+
Developing cost-effective sampling protocols and low-cost 3D-printed probes to detect rare or elusive species through genetic material released in the water.
|
| 207 |
+
</p>
|
| 208 |
+
</div>
|
| 209 |
+
|
| 210 |
+
<div class="bg-indigo-50 p-5 rounded-xl border border-indigo-100">
|
| 211 |
+
<h3 class="font-bold text-indigo-800 mb-2 flex items-center gap-2">⚓ Robotics & Acoustics</h3>
|
| 212 |
+
<p class="text-sm">
|
| 213 |
+
Deploying upgraded ROVs for quantitative benthic assessments and Ground Unmanned Vehicles (GUVs) for sandy shore monitoring. Includes low-cost hydrophones for citizen-science acoustic monitoring.
|
| 214 |
+
</p>
|
| 215 |
+
</div>
|
| 216 |
+
</div>
|
| 217 |
+
|
| 218 |
+
<p>
|
| 219 |
+
The identification tool provided here addresses the challenge of monitoring visually similar species.
|
| 220 |
+
It leverages the <strong>MEDFISH101</strong> dataset, a rigorously curated collection of approximately
|
| 221 |
+
<strong>70,000 expert-validated images</strong>. This dataset represents 101 fish species
|
| 222 |
+
inhabiting the Hellenic and Mediterranean seas, spanning major families such as <em>Sparidae</em>,
|
| 223 |
+
<em>Serranidae</em>, and <em>Labridae</em>.
|
| 224 |
+
</p>
|
| 225 |
+
<p>
|
| 226 |
+
By encompassing commercial, protected, and invasive species—including the Indo-Pacific Lionfish (<em>Pterois miles</em>)—the tool facilitates near real-time ecological monitoring and early detection
|
| 227 |
+
of biological threats. Powered by state-of-the-art Vision Foundation Models achieving up to
|
| 228 |
+
<strong>94,12% accuracy</strong> using DINOv2-Giant, it empowers citizen scientists to contribute reliable data for
|
| 229 |
+
evidence-based marine management.
|
| 230 |
+
</p>
|
| 231 |
+
</div>
|
| 232 |
+
|
| 233 |
+
<div class="mt-10">
|
| 234 |
+
<h3 class="text-xl font-bold text-indigo-700 mb-4 flex items-center gap-2">
|
| 235 |
+
🐟 MEDFISH101 Species List
|
| 236 |
+
</h3>
|
| 237 |
+
<p class="text-sm text-gray-500 mb-4">
|
| 238 |
+
The following 101 species are currently supported by the model classification engine:
|
| 239 |
+
</p>
|
| 240 |
+
|
| 241 |
+
<div class="bg-gray-50 rounded-xl p-6 border border-gray-200 h-[500px] overflow-y-auto">
|
| 242 |
+
<ul class="grid grid-cols-1 md:grid-cols-3 gap-y-2 gap-x-4 text-sm text-gray-700 font-medium">
|
| 243 |
+
<li><i>Aidablennius sphynx</i></li>
|
| 244 |
+
<li><i>Apogon imberbis</i></li>
|
| 245 |
+
<li><i>Arnoglossus laterna</i></li>
|
| 246 |
+
<li><i>Atherina boyeri</i></li>
|
| 247 |
+
<li><i>Atherina hepsetus</i></li>
|
| 248 |
+
<li><i>Boops boops</i></li>
|
| 249 |
+
<li><i>Bothus podas</i></li>
|
| 250 |
+
<li><i>Callionymus pusillus</i></li>
|
| 251 |
+
<li><i>Callionymus risso</i></li>
|
| 252 |
+
<li><i>Caranx crysos</i></li>
|
| 253 |
+
<li><i>Chelidonichthys lucerna</i></li>
|
| 254 |
+
<li><i>Chromis chromis</i></li>
|
| 255 |
+
<li><i>Coris julis</i></li>
|
| 256 |
+
<li><i>Dactylopterus volitans</i></li>
|
| 257 |
+
<li><i>Dasyatis pastinaca</i></li>
|
| 258 |
+
<li><i>Diplodus annularis</i></li>
|
| 259 |
+
<li><i>Diplodus puntazzo</i></li>
|
| 260 |
+
<li><i>Diplodus sargus</i></li>
|
| 261 |
+
<li><i>Diplodus vulgaris</i></li>
|
| 262 |
+
<li><i>Echiichthys vipera</i></li>
|
| 263 |
+
<li><i>Epinephelus costae</i></li>
|
| 264 |
+
<li><i>Epinephelus marginatus</i></li>
|
| 265 |
+
<li><i>Fistularia commersonii</i></li>
|
| 266 |
+
<li><i>Gobius auratus</i></li>
|
| 267 |
+
<li><i>Gobius bucchichi</i></li>
|
| 268 |
+
<li><i>Gobius cobitis</i></li>
|
| 269 |
+
<li><i>Gobius cruentatus</i></li>
|
| 270 |
+
<li><i>Gobius geniporus</i></li>
|
| 271 |
+
<li><i>Gobius incognitus</i></li>
|
| 272 |
+
<li><i>Gobius niger</i></li>
|
| 273 |
+
<li><i>Gobius paganellus</i></li>
|
| 274 |
+
<li><i>Gobius vittatus</i></li>
|
| 275 |
+
<li><i>Hippocampus guttulatus</i></li>
|
| 276 |
+
<li><i>Hippocampus hippocampus</i></li>
|
| 277 |
+
<li><i>Labrus bergylta</i></li>
|
| 278 |
+
<li><i>Labrus merula</i></li>
|
| 279 |
+
<li><i>Labrus mixtus</i></li>
|
| 280 |
+
<li><i>Labrus viridis</i></li>
|
| 281 |
+
<li><i>Lagocephalus sceleratus</i></li>
|
| 282 |
+
<li><i>Lithognathus mormyrus</i></li>
|
| 283 |
+
<li><i>Microlipophrys nigriceps</i></li>
|
| 284 |
+
<li><i>Mugil auratus</i></li>
|
| 285 |
+
<li><i>Mugil cephalus</i></li>
|
| 286 |
+
<li><i>Mullus barbatus</i></li>
|
| 287 |
+
<li><i>Mullus surmuletus</i></li>
|
| 288 |
+
<li><i>Muraena helena</i></li>
|
| 289 |
+
<li><i>Oblada melanura</i></li>
|
| 290 |
+
<li><i>Pagrus pagrus</i></li>
|
| 291 |
+
<li><i>Parablennius gattorugine</i></li>
|
| 292 |
+
<li><i>Parablennius incognitus</i></li>
|
| 293 |
+
<li><i>Parablennius pilicornis</i></li>
|
| 294 |
+
<li><i>Parablennius rouxi</i></li>
|
| 295 |
+
<li><i>Parablennius sanguinolentus</i></li>
|
| 296 |
+
<li><i>Parablennius tentacularis</i></li>
|
| 297 |
+
<li><i>Parablennius zvonimiri</i></li>
|
| 298 |
+
<li><i>Parupeneus forsskali</i></li>
|
| 299 |
+
<li><i>Phycis phycis</i></li>
|
| 300 |
+
<li><i>Plotosus lineatus</i></li>
|
| 301 |
+
<li><i>Pomatoschistus marmoratus</i></li>
|
| 302 |
+
<li><i>Pterois miles</i></li>
|
| 303 |
+
<li><i>Salaria pavo</i></li>
|
| 304 |
+
<li><i>Sargocentron rubrum</i></li>
|
| 305 |
+
<li><i>Sarpa salpa</i></li>
|
| 306 |
+
<li><i>Sciaena umbra</i></li>
|
| 307 |
+
<li><i>Scorpaena maderensis</i></li>
|
| 308 |
+
<li><i>Scorpaena notata</i></li>
|
| 309 |
+
<li><i>Scorpaena scrofa</i></li>
|
| 310 |
+
<li><i>Serranus cabrilla</i></li>
|
| 311 |
+
<li><i>Serranus hepatus</i></li>
|
| 312 |
+
<li><i>Serranus scriba</i></li>
|
| 313 |
+
<li><i>Siganus luridus</i></li>
|
| 314 |
+
<li><i>Siganus rivulatus</i></li>
|
| 315 |
+
<li><i>Solea solea</i></li>
|
| 316 |
+
<li><i>Sparisoma cretense</i></li>
|
| 317 |
+
<li><i>Sparus aurata</i></li>
|
| 318 |
+
<li><i>Spicara maena</i></li>
|
| 319 |
+
<li><i>Spicara smaris</i></li>
|
| 320 |
+
<li><i>Spondyliosoma cantharus</i></li>
|
| 321 |
+
<li><i>Stephanolepis diaspros</i></li>
|
| 322 |
+
<li><i>Symphodus cinereus</i></li>
|
| 323 |
+
<li><i>Symphodus mediterraneus</i></li>
|
| 324 |
+
<li><i>Symphodus melanocercus</i></li>
|
| 325 |
+
<li><i>Symphodus ocellatus</i></li>
|
| 326 |
+
<li><i>Symphodus roissali</i></li>
|
| 327 |
+
<li><i>Symphodus rostratus</i></li>
|
| 328 |
+
<li><i>Symphodus tinca</i></li>
|
| 329 |
+
<li><i>Syngnathus abaster</i></li>
|
| 330 |
+
<li><i>Syngnathus tenuirostris</i></li>
|
| 331 |
+
<li><i>Syngnathus typhle</i></li>
|
| 332 |
+
<li><i>Thalassoma pavo</i></li>
|
| 333 |
+
<li><i>Thorogobius ephippiatus</i></li>
|
| 334 |
+
<li><i>Torpedo marmorata</i></li>
|
| 335 |
+
<li><i>Torquigener flavimaculosus</i></li>
|
| 336 |
+
<li><i>Trachinus araneus</i></li>
|
| 337 |
+
<li><i>Trachinus draco</i></li>
|
| 338 |
+
<li><i>Trachinus radiatus</i></li>
|
| 339 |
+
<li><i>Tripterygion delaisi</i></li>
|
| 340 |
+
<li><i>Tripterygion melanurus</i></li>
|
| 341 |
+
<li><i>Tripterygion tripteronotus</i></li>
|
| 342 |
+
<li><i>Uranoscopus scaber</i></li>
|
| 343 |
+
<li><i>Xyrichtys novacula</i></li>
|
| 344 |
+
</ul>
|
| 345 |
+
</div>
|
| 346 |
+
</div>
|
| 347 |
+
</div>
|
| 348 |
+
</section>
|
| 349 |
+
|
| 350 |
<section id="page-tools">
|
| 351 |
<div class="bg-white shadow-lg rounded-2xl p-8 w-full">
|
| 352 |
<h2 class="text-2xl font-bold text-indigo-600 mb-6 flex items-center gap-2">🧰 Tools</h2>
|
| 353 |
|
|
|
|
| 354 |
<div class="flex gap-3 mb-6 border-b pb-2">
|
| 355 |
+
<button id="sub-classification" class="subtab-btn text-indigo-600 font-medium border-b-2 border-indigo-600 pb-1" onclick="showSubTool('classification')">🔍 Classification</button>
|
| 356 |
+
<button id="sub-attention" class="subtab-btn text-gray-500 hover:text-indigo-600 pb-1" onclick="showSubTool('attention')">🧠 Visualization</button>
|
| 357 |
</div>
|
| 358 |
|
| 359 |
+
<div id="tool-attention" class="flex flex-col items-center w-full mt-6">
|
| 360 |
+
|
| 361 |
+
<div class="flex flex-col md:flex-row w-full items-stretch justify-center gap-8 px-4">
|
| 362 |
+
|
| 363 |
+
<div class="flex-1 flex flex-col justify-center items-start gap-4 min-w-[250px]">
|
| 364 |
+
<p class="text-gray-600 font-semibold mb-1 text-sm">Choose your model:</p>
|
| 365 |
+
|
| 366 |
+
<div class="toggle-wrapper group" onclick="setModel('dino')">
|
| 367 |
+
<div id="toggle-dino-vis" class="toggle active group-hover:ring-2 group-hover:ring-green-300">
|
| 368 |
+
<div class="toggle-circle shadow-sm"></div>
|
| 369 |
+
</div>
|
| 370 |
+
<div class="flex flex-col">
|
| 371 |
+
<span class="text-gray-800 font-bold text-sm">DINOv2-Giant</span>
|
| 372 |
+
<span class="text-gray-400 text-xs">High accuracy, slower</span>
|
| 373 |
+
</div>
|
| 374 |
+
</div>
|
| 375 |
+
|
| 376 |
+
<div class="toggle-wrapper group" onclick="setModel('yolo')">
|
| 377 |
+
<div id="toggle-yolo-vis" class="toggle group-hover:ring-2 group-hover:ring-green-300">
|
| 378 |
+
<div class="toggle-circle shadow-sm"></div>
|
| 379 |
+
</div>
|
| 380 |
+
<div class="flex flex-col">
|
| 381 |
+
<span class="text-gray-800 font-bold text-sm">YOLOv11-X</span>
|
| 382 |
+
<span class="text-gray-400 text-xs">Lower accuracy, faster</span>
|
| 383 |
+
</div>
|
| 384 |
+
</div>
|
| 385 |
+
</div>
|
| 386 |
+
|
| 387 |
+
<div class="flex-1 flex flex-col justify-center items-center text-center border-2 border-dashed border-gray-300 rounded-xl p-6 bg-gray-50 hover:bg-gray-100 transition min-w-[300px]">
|
| 388 |
+
<p class="text-gray-700 font-bold mb-2">Upload Image</p>
|
| 389 |
+
<p class="text-gray-400 text-xs mb-5">Supported: JPG, PNG</p>
|
| 390 |
+
|
| 391 |
+
<label for="vis-file"
|
| 392 |
+
class="inline-flex items-center justify-center gap-2 px-8 py-3 bg-green-600 hover:bg-green-700 text-white font-bold rounded-full cursor-pointer shadow-md transition-all transform hover:scale-105">
|
| 393 |
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-5 h-5">
|
| 394 |
+
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5" />
|
| 395 |
+
</svg>
|
| 396 |
+
Choose File
|
| 397 |
+
</label>
|
| 398 |
+
|
| 399 |
+
<input id="vis-file" type="file" accept="image/*" class="hidden" onchange="onVisFileSelected()" />
|
| 400 |
+
<p id="vis-filename" class="text-gray-500 mt-3 text-xs italic font-medium"></p>
|
| 401 |
</div>
|
| 402 |
+
|
| 403 |
+
<div class="flex-1 min-w-[250px] hidden md:block"></div>
|
| 404 |
+
|
| 405 |
+
</div>
|
| 406 |
+
|
| 407 |
+
<div class="w-full flex justify-center mt-6">
|
| 408 |
+
<button id="vis-run" onclick="runVisualization()"
|
| 409 |
+
style="display:none;"
|
| 410 |
+
class="px-8 py-3 bg-indigo-600 text-white text-lg font-semibold rounded-full shadow-md hover:bg-indigo-700 transition transform hover:scale-105">
|
| 411 |
+
▶️ Run Visualization
|
| 412 |
+
</button>
|
| 413 |
</div>
|
| 414 |
|
| 415 |
+
<div id="attention-extra" class="hidden flex flex-col items-center gap-6 w-full mt-8">
|
|
|
|
| 416 |
|
| 417 |
<div class="flex flex-col md:flex-row justify-center items-start gap-6">
|
| 418 |
<div class="flex flex-col items-center">
|
| 419 |
<h4 class="text-gray-600 mb-2 font-medium">Original Image</h4>
|
| 420 |
+
<img id="original" class="rounded-lg shadow-md max-w-[200px] hidden" />
|
| 421 |
</div>
|
| 422 |
+
|
| 423 |
<div class="flex flex-col items-center">
|
| 424 |
+
<h4 class="text-gray-600 mb-2 font-medium">PCA Attention</h4>
|
| 425 |
+
<img id="output" class="rounded-lg shadow-md max-w-[200px] hidden" />
|
| 426 |
</div>
|
| 427 |
</div>
|
| 428 |
|
| 429 |
+
<div id="headsContainer" class="hidden mt-8 w-full">
|
| 430 |
<h4 class="text-gray-600 mb-3 font-medium text-center">All Attention Heads</h4>
|
| 431 |
<div id="headsGrid" class="flex flex-wrap justify-center gap-3"></div>
|
| 432 |
</div>
|
| 433 |
+
|
| 434 |
<p id="status" class="text-center text-gray-500 mt-2 text-sm"></p>
|
| 435 |
</div>
|
| 436 |
+
|
| 437 |
</div>
|
| 438 |
|
| 439 |
+
<div id="tool-classification" class="hidden flex flex-col items-start mt-6 w-full">
|
| 440 |
+
|
| 441 |
+
<div class="flex flex-col md:flex-row w-full items-stretch justify-center gap-8 px-4">
|
| 442 |
+
|
| 443 |
+
<div class="flex-1 flex flex-col justify-center items-start gap-4 min-w-[250px]">
|
| 444 |
+
<p class="text-gray-600 font-semibold mb-1 text-sm">Choose your model:</p>
|
| 445 |
+
|
| 446 |
+
<div class="toggle-wrapper group" onclick="setModel('dino')">
|
| 447 |
+
<div id="toggle-dino-cls" class="toggle active group-hover:ring-2 group-hover:ring-green-300">
|
| 448 |
+
<div class="toggle-circle shadow-sm"></div>
|
| 449 |
+
</div>
|
| 450 |
+
<div class="flex flex-col">
|
| 451 |
+
<span class="text-gray-800 font-bold text-sm">DINOv2-Giant</span>
|
| 452 |
+
<span class="text-gray-400 text-xs">High accuracy, slower</span>
|
| 453 |
+
</div>
|
| 454 |
+
</div>
|
| 455 |
+
|
| 456 |
+
<div class="toggle-wrapper group" onclick="setModel('yolo')">
|
| 457 |
+
<div id="toggle-yolo-cls" class="toggle group-hover:ring-2 group-hover:ring-green-300">
|
| 458 |
+
<div class="toggle-circle shadow-sm"></div>
|
| 459 |
+
</div>
|
| 460 |
+
<div class="flex flex-col">
|
| 461 |
+
<span class="text-gray-800 font-bold text-sm">YOLOv11-X</span>
|
| 462 |
+
<span class="text-gray-400 text-xs">Lower accuracy, faster</span>
|
| 463 |
+
</div>
|
| 464 |
+
</div>
|
| 465 |
+
</div>
|
| 466 |
+
|
| 467 |
+
<div class="flex-1 flex flex-col justify-center items-center text-center border-2 border-dashed border-gray-300 rounded-xl p-6 bg-gray-50 hover:bg-gray-100 transition min-w-[300px]">
|
| 468 |
+
<p class="text-gray-700 font-bold mb-2">Upload Image</p>
|
| 469 |
+
<p class="text-gray-400 text-xs mb-5">Supported: JPG, PNG</p>
|
| 470 |
+
|
| 471 |
+
<label for="cls-file"
|
| 472 |
+
class="inline-flex items-center justify-center gap-2 px-8 py-3 bg-green-600 hover:bg-green-700 text-white font-bold rounded-full cursor-pointer shadow-md transition-all transform hover:scale-105">
|
| 473 |
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-5 h-5">
|
| 474 |
+
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5" />
|
| 475 |
+
</svg>
|
| 476 |
+
Choose File
|
| 477 |
+
</label>
|
| 478 |
+
|
| 479 |
+
<input id="cls-file" type="file" accept="image/*" class="hidden" onchange="onClsFileSelected()" />
|
| 480 |
+
<p id="cls-filename" class="text-gray-500 mt-3 text-xs italic"></p>
|
| 481 |
+
</div>
|
| 482 |
+
|
| 483 |
+
<div class="flex-1 flex flex-col justify-center gap-4 min-w-[250px]">
|
| 484 |
+
<div>
|
| 485 |
+
<label class="block text-gray-700 font-bold mb-1 text-sm">Location of observation:</label>
|
| 486 |
+
<input id="obs-location" type="text" class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm text-gray-900 focus:ring-2 focus:ring-green-500 focus:border-green-500 transition-all focus:outline-none shadow-sm" placeholder="e.g. Aegean Sea" />
|
| 487 |
+
</div>
|
| 488 |
+
<div>
|
| 489 |
+
<label class="block text-gray-700 font-bold mb-1 text-sm">Potential species name:</label>
|
| 490 |
+
<input id="obs-species" type="text" class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm text-gray-900 focus:ring-2 focus:ring-green-500 focus:border-green-500 transition-all focus:outline-none shadow-sm" placeholder="e.g. Sparus aurata" />
|
| 491 |
+
</div>
|
| 492 |
+
</div>
|
| 493 |
+
|
| 494 |
+
</div>
|
| 495 |
+
|
| 496 |
+
<div class="w-full flex justify-center mt-6">
|
| 497 |
+
<button id="cls-run" onclick="runClassification()" style="display:none;" class="px-8 py-3 bg-green-600 text-white text-lg font-semibold rounded-full shadow-md hover:bg-green-700 transition">
|
| 498 |
+
▶️ Run Classification
|
| 499 |
+
</button>
|
| 500 |
</div>
|
| 501 |
|
| 502 |
+
<div id="cls-result" class="text-center text-gray-700 mt-6 text-lg font-medium w-full"></div>
|
| 503 |
|
|
|
|
| 504 |
</div>
|
| 505 |
+
|
| 506 |
</div>
|
| 507 |
</section>
|
| 508 |
</main>
|
| 509 |
|
|
|
|
| 510 |
<script>
|
| 511 |
+
let selectedModel = "dino"; // default model
|
| 512 |
+
|
| 513 |
+
function setModel(name) {
|
| 514 |
+
selectedModel = name;
|
| 515 |
+
|
| 516 |
+
// Update Visualization Toggles
|
| 517 |
+
document.getElementById("toggle-dino-vis")?.classList.toggle("active", name === "dino");
|
| 518 |
+
document.getElementById("toggle-yolo-vis")?.classList.toggle("active", name === "yolo");
|
| 519 |
+
|
| 520 |
+
// Update Classification Toggles
|
| 521 |
+
document.getElementById("toggle-dino-cls")?.classList.toggle("active", name === "dino");
|
| 522 |
+
document.getElementById("toggle-yolo-cls")?.classList.toggle("active", name === "yolo");
|
| 523 |
+
|
| 524 |
+
console.log("MODEL SELECTED:", selectedModel);
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
let activeTool = "attention";
|
| 528 |
|
| 529 |
function showSubTool(name) {
|
|
|
|
| 539 |
activeTool = name;
|
| 540 |
}
|
| 541 |
|
| 542 |
+
// ──────────────────────────────────────────────
|
| 543 |
+
// 🧠 VISUALIZATION LOGIC
|
| 544 |
+
// ──────────────────────────────────────────────
|
| 545 |
+
function onVisFileSelected() {
|
| 546 |
+
const fileInput = document.getElementById("vis-file");
|
| 547 |
+
const nameEl = document.getElementById("vis-filename");
|
| 548 |
+
const runBtn = document.getElementById("vis-run");
|
| 549 |
const extra = document.getElementById("attention-extra");
|
| 550 |
const original = document.getElementById("original");
|
|
|
|
| 551 |
|
| 552 |
+
// Reset previous results
|
| 553 |
+
extra.classList.add("hidden");
|
| 554 |
+
|
| 555 |
if (fileInput.files.length > 0) {
|
|
|
|
| 556 |
const file = fileInput.files[0];
|
| 557 |
+
nameEl.textContent = file.name; // Show filename
|
| 558 |
+
runBtn.style.display = "block"; // Show Run button
|
| 559 |
|
| 560 |
+
// Pre-load original image for display later
|
| 561 |
const reader = new FileReader();
|
| 562 |
reader.onload = e => {
|
| 563 |
original.src = e.target.result;
|
|
|
|
| 565 |
};
|
| 566 |
reader.readAsDataURL(file);
|
| 567 |
} else {
|
|
|
|
|
|
|
| 568 |
nameEl.textContent = "";
|
| 569 |
+
runBtn.style.display = "none";
|
| 570 |
}
|
| 571 |
}
|
| 572 |
|
| 573 |
+
async function runVisualization() {
|
| 574 |
+
const file = document.getElementById("vis-file").files[0];
|
| 575 |
const output = document.getElementById("output");
|
| 576 |
const status = document.getElementById("status");
|
| 577 |
const headsContainer = document.getElementById("headsContainer");
|
| 578 |
const headsGrid = document.getElementById("headsGrid");
|
| 579 |
+
const btn = document.getElementById("vis-run");
|
| 580 |
+
const extra = document.getElementById("attention-extra");
|
| 581 |
|
| 582 |
if (!file) return alert("Please choose an image first!");
|
| 583 |
+
|
| 584 |
+
// 1. Change Button State to Loading
|
| 585 |
+
btn.disabled = true;
|
| 586 |
+
btn.classList.add("opacity-80", "cursor-not-allowed");
|
| 587 |
+
// Replace text with spinner
|
| 588 |
+
btn.innerHTML = `
|
| 589 |
+
<svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-white inline-block" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
| 590 |
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
| 591 |
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
| 592 |
+
</svg>
|
| 593 |
+
Processing...
|
| 594 |
+
`;
|
| 595 |
+
|
| 596 |
+
// Setup UI for results
|
| 597 |
+
extra.classList.remove("hidden");
|
| 598 |
output.classList.add("hidden");
|
| 599 |
+
headsContainer.classList.add("hidden");
|
| 600 |
headsGrid.innerHTML = "";
|
| 601 |
+
status.textContent = "Running model inference...";
|
| 602 |
|
| 603 |
+
// Google Analytics
|
| 604 |
+
if (typeof gtag === 'function') {
|
| 605 |
+
gtag('event', 'run_visualization', { 'event_category': 'Model', 'event_label': 'DINOv2_Hybrid' });
|
| 606 |
+
}
|
| 607 |
|
| 608 |
const fd = new FormData();
|
| 609 |
fd.append("file", file);
|
|
|
|
| 611 |
try {
|
| 612 |
const res = await fetch("/attention", { method: "POST", body: fd });
|
| 613 |
const json = await res.json();
|
| 614 |
+
|
| 615 |
+
// 1. Show PCA Image
|
| 616 |
+
if (json.pca_image) {
|
| 617 |
+
output.src = "data:image/png;base64," + json.pca_image;
|
| 618 |
+
output.classList.remove("hidden");
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
// 2. Show 16 Attention Heads
|
| 622 |
if (json.head_attention_maps) {
|
| 623 |
json.head_attention_maps.forEach((b64, i) => {
|
| 624 |
const img = document.createElement("img");
|
| 625 |
img.src = "data:image/png;base64," + b64;
|
| 626 |
+
img.className = "rounded-md shadow-sm w-[120px] transition hover:scale-110";
|
| 627 |
+
img.title = `Head ${i+1}`;
|
| 628 |
headsGrid.appendChild(img);
|
| 629 |
});
|
| 630 |
headsContainer.classList.remove("hidden");
|
| 631 |
}
|
| 632 |
+
|
| 633 |
+
status.textContent = "✅ Visualization Complete!";
|
| 634 |
+
|
| 635 |
} catch (err) {
|
| 636 |
status.textContent = "❌ Error: " + err.message;
|
| 637 |
} finally {
|
| 638 |
+
// 2. Reset Button State
|
| 639 |
btn.disabled = false;
|
| 640 |
+
btn.innerHTML = "▶️ Run Visualization";
|
| 641 |
+
btn.classList.remove("opacity-80", "cursor-not-allowed");
|
| 642 |
}
|
| 643 |
}
|
| 644 |
+
// ──────────────────────────────────────────────
|
| 645 |
+
// 🔍 CLASSIFICATION LOGIC
|
| 646 |
+
// ──────────────────────────────────────────────
|
| 647 |
function onClsFileSelected() {
|
| 648 |
const fileInput = document.getElementById("cls-file");
|
| 649 |
const fileName = document.getElementById("cls-filename");
|
| 650 |
const runBtn = document.getElementById("cls-run");
|
| 651 |
+
|
| 652 |
+
// Clear previous results
|
| 653 |
+
document.getElementById("cls-result").innerHTML = "";
|
| 654 |
+
|
| 655 |
if (fileInput.files.length > 0) {
|
| 656 |
fileName.textContent = fileInput.files[0].name;
|
| 657 |
runBtn.style.display = "block";
|
|
|
|
| 668 |
|
| 669 |
if (!file) return alert("Please choose an image to classify!");
|
| 670 |
|
| 671 |
+
// 1. Change Button State to Loading
|
| 672 |
btn.disabled = true;
|
| 673 |
+
btn.classList.add("opacity-80", "cursor-not-allowed");
|
| 674 |
+
// Replace text with spinner
|
| 675 |
+
btn.innerHTML = `
|
| 676 |
+
<svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-white inline-block" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
| 677 |
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
| 678 |
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
| 679 |
+
</svg>
|
| 680 |
+
Processing...
|
| 681 |
+
`;
|
| 682 |
+
|
| 683 |
+
// Analytics
|
| 684 |
+
if (typeof gtag === 'function') {
|
| 685 |
+
gtag('event', 'run_classification', { 'event_category': 'Model', 'event_label': selectedModel });
|
| 686 |
+
}
|
| 687 |
|
| 688 |
const fd = new FormData();
|
| 689 |
fd.append("file", file);
|
| 690 |
+
fd.append("model", selectedModel);
|
| 691 |
|
| 692 |
try {
|
| 693 |
const res = await fetch("/classify", { method: "POST", body: fd });
|
| 694 |
const json = await res.json();
|
| 695 |
+
|
| 696 |
+
if (json.top5) result.innerHTML = ""; // Clear previous results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 697 |
|
| 698 |
if (json.plot) {
|
| 699 |
const plotImg = document.createElement("img");
|
| 700 |
plotImg.src = json.plot;
|
| 701 |
+
plotImg.className = "block mx-auto mt-6 max-w-4xl rounded-lg shadow-md";
|
| 702 |
result.appendChild(plotImg);
|
| 703 |
+
} else {
|
| 704 |
+
result.textContent = "No predictions returned.";
|
| 705 |
}
|
| 706 |
+
|
| 707 |
} catch (err) {
|
| 708 |
result.textContent = "❌ Error: " + err.message;
|
| 709 |
} finally {
|
| 710 |
+
// 2. Reset Button State
|
| 711 |
btn.disabled = false;
|
| 712 |
+
btn.innerHTML = "▶️ Run Classification";
|
| 713 |
+
btn.classList.remove("opacity-80", "cursor-not-allowed");
|
| 714 |
}
|
| 715 |
}
|
| 716 |
|
| 717 |
+
// Helper for "Run Active Tool" if needed
|
| 718 |
async function runActiveTool() {
|
| 719 |
+
if (activeTool === "attention") await runVisualization();
|
| 720 |
else await runClassification();
|
| 721 |
}
|
| 722 |
|
| 723 |
+
// TAB SWITCHING LOGIC
|
| 724 |
+
// TAB SWITCHING LOGIC (Fixed)
|
| 725 |
+
function showTab(tabName) {
|
| 726 |
+
// 1. Hide all pages
|
| 727 |
+
['tools', 'research', 'people'].forEach(page => {
|
| 728 |
+
const el = document.getElementById('page-' + page);
|
| 729 |
+
if(el) el.classList.add('hidden');
|
| 730 |
+
});
|
| 731 |
+
|
| 732 |
+
// 2. Show selected page
|
| 733 |
+
const selected = document.getElementById('page-' + tabName);
|
| 734 |
+
if(selected) selected.classList.remove('hidden');
|
| 735 |
+
|
| 736 |
+
// 3. Reset All Buttons to "Inactive" State
|
| 737 |
+
const allButtons = document.querySelectorAll('.tab-btn');
|
| 738 |
+
allButtons.forEach(btn => {
|
| 739 |
+
// Remove the "Active" styles (Purple/Indigo background & White text)
|
| 740 |
+
btn.classList.remove('bg-indigo-600', 'text-white', 'shadow-md');
|
| 741 |
+
|
| 742 |
+
// Add the "Inactive" styles (Transparent background & Gray text)
|
| 743 |
+
btn.classList.add('text-slate-600', 'hover:bg-white/80', 'hover:text-indigo-700');
|
| 744 |
+
});
|
| 745 |
+
|
| 746 |
+
// 4. Set Active Button Style
|
| 747 |
+
const activeBtn = document.getElementById('tab-' + tabName);
|
| 748 |
+
if(activeBtn) {
|
| 749 |
+
// Remove "Inactive" styles
|
| 750 |
+
activeBtn.classList.remove('text-slate-600', 'hover:bg-white/80', 'hover:text-indigo-700');
|
| 751 |
+
|
| 752 |
+
// Add "Active" styles (Purple/Indigo background & White text)
|
| 753 |
+
activeBtn.classList.add('bg-indigo-600', 'text-white', 'shadow-md');
|
| 754 |
+
}
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
// Initialize
|
| 758 |
+
showSubTool("classification");
|
| 759 |
</script>
|
| 760 |
+
|
| 761 |
+
<footer class="bg-slate-900 border-t border-slate-800 mt-20 pb-12 text-white">
|
| 762 |
+
<div class="max-w-7xl mx-auto px-6 pt-16">
|
| 763 |
+
|
| 764 |
+
<div class="text-center mb-10">
|
| 765 |
+
<h3 class="text-sm font-bold tracking-[0.2em] text-slate-400 uppercase">
|
| 766 |
+
Supported By
|
| 767 |
+
</h3>
|
| 768 |
+
<div class="w-16 h-1 bg-indigo-500 mx-auto mt-4 rounded-full shadow-lg shadow-indigo-500/50"></div>
|
| 769 |
+
</div>
|
| 770 |
+
|
| 771 |
+
<div class="bg-white rounded-3xl p-10 shadow-2xl mx-auto max-w-6xl">
|
| 772 |
+
<div class="flex flex-wrap justify-center items-center gap-x-16 gap-y-12">
|
| 773 |
+
|
| 774 |
+
<a href="https://www.iacm.forth.gr/" target="_blank" rel="noopener noreferrer">
|
| 775 |
+
<img src="/static/logos/forth.png" alt="IACM-FORTH" class="h-24 md:h-32 w-auto object-contain transition-transform duration-300 hover:scale-110 cursor-pointer">
|
| 776 |
+
</a>
|
| 777 |
+
|
| 778 |
+
<a href="https://www.aegean.gr/" target="_blank" rel="noopener noreferrer">
|
| 779 |
+
<img src="/static/logos/aegean.png" alt="University of the Aegean" class="h-24 md:h-32 w-auto object-contain transition-transform duration-300 hover:scale-110 cursor-pointer">
|
| 780 |
+
</a>
|
| 781 |
+
|
| 782 |
+
<a href="https://www.elidek.gr/en/homepage/" target="_blank" rel="noopener noreferrer">
|
| 783 |
+
<img src="/static/logos/hfri.png" alt="HFRI" class="h-24 md:h-32 w-auto object-contain transition-transform duration-300 hover:scale-110 cursor-pointer">
|
| 784 |
+
</a>
|
| 785 |
+
|
| 786 |
+
<a href="https://www.uoc.gr/en/home/" target="_blank" rel="noopener noreferrer">
|
| 787 |
+
<img src="/static/logos/uoc.png" alt="University of Crete" class="h-24 md:h-32 w-auto object-contain transition-transform duration-300 hover:scale-110 cursor-pointer">
|
| 788 |
+
</a>
|
| 789 |
+
|
| 790 |
+
<a href="https://www.auth.gr/en/" target="_blank" rel="noopener noreferrer">
|
| 791 |
+
<img src="/static/logos/auth.png" alt="Aristotle University of Thessaloniki" class="h-12 md:h-14 w-auto object-contain transition-transform duration-300 hover:scale-110 cursor-pointer">
|
| 792 |
+
</a>
|
| 793 |
+
|
| 794 |
+
</div>
|
| 795 |
+
</div>
|
| 796 |
+
|
| 797 |
+
<div class="mt-16 text-center border-t border-slate-800 pt-8">
|
| 798 |
+
<p class="text-slate-500 text-sm">
|
| 799 |
+
© 2025 NEMO-Tools. Mediterranean Fish Species Classification. All rights reserved.
|
| 800 |
+
</p>
|
| 801 |
+
</div>
|
| 802 |
+
|
| 803 |
+
</div>
|
| 804 |
+
</footer>
|
| 805 |
+
|
| 806 |
</body>
|
| 807 |
+
</html>
|
app/static/logos/aegean.png
ADDED
|
Git LFS Details
|
app/static/logos/auth.png
ADDED
|
Git LFS Details
|
app/static/logos/forth.png
ADDED
|
Git LFS Details
|
app/static/logos/hfri.png
ADDED
|
Git LFS Details
|
app/static/logos/uoc.png
ADDED
|
Git LFS Details
|
app/static/team/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
app/static/team/doxa.jpg
ADDED
|
Git LFS Details
|
app/static/team/dretaki.jpg
ADDED
|
Git LFS Details
|
app/static/team/kamarianakis.jpg
ADDED
|
Git LFS Details
|
app/static/team/katsanevakis.jpg
ADDED
|
Git LFS Details
|
app/static/team/kofidis.jpg
ADDED
|
Git LFS Details
|
app/static/team/mazaris.jpg
ADDED
|
Git LFS Details
|
app/static/team/pantazis.jpg
ADDED
|
Git LFS Details
|
app/static/team/poursanidis.jpg
ADDED
|
Git LFS Details
|
app/static/team/zotou.jpg
ADDED
|
Git LFS Details
|
requirements.txt
CHANGED
|
@@ -16,3 +16,6 @@ huggingface-hub
|
|
| 16 |
peft
|
| 17 |
|
| 18 |
python-multipart
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
peft
|
| 17 |
|
| 18 |
python-multipart
|
| 19 |
+
ultralytics
|
| 20 |
+
opencv-python-headless
|
| 21 |
+
pyyaml
|