Update app.py
Browse files
app.py
CHANGED
@@ -6,13 +6,68 @@
|
|
6 |
# Written by Xueyan Zou ([email protected]), Jianwei Yang ([email protected])
|
7 |
# --------------------------------------------------------
|
8 |
|
9 |
-
# Install
|
10 |
import os
|
11 |
import sys
|
12 |
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
print("Installing detectron2...")
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Set Python path to include the repository root
|
18 |
os.environ["PYTHONPATH"] = os.getcwd()
|
|
|
6 |
# Written by Xueyan Zou ([email protected]), Jianwei Yang ([email protected])
|
7 |
# --------------------------------------------------------
|
8 |
|
9 |
+
# Install dependencies and patch files before any imports
|
10 |
import os
|
11 |
import sys
|
12 |
import subprocess
|
13 |
+
|
14 |
+
print("Setting up SEEM environment...")
|
15 |
+
|
16 |
+
# Create a custom distributed.py file that doesn't need mpi4py
|
17 |
+
os.makedirs('utils', exist_ok=True)
|
18 |
+
with open('utils/distributed.py', 'w') as f:
|
19 |
+
f.write("""# Custom distributed.py without mpi4py dependency
|
20 |
+
import os
|
21 |
+
import torch
|
22 |
+
import torch.distributed as dist
|
23 |
+
|
24 |
+
class MPI:
|
25 |
+
class COMM_WORLD:
|
26 |
+
@staticmethod
|
27 |
+
def Get_rank():
|
28 |
+
return 0
|
29 |
+
@staticmethod
|
30 |
+
def Get_size():
|
31 |
+
return 1
|
32 |
+
|
33 |
+
def init_distributed(opt=None):
|
34 |
+
if opt is not None:
|
35 |
+
opt.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
36 |
+
opt.rank = 0
|
37 |
+
opt.world_size = 1
|
38 |
+
opt.gpu = 0
|
39 |
+
return opt
|
40 |
+
|
41 |
+
return None
|
42 |
+
|
43 |
+
def get_rank():
|
44 |
+
return 0
|
45 |
+
|
46 |
+
def get_world_size():
|
47 |
+
return 1
|
48 |
+
|
49 |
+
def is_main_process():
|
50 |
+
return True
|
51 |
+
|
52 |
+
def synchronize():
|
53 |
+
pass
|
54 |
+
|
55 |
+
def all_gather(data):
|
56 |
+
return [data]
|
57 |
+
|
58 |
+
def reduce_dict(input_dict, average=True):
|
59 |
+
return input_dict
|
60 |
+
""")
|
61 |
+
print("Created custom distributed.py")
|
62 |
+
|
63 |
+
# Install detectron2
|
64 |
print("Installing detectron2...")
|
65 |
+
try:
|
66 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "git+https://github.com/MaureenZOU/detectron2-xyz.git"])
|
67 |
+
print("Detectron2 installation complete!")
|
68 |
+
except Exception as e:
|
69 |
+
print(f"Error installing detectron2: {e}")
|
70 |
+
sys.exit(1)
|
71 |
|
72 |
# Set Python path to include the repository root
|
73 |
os.environ["PYTHONPATH"] = os.getcwd()
|