Update src/omniglue/dino_extract.py
Browse files
src/omniglue/dino_extract.py
CHANGED
|
@@ -28,6 +28,7 @@ class DINOExtract:
|
|
| 28 |
def __init__(self, cpt_path: str, feature_layer: int = 1):
|
| 29 |
self.feature_layer = feature_layer
|
| 30 |
self.model = dino.vit_base()
|
|
|
|
| 31 |
state_dict_raw = torch.load(cpt_path, map_location='cpu')
|
| 32 |
|
| 33 |
# state_dict = {}
|
|
@@ -35,7 +36,7 @@ class DINOExtract:
|
|
| 35 |
# state_dict[k.replace('blocks', 'blocks.0')] = v
|
| 36 |
|
| 37 |
self.model.load_state_dict(state_dict_raw)
|
| 38 |
-
self.model.eval()
|
| 39 |
|
| 40 |
self.image_size_max = 630
|
| 41 |
|
|
@@ -98,6 +99,7 @@ class DINOExtract:
|
|
| 98 |
image_processed = image / 255.0
|
| 99 |
image_processed = (image_processed - mean) / std
|
| 100 |
image_processed = torch.from_numpy(image_processed).permute(2, 0, 1)
|
|
|
|
| 101 |
return image_processed
|
| 102 |
|
| 103 |
def extract_feature(self, image):
|
|
|
|
| 28 |
def __init__(self, cpt_path: str, feature_layer: int = 1):
|
| 29 |
self.feature_layer = feature_layer
|
| 30 |
self.model = dino.vit_base()
|
| 31 |
+
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 32 |
state_dict_raw = torch.load(cpt_path, map_location='cpu')
|
| 33 |
|
| 34 |
# state_dict = {}
|
|
|
|
| 36 |
# state_dict[k.replace('blocks', 'blocks.0')] = v
|
| 37 |
|
| 38 |
self.model.load_state_dict(state_dict_raw)
|
| 39 |
+
self.model.eval().to(self.device)
|
| 40 |
|
| 41 |
self.image_size_max = 630
|
| 42 |
|
|
|
|
| 99 |
image_processed = image / 255.0
|
| 100 |
image_processed = (image_processed - mean) / std
|
| 101 |
image_processed = torch.from_numpy(image_processed).permute(2, 0, 1)
|
| 102 |
+
image_processed = image_processed.to(self.device)
|
| 103 |
return image_processed
|
| 104 |
|
| 105 |
def extract_feature(self, image):
|