test
Browse files
app.py
CHANGED
@@ -89,30 +89,30 @@ model_option = gr.Radio(options, value="dino16",
|
|
89 |
|
90 |
@spaces.GPU
|
91 |
def upsample_features(image, model_option):
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
|
117 |
|
118 |
demo = gr.Interface(fn=upsample_features,
|
|
|
89 |
|
90 |
@spaces.GPU
|
91 |
def upsample_features(image, model_option):
|
92 |
+
with torch.no_grad():
|
93 |
+
subprocess.check_call(
|
94 |
+
["pip", "install", "git+https://github.com/mhamilton723/FeatUp"])
|
95 |
+
|
96 |
+
from featup.util import norm, unnorm
|
97 |
+
models = {o: torch.hub.load("mhamilton723/FeatUp", o) for o in options}
|
98 |
+
|
99 |
+
# Image preprocessing
|
100 |
+
input_size = 224
|
101 |
+
transform = T.Compose([
|
102 |
+
T.Resize(input_size),
|
103 |
+
T.CenterCrop((input_size, input_size)),
|
104 |
+
T.ToTensor(),
|
105 |
+
norm
|
106 |
+
])
|
107 |
+
image_tensor = transform(image).unsqueeze(0).cuda()
|
108 |
+
|
109 |
+
# Load the selected model
|
110 |
+
upsampler = models[model_option].cuda()
|
111 |
+
hr_feats = upsampler(image_tensor)
|
112 |
+
lr_feats = upsampler.model(image_tensor)
|
113 |
+
upsampler.cpu()
|
114 |
+
|
115 |
+
return plot_feats(unnorm(image_tensor)[0], lr_feats[0], hr_feats[0])
|
116 |
|
117 |
|
118 |
demo = gr.Interface(fn=upsample_features,
|