Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,9 @@ from transformers import Dinov2Config, Dinov2Model, Dinov2ForImageClassification
|
|
| 5 |
import torch.nn as nn
|
| 6 |
import os
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
def create_head(num_features , number_classes ,dropout_prob=0.5 ,activation_func =nn.ReLU):
|
| 10 |
features_lst = [num_features , num_features//2 , num_features//4]
|
| 11 |
layers = []
|
|
@@ -16,6 +18,7 @@ def create_head(num_features , number_classes ,dropout_prob=0.5 ,activation_func
|
|
| 16 |
if dropout_prob !=0 : layers.append(nn.Dropout(dropout_prob))
|
| 17 |
layers.append(nn.Linear(features_lst[-1] , number_classes))
|
| 18 |
return nn.Sequential(*layers)
|
|
|
|
| 19 |
|
| 20 |
class NewheadDinov2ForImageClassification(Dinov2ForImageClassification):
|
| 21 |
def __init__(self, config: Dinov2Config) -> None:
|
|
@@ -28,7 +31,6 @@ class NewheadDinov2ForImageClassification(Dinov2ForImageClassification):
|
|
| 28 |
self.classifier = create_head(config.hidden_size * 2, config.num_labels)
|
| 29 |
|
| 30 |
# IMPORT CLASSIFICATION MODEL
|
| 31 |
-
checkpoint_name = "lombardata/dino-base-2023_11_27-with_custom_head"
|
| 32 |
# import labels
|
| 33 |
classes_names = ["Acropore_branched", "Acropore_digitised", "Acropore_tabular", "Algae_assembly",
|
| 34 |
"Algae_limestone", "Algae_sodding", "Dead_coral", "Fish", "Human_object",
|
|
|
|
| 5 |
import torch.nn as nn
|
| 6 |
import os
|
| 7 |
|
| 8 |
+
model_name = "dinov2-large-2024_01_24-with_data_aug_batch-size32_epochs93_freeze"
|
| 9 |
+
|
| 10 |
+
# CREATE CUSTOM MODEL
|
| 11 |
def create_head(num_features , number_classes ,dropout_prob=0.5 ,activation_func =nn.ReLU):
|
| 12 |
features_lst = [num_features , num_features//2 , num_features//4]
|
| 13 |
layers = []
|
|
|
|
| 18 |
if dropout_prob !=0 : layers.append(nn.Dropout(dropout_prob))
|
| 19 |
layers.append(nn.Linear(features_lst[-1] , number_classes))
|
| 20 |
return nn.Sequential(*layers)
|
| 21 |
+
from transformers import Dinov2Config, Dinov2Model
|
| 22 |
|
| 23 |
class NewheadDinov2ForImageClassification(Dinov2ForImageClassification):
|
| 24 |
def __init__(self, config: Dinov2Config) -> None:
|
|
|
|
| 31 |
self.classifier = create_head(config.hidden_size * 2, config.num_labels)
|
| 32 |
|
| 33 |
# IMPORT CLASSIFICATION MODEL
|
|
|
|
| 34 |
# import labels
|
| 35 |
classes_names = ["Acropore_branched", "Acropore_digitised", "Acropore_tabular", "Algae_assembly",
|
| 36 |
"Algae_limestone", "Algae_sodding", "Dead_coral", "Fish", "Human_object",
|