Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,11 @@ import torch.nn as nn
|
|
6 |
import os
|
7 |
from huggingface_hub import hf_hub_download
|
8 |
|
|
|
9 |
model_name = "dinov2-large-2024_01_24-with_data_aug_batch-size32_epochs93_freeze"
|
10 |
checkpoint_name = "lombardata/" + model_name
|
11 |
|
12 |
-
#
|
13 |
def create_head(num_features , number_classes ,dropout_prob=0.5 ,activation_func =nn.ReLU):
|
14 |
features_lst = [num_features , num_features//2 , num_features//4]
|
15 |
layers = []
|
@@ -35,7 +36,12 @@ class NewheadDinov2ForImageClassification(Dinov2ForImageClassification):
|
|
35 |
model = NewheadDinov2ForImageClassification.from_pretrained(checkpoint_name)
|
36 |
|
37 |
# IMPORT MODEL CONFIG PARAMETERS
|
38 |
-
hf_hub_download(repo_id=checkpoint_name, filename="config.json")
|
|
|
|
|
|
|
|
|
|
|
39 |
id2label = config["id2label"]
|
40 |
label2id = config["label2id"]
|
41 |
image_size = config["image_size"]
|
|
|
6 |
import os
|
7 |
from huggingface_hub import hf_hub_download
|
8 |
|
9 |
+
# DEFINE MODEL NAME
|
10 |
model_name = "dinov2-large-2024_01_24-with_data_aug_batch-size32_epochs93_freeze"
|
11 |
checkpoint_name = "lombardata/" + model_name
|
12 |
|
13 |
+
# IMPORT CLASSIFICATION MODEL
|
14 |
def create_head(num_features , number_classes ,dropout_prob=0.5 ,activation_func =nn.ReLU):
|
15 |
features_lst = [num_features , num_features//2 , num_features//4]
|
16 |
layers = []
|
|
|
36 |
model = NewheadDinov2ForImageClassification.from_pretrained(checkpoint_name)
|
37 |
|
38 |
# IMPORT MODEL CONFIG PARAMETERS
|
39 |
+
config_path = hf_hub_download(repo_id=checkpoint_name, filename="config.json")
|
40 |
+
# Opening JSON file
|
41 |
+
config_file = open(config_path)
|
42 |
+
# returns JSON object as
|
43 |
+
config = json.load(config_file)
|
44 |
+
# import parameters
|
45 |
id2label = config["id2label"]
|
46 |
label2id = config["label2id"]
|
47 |
image_size = config["image_size"]
|