Spaces:
Running
on
T4
Running
on
T4
yizhangliu
commited on
Commit
•
bc4c863
1
Parent(s):
7120670
update app.py
Browse files
app.py
CHANGED
@@ -13,12 +13,12 @@ os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
|
13 |
|
14 |
if os.environ.get('IS_MY_DEBUG') is None:
|
15 |
result = subprocess.run(['pip', 'install', '-e', 'GroundingDINO'], check=True)
|
16 |
-
|
17 |
|
18 |
logger.info(f"Start app...")
|
19 |
|
20 |
# result = subprocess.run(['pip', 'list'], check=True)
|
21 |
-
#
|
22 |
|
23 |
sys.path.insert(0, './GroundingDINO')
|
24 |
|
@@ -132,7 +132,7 @@ def load_model_hf(model_config_path, repo_id, filename, device='cpu'):
|
|
132 |
cache_file = hf_hub_download(repo_id=repo_id, filename=filename)
|
133 |
checkpoint = torch.load(cache_file, map_location=device)
|
134 |
log = model.load_state_dict(clean_state_dict(checkpoint['model']), strict=False)
|
135 |
-
|
136 |
_ = model.eval()
|
137 |
return model
|
138 |
|
@@ -289,7 +289,7 @@ def set_device(args):
|
|
289 |
device = args.cuda if torch.cuda.is_available() else 'cpu'
|
290 |
else:
|
291 |
device = 'cpu'
|
292 |
-
|
293 |
|
294 |
def load_groundingdino_model(device):
|
295 |
# initialize groundingdino model
|
@@ -302,7 +302,7 @@ def get_sam_vit_h_4b8939():
|
|
302 |
if not os.path.exists('./sam_vit_h_4b8939.pth'):
|
303 |
logger.info(f"get sam_vit_h_4b8939.pth...")
|
304 |
result = subprocess.run(['wget', '-nv', 'https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth'], check=True)
|
305 |
-
|
306 |
|
307 |
def load_sam_model(device):
|
308 |
# initialize SAM
|
@@ -1091,10 +1091,11 @@ def main_gradio(args):
|
|
1091 |
<a href="https://huggingface.co/spaces/yizhangliu/Grounded-Segment-Anything?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
1092 |
gr.Markdown(DESCRIPTION)
|
1093 |
|
1094 |
-
|
1095 |
-
|
1096 |
computer_info()
|
1097 |
block.queue(max_size=10, api_open=False)
|
|
|
1098 |
block.launch(server_name='0.0.0.0', server_port=args.port, debug=args.debug, share=args.share, show_api=False)
|
1099 |
|
1100 |
if __name__ == "__main__":
|
@@ -1104,7 +1105,7 @@ if __name__ == "__main__":
|
|
1104 |
parser.add_argument("--port", "-p", type=int, default=7860, help="port")
|
1105 |
parser.add_argument("--cuda", "-c", type=str, default='cuda:0', help="cuda")
|
1106 |
args, _ = parser.parse_known_args()
|
1107 |
-
|
1108 |
|
1109 |
if os.environ.get('IS_MY_DEBUG') is None:
|
1110 |
os.system("pip list")
|
|
|
13 |
|
14 |
if os.environ.get('IS_MY_DEBUG') is None:
|
15 |
result = subprocess.run(['pip', 'install', '-e', 'GroundingDINO'], check=True)
|
16 |
+
logger.info(f'pip install GroundingDINO = {result}')
|
17 |
|
18 |
logger.info(f"Start app...")
|
19 |
|
20 |
# result = subprocess.run(['pip', 'list'], check=True)
|
21 |
+
# logger.info(f'pip list = {result}')
|
22 |
|
23 |
sys.path.insert(0, './GroundingDINO')
|
24 |
|
|
|
132 |
cache_file = hf_hub_download(repo_id=repo_id, filename=filename)
|
133 |
checkpoint = torch.load(cache_file, map_location=device)
|
134 |
log = model.load_state_dict(clean_state_dict(checkpoint['model']), strict=False)
|
135 |
+
logger.info("Model loaded from {} \n => {}".format(cache_file, log))
|
136 |
_ = model.eval()
|
137 |
return model
|
138 |
|
|
|
289 |
device = args.cuda if torch.cuda.is_available() else 'cpu'
|
290 |
else:
|
291 |
device = 'cpu'
|
292 |
+
logger.info(f'device={device}')
|
293 |
|
294 |
def load_groundingdino_model(device):
|
295 |
# initialize groundingdino model
|
|
|
302 |
if not os.path.exists('./sam_vit_h_4b8939.pth'):
|
303 |
logger.info(f"get sam_vit_h_4b8939.pth...")
|
304 |
result = subprocess.run(['wget', '-nv', 'https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth'], check=True)
|
305 |
+
logger.info(f'wget sam_vit_h_4b8939.pth result = {result}')
|
306 |
|
307 |
def load_sam_model(device):
|
308 |
# initialize SAM
|
|
|
1091 |
<a href="https://huggingface.co/spaces/yizhangliu/Grounded-Segment-Anything?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
1092 |
gr.Markdown(DESCRIPTION)
|
1093 |
|
1094 |
+
logger.info(f'device = {device}')
|
1095 |
+
logger.info(f'torch.cuda.is_available = {torch.cuda.is_available()}')
|
1096 |
computer_info()
|
1097 |
block.queue(max_size=10, api_open=False)
|
1098 |
+
logger.info(f"Start a gradio server[{os.getpid()}]: http://0.0.0.0:{args.port}")
|
1099 |
block.launch(server_name='0.0.0.0', server_port=args.port, debug=args.debug, share=args.share, show_api=False)
|
1100 |
|
1101 |
if __name__ == "__main__":
|
|
|
1105 |
parser.add_argument("--port", "-p", type=int, default=7860, help="port")
|
1106 |
parser.add_argument("--cuda", "-c", type=str, default='cuda:0', help="cuda")
|
1107 |
args, _ = parser.parse_known_args()
|
1108 |
+
logger.info(f'args = {args}')
|
1109 |
|
1110 |
if os.environ.get('IS_MY_DEBUG') is None:
|
1111 |
os.system("pip list")
|