test
Browse files
app.py
CHANGED
@@ -2,31 +2,10 @@ import os
|
|
2 |
import subprocess
|
3 |
import glob
|
4 |
|
5 |
-
# Find all CUDA directories that match /usr/local/cuda*
|
6 |
-
cuda_dirs = glob.glob('/usr/local/cuda*')
|
7 |
-
|
8 |
-
if not cuda_dirs:
|
9 |
-
raise EnvironmentError('No CUDA installation found. Please install CUDA or set CUDA_HOME manually.')
|
10 |
-
|
11 |
-
# Assume the highest version of CUDA is the one to use
|
12 |
-
cuda_dirs.sort()
|
13 |
-
cuda_home = cuda_dirs[-1]
|
14 |
-
|
15 |
-
# Set the CUDA_HOME environment variable
|
16 |
-
os.environ['CUDA_HOME'] = cuda_home
|
17 |
-
os.environ['PATH'] = os.environ['CUDA_HOME'] + '/bin:' + os.environ['PATH']
|
18 |
-
os.environ['LD_LIBRARY_PATH'] = os.environ['CUDA_HOME'] + '/lib64:' + os.environ.get('LD_LIBRARY_PATH', '')
|
19 |
-
|
20 |
-
# Install the required package from GitHub
|
21 |
-
subprocess.check_call(["pip", "install", "git+https://github.com/mhamilton723/FeatUp"])
|
22 |
-
|
23 |
-
|
24 |
import matplotlib.pyplot as plt
|
25 |
import torch
|
26 |
import torchvision.transforms as T
|
27 |
-
from PIL import Image
|
28 |
import gradio as gr
|
29 |
-
from featup.util import norm, unnorm, pca, remove_axes
|
30 |
from pytorch_lightning import seed_everything
|
31 |
import os
|
32 |
import requests
|
@@ -35,6 +14,7 @@ import spaces
|
|
35 |
|
36 |
|
37 |
def plot_feats(image, lr, hr):
|
|
|
38 |
assert len(image.shape) == len(lr.shape) == len(hr.shape) == 3
|
39 |
seed_everything(0)
|
40 |
[lr_feats_pca, hr_feats_pca], _ = pca(
|
@@ -113,6 +93,30 @@ models = {o: torch.hub.load("mhamilton723/FeatUp", o) for o in options}
|
|
113 |
|
114 |
@spaces.GPU
|
115 |
def upsample_features(image, model_option):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
# Image preprocessing
|
117 |
input_size = 224
|
118 |
transform = T.Compose([
|
|
|
2 |
import subprocess
|
3 |
import glob
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import matplotlib.pyplot as plt
|
6 |
import torch
|
7 |
import torchvision.transforms as T
|
|
|
8 |
import gradio as gr
|
|
|
9 |
from pytorch_lightning import seed_everything
|
10 |
import os
|
11 |
import requests
|
|
|
14 |
|
15 |
|
16 |
def plot_feats(image, lr, hr):
|
17 |
+
from featup.util import pca, remove_axes
|
18 |
assert len(image.shape) == len(lr.shape) == len(hr.shape) == 3
|
19 |
seed_everything(0)
|
20 |
[lr_feats_pca, hr_feats_pca], _ = pca(
|
|
|
93 |
|
94 |
@spaces.GPU
|
95 |
def upsample_features(image, model_option):
|
96 |
+
|
97 |
+
# Find all CUDA directories that match /usr/local/cuda*
|
98 |
+
cuda_dirs = glob.glob('/usr/local/cuda*')
|
99 |
+
|
100 |
+
if not cuda_dirs:
|
101 |
+
raise EnvironmentError('No CUDA installation found. Please install CUDA or set CUDA_HOME manually.')
|
102 |
+
|
103 |
+
# Assume the highest version of CUDA is the one to use
|
104 |
+
cuda_dirs.sort()
|
105 |
+
cuda_home = cuda_dirs[-1]
|
106 |
+
|
107 |
+
# Set the CUDA_HOME environment variable
|
108 |
+
os.environ['CUDA_HOME'] = cuda_home
|
109 |
+
os.environ['PATH'] = os.environ['CUDA_HOME'] + '/bin:' + os.environ['PATH']
|
110 |
+
os.environ['LD_LIBRARY_PATH'] = os.environ['CUDA_HOME'] + '/lib64:' + os.environ.get('LD_LIBRARY_PATH', '')
|
111 |
+
|
112 |
+
# Install the required package from GitHub
|
113 |
+
subprocess.check_call(["pip", "install", "git+https://github.com/mhamilton723/FeatUp"])
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
from featup.util import norm, unnorm
|
118 |
+
|
119 |
+
|
120 |
# Image preprocessing
|
121 |
input_size = 224
|
122 |
transform = T.Compose([
|