test dinov2
Browse files- .gitattributes +1 -0
- _test_preprocessed.csv +3 -0
- script.py +25 -24
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip 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
|
|
|
|
33 |
*.zip 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 |
+
*.csv filter=lfs diff=lfs merge=lfs -text
|
_test_preprocessed.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8615ab5f08f97624cfc5d3200a0a573dac6e99958196ff297000ce8c6b572fcf
|
3 |
+
size 12274373
|
script.py
CHANGED
@@ -23,15 +23,15 @@ class PytorchWorker:
|
|
23 |
self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
24 |
print(f"Using devide: {self.device}")
|
25 |
|
26 |
-
model = timm.create_model(model_name, num_classes=
|
27 |
-
weights = torch.load(model_path, map_location=self.device)
|
28 |
-
model.load_state_dict({w.replace("model.", ""): v for w, v in weights.items()})
|
29 |
|
30 |
return model.to(self.device).eval()
|
31 |
|
32 |
self.model = _load_model(model_name, model_path)
|
33 |
|
34 |
-
self.transforms = T.Compose([T.Resize((
|
35 |
T.ToTensor(),
|
36 |
T.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])])
|
37 |
|
@@ -43,9 +43,9 @@ class PytorchWorker:
|
|
43 |
:return: A list with logits and confidences.
|
44 |
"""
|
45 |
|
46 |
-
|
47 |
|
48 |
-
return
|
49 |
|
50 |
|
51 |
def make_submission(test_metadata, model_path, model_name, output_csv_path="./submission.csv", images_root_path="/tmp/data/private_testset"):
|
@@ -77,33 +77,34 @@ def make_submission(test_metadata, model_path, model_name, output_csv_path="./su
|
|
77 |
if __name__ == "__main__":
|
78 |
|
79 |
MODEL_PATH = "metaformer-s-224.pth"
|
80 |
-
MODEL_NAME = "
|
81 |
|
82 |
# Real submission
|
83 |
-
import zipfile
|
84 |
|
85 |
-
with zipfile.ZipFile("/tmp/data/private_testset.zip", 'r') as zip_ref:
|
86 |
-
|
87 |
-
|
88 |
-
metadata_file_path = "./FungiCLEF2024_TestMetadata.csv"
|
89 |
-
test_metadata = pd.read_csv(metadata_file_path)
|
90 |
-
|
91 |
-
make_submission(
|
92 |
-
test_metadata=test_metadata,
|
93 |
-
model_path=MODEL_PATH,
|
94 |
-
model_name=MODEL_NAME
|
95 |
-
)
|
96 |
-
|
97 |
-
# Test submission
|
98 |
-
# metadata_file_path = "../trial_test.csv"
|
99 |
|
|
|
100 |
# test_metadata = pd.read_csv(metadata_file_path)
|
101 |
|
102 |
# make_submission(
|
103 |
# test_metadata=test_metadata,
|
104 |
# model_path=MODEL_PATH,
|
105 |
-
# model_name=MODEL_NAME
|
106 |
-
# images_root_path="../data/DF"
|
107 |
# )
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
|
|
23 |
self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
24 |
print(f"Using devide: {self.device}")
|
25 |
|
26 |
+
model = timm.create_model(model_name, num_classes=0, pretrained=False)
|
27 |
+
# weights = torch.load(model_path, map_location=self.device)
|
28 |
+
# model.load_state_dict({w.replace("model.", ""): v for w, v in weights.items()})
|
29 |
|
30 |
return model.to(self.device).eval()
|
31 |
|
32 |
self.model = _load_model(model_name, model_path)
|
33 |
|
34 |
+
self.transforms = T.Compose([T.Resize((518, 518)),
|
35 |
T.ToTensor(),
|
36 |
T.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])])
|
37 |
|
|
|
43 |
:return: A list with logits and confidences.
|
44 |
"""
|
45 |
|
46 |
+
self.model(self.transforms(image).unsqueeze(0).to(self.device))
|
47 |
|
48 |
+
return [-1]
|
49 |
|
50 |
|
51 |
def make_submission(test_metadata, model_path, model_name, output_csv_path="./submission.csv", images_root_path="/tmp/data/private_testset"):
|
|
|
77 |
if __name__ == "__main__":
|
78 |
|
79 |
MODEL_PATH = "metaformer-s-224.pth"
|
80 |
+
MODEL_NAME = "timm/vit_base_patch14_reg4_dinov2.lvd142m"
|
81 |
|
82 |
# Real submission
|
83 |
+
# import zipfile
|
84 |
|
85 |
+
# with zipfile.ZipFile("/tmp/data/private_testset.zip", 'r') as zip_ref:
|
86 |
+
# zip_ref.extractall("/tmp/data")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
+
# metadata_file_path = "./test_preprocessed.csv"
|
89 |
# test_metadata = pd.read_csv(metadata_file_path)
|
90 |
|
91 |
# make_submission(
|
92 |
# test_metadata=test_metadata,
|
93 |
# model_path=MODEL_PATH,
|
94 |
+
# model_name=MODEL_NAME
|
|
|
95 |
# )
|
96 |
|
97 |
+
# Test submission
|
98 |
+
|
99 |
+
metadata_file_path = "../trial_submission.csv"
|
100 |
+
|
101 |
+
test_metadata = pd.read_csv(metadata_file_path)
|
102 |
+
|
103 |
+
make_submission(
|
104 |
+
test_metadata=test_metadata,
|
105 |
+
model_path=MODEL_PATH,
|
106 |
+
model_name=MODEL_NAME,
|
107 |
+
images_root_path="../data/DF_FULL"
|
108 |
+
)
|
109 |
+
|
110 |
|