Update config.py
Browse files
config.py
CHANGED
@@ -1,7 +1,9 @@
|
|
|
|
1 |
import sys
|
2 |
import torch
|
3 |
from multiprocessing import cpu_count
|
4 |
|
|
|
5 |
class Config:
|
6 |
def __init__(self):
|
7 |
self.device = "cuda:0"
|
@@ -9,8 +11,42 @@ class Config:
|
|
9 |
self.n_cpu = 0
|
10 |
self.gpu_name = None
|
11 |
self.gpu_mem = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
self.x_pad, self.x_query, self.x_center, self.x_max = self.device_config()
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# has_mps is only available in nightly pytorch (for now) and MasOS 12.3+.
|
15 |
# check `getattr` and try it for compatibility
|
16 |
@staticmethod
|
@@ -70,7 +106,7 @@ class Config:
|
|
70 |
x_center = 38
|
71 |
x_max = 41
|
72 |
|
73 |
-
if self.gpu_mem
|
74 |
x_pad = 1
|
75 |
x_query = 5
|
76 |
x_center = 30
|
|
|
1 |
+
import argparse
|
2 |
import sys
|
3 |
import torch
|
4 |
from multiprocessing import cpu_count
|
5 |
|
6 |
+
|
7 |
class Config:
|
8 |
def __init__(self):
|
9 |
self.device = "cuda:0"
|
|
|
11 |
self.n_cpu = 0
|
12 |
self.gpu_name = None
|
13 |
self.gpu_mem = None
|
14 |
+
(
|
15 |
+
self.python_cmd,
|
16 |
+
self.listen_port,
|
17 |
+
self.iscolab,
|
18 |
+
self.noparallel,
|
19 |
+
self.noautoopen,
|
20 |
+
) = self.arg_parse()
|
21 |
self.x_pad, self.x_query, self.x_center, self.x_max = self.device_config()
|
22 |
|
23 |
+
@staticmethod
|
24 |
+
def arg_parse() -> tuple:
|
25 |
+
exe = sys.executable or "python"
|
26 |
+
parser = argparse.ArgumentParser()
|
27 |
+
parser.add_argument("--port", type=int, default=7865, help="Listen port")
|
28 |
+
parser.add_argument("--pycmd", type=str, default=exe, help="Python command")
|
29 |
+
parser.add_argument("--colab", action="store_true", help="Launch in colab")
|
30 |
+
parser.add_argument(
|
31 |
+
"--noparallel", action="store_true", help="Disable parallel processing"
|
32 |
+
)
|
33 |
+
parser.add_argument(
|
34 |
+
"--noautoopen",
|
35 |
+
action="store_true",
|
36 |
+
help="Do not open in browser automatically",
|
37 |
+
)
|
38 |
+
cmd_opts = parser.parse_args()
|
39 |
+
|
40 |
+
cmd_opts.port = cmd_opts.port if 0 <= cmd_opts.port <= 65535 else 7865
|
41 |
+
|
42 |
+
return (
|
43 |
+
cmd_opts.pycmd,
|
44 |
+
cmd_opts.port,
|
45 |
+
cmd_opts.colab,
|
46 |
+
cmd_opts.noparallel,
|
47 |
+
cmd_opts.noautoopen,
|
48 |
+
)
|
49 |
+
|
50 |
# has_mps is only available in nightly pytorch (for now) and MasOS 12.3+.
|
51 |
# check `getattr` and try it for compatibility
|
52 |
@staticmethod
|
|
|
106 |
x_center = 38
|
107 |
x_max = 41
|
108 |
|
109 |
+
if self.gpu_mem != None and self.gpu_mem <= 4:
|
110 |
x_pad = 1
|
111 |
x_query = 5
|
112 |
x_center = 30
|