test
Browse files
app.py
CHANGED
@@ -12,6 +12,28 @@ import csv
|
|
12 |
import spaces
|
13 |
# from triton.fb import build_paths
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def plot_feats(image, lr, hr):
|
17 |
from featup.util import pca, remove_axes
|
@@ -89,46 +111,8 @@ model_option = gr.Radio(options, value="dino16",
|
|
89 |
label='Choose a backbone to upsample')
|
90 |
|
91 |
|
92 |
-
def find_cuda_home():
|
93 |
-
try:
|
94 |
-
# Define the search string and the directory
|
95 |
-
search_string = "CUDA"
|
96 |
-
search_directory = "/usr"
|
97 |
-
|
98 |
-
# Use subprocess to run the grep command
|
99 |
-
command = ['grep', '-r', search_string, search_directory]
|
100 |
-
output = subprocess.check_output(command).decode()
|
101 |
-
|
102 |
-
print(output)
|
103 |
-
for line in output.split('\n'):
|
104 |
-
if 'Cuda compilation tools' in line:
|
105 |
-
version = line.split()[-1]
|
106 |
-
return f"/usr/local/cuda-{version.split('.')[0]}.{version.split('.')[1]}"
|
107 |
-
except Exception as e:
|
108 |
-
print(f"Error finding CUDA_HOME: {e}")
|
109 |
-
return None
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
print(torch.cuda.is_available())
|
114 |
-
from torch.utils.cpp_extension import _find_cuda_home
|
115 |
-
cuda_home = _find_cuda_home()
|
116 |
-
if cuda_home is None:
|
117 |
-
raise EnvironmentError("CUDA_HOME could not be found.")
|
118 |
-
|
119 |
-
|
120 |
@spaces.GPU
|
121 |
def upsample_features(image, model_option):
|
122 |
-
|
123 |
-
os.environ["CUDA_HOME"] = cuda_home
|
124 |
-
print(os.environ["CUDA_HOME"])
|
125 |
-
os.environ['PATH'] = '/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
|
126 |
-
os.environ['LD_LIBRARY_PATH'] = '/usr/local/nvidia/lib:/usr/local/nvidia/lib64'
|
127 |
-
|
128 |
-
# Install the required package from GitHub
|
129 |
-
subprocess.check_call(
|
130 |
-
["pip", "install", "git+https://github.com/mhamilton723/FeatUp"])
|
131 |
-
|
132 |
from featup.util import norm, unnorm
|
133 |
models = {o: torch.hub.load("mhamilton723/FeatUp", o) for o in options}
|
134 |
|
|
|
12 |
import spaces
|
13 |
# from triton.fb import build_paths
|
14 |
|
15 |
+
from torch.utils.cpp_extension import load
|
16 |
+
|
17 |
+
# Compile and load the CUDA extension
|
18 |
+
adaptive_conv_cuda_impl = load(
|
19 |
+
name='adaptive_conv_cuda_impl',
|
20 |
+
sources=[
|
21 |
+
'featup/adaptive_conv_cuda/adaptive_conv_cuda.cpp',
|
22 |
+
'featup/adaptive_conv_cuda/adaptive_conv_kernel.cu'
|
23 |
+
],
|
24 |
+
extra_cflags=['-O3'],
|
25 |
+
extra_cuda_cflags=['-O3']
|
26 |
+
)
|
27 |
+
|
28 |
+
# Compile and load the C++ extension
|
29 |
+
adaptive_conv_cpp_impl = load(
|
30 |
+
name='adaptive_conv_cpp_impl',
|
31 |
+
sources=['featup/adaptive_conv_cuda/adaptive_conv.cpp'],
|
32 |
+
extra_cflags=['-O3']
|
33 |
+
)
|
34 |
+
|
35 |
+
print(adaptive_conv_cuda_impl, adaptive_conv_cpp_impl)
|
36 |
+
|
37 |
|
38 |
def plot_feats(image, lr, hr):
|
39 |
from featup.util import pca, remove_axes
|
|
|
111 |
label='Choose a backbone to upsample')
|
112 |
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
@spaces.GPU
|
115 |
def upsample_features(image, model_option):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
from featup.util import norm, unnorm
|
117 |
models = {o: torch.hub.load("mhamilton723/FeatUp", o) for o in options}
|
118 |
|