File size: 676 Bytes
8332d88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import subprocess
import sys
import os

# Install torch first
subprocess.check_call([sys.executable, "-m", "pip", "install", "torch>=2.0.0", "torchvision>=0.15.0"])

# Clone and install detectron2
if not os.path.exists('detectron2'):
    subprocess.check_call(["git", "clone", "https://github.com/facebookresearch/detectron2"])

# Install detectron2 dependencies
import distutils.core
dist = distutils.core.run_setup("./detectron2/setup.py")
deps = ' '.join([f"'{x}'" for x in dist.install_requires if 'torch' not in x])
subprocess.check_call(f"{sys.executable} -m pip install {deps}", shell=True)

# Add detectron2 to path
sys.path.insert(0, os.path.abspath('./detectron2'))