Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pari/install update #98

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,55 @@ We use an evironment with the following specifications, packages and dependencie

## Setup Instructions

- Create a conda environment
- Create a conda environment:

```bash
conda create --name oneformer python=3.8 -y
conda activate oneformer
```

- Install packages and other dependencies.
- Install packages and other dependencies:

```bash
git clone https://github.com/SHI-Labs/OneFormer.git
cd OneFormer

# Install Pytorch
conda install pytorch==1.10.1 torchvision==0.11.2 cudatoolkit=11.3 -c pytorch -c conda-forge
# Install Pytorch; if nvcc supports cudatoolkit 11.3 then just install cudatoolkit=11.3, else cudatoolkit-dev=11.3
conda install pytorch==1.10.1 torchvision==0.11.2 cudatoolkit-dev=11.3 -c pytorch -c conda-forge

# Install opencv (required for running the demo)
pip3 install -U opencv-python

# Install detectron2
python tools/setup_detectron2.py
pip3 install 'git+https://github.com/facebookresearch/detectron2.git#egg=detectron2'
# OR: python tools/setup_detectron2.py

# Install other dependencies
pip3 install git+https://github.com/cocodataset/panopticapi.git
pip3 install git+https://github.com/mcordts/cityscapesScripts.git
pip3 install -r requirements.txt
```

- Setup wandb.
- Install OneFormer in development mode:

From repo root (`OneFormer/`), run:
```bash
pip3 install -e .
```

- Setup wandb:

```bash
# Setup wand
pip3 install wandb
wandb login
```

- Setup CUDA Kernel for MSDeformAttn. `CUDA_HOME` must be defined and points to the directory of the installed CUDA toolkit.
- Setup CUDA Kernel for MSDeformAttn (`CUDA_HOME`:check with which nvcc - must be defined, pointing to the directory of the installed CUDA toolkit):

```bash
# Setup MSDeformAttn
cd oneformer/modeling/pixel_decoder/ops
pushd oneformer/modeling/pixel_decoder/ops
sh make.sh
cd ../../../..
popd
```

22 changes: 13 additions & 9 deletions demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
import os
import torch
import random
# fmt: off
import sys
sys.path.insert(1, os.path.join(sys.path[0], '..'))
# fmt: on

import time
import cv2
Expand Down Expand Up @@ -107,7 +103,6 @@ def get_parser():
if args.input:
for path in tqdm.tqdm(args.input, disable=not args.output):
# use PIL, to be consistent with evaluation

img = read_image(path, format="BGR")
start_time = time.time()
predictions, visualized_output = demo.run_on_image(img, args.task)
Expand All @@ -125,14 +120,23 @@ def get_parser():
for k in visualized_output.keys():
os.makedirs(k, exist_ok=True)
out_filename = os.path.join(k, args.output)
visualized_output[k].save(out_filename)
visualized_output[k].save(out_filename)
else:
for k in visualized_output.keys():
opath = os.path.join(args.output, k)
opath = os.path.join(args.output, k)
os.makedirs(opath, exist_ok=True)
out_filename = os.path.join(opath, os.path.basename(path))
visualized_output[k].save(out_filename)
visualized_output[k].save(out_filename)
else:
raise ValueError("Please specify an output path!")
logger.debug("No output path specified; displaying output image(s)")
try:
for k in visualized_output.keys():
window_title = f"{WINDOW_NAME}: {k}"
cv2.imshow(window_title, visualized_output[k].get_image())
cv2.waitKey(1)
print("Press any key...")
cv2.waitKey(-1) # blocking
finally:
cv2.destroyAllWindows()
else:
raise ValueError("No Input Given")
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cython
numpy<1.24.0
scipy==1.8.1
shapely
h5py==3.7.0
Expand Down
58 changes: 58 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""OneFormer: One Transformer to Rule Universal Image Segmentation"""

import pathlib
import shlex
import subprocess
import warnings

from pkg_resources import parse_requirements
from setuptools import setup, find_packages

# Package version
VERSION = '1.0.0'

def version(base_version=VERSION, default_branch='main'):
"""Prepare SCM-aware package version string."""
branch_name = subprocess.check_output(shlex.split("git rev-parse --abbrev-ref HEAD"), text=True).strip()
if branch_name == default_branch:
return base_version
else:
short_commit_sha = subprocess.check_output(shlex.split("git rev-parse --short HEAD"), text=True).strip()
return f'{base_version}+g{short_commit_sha}'


# Packages to install
packages = find_packages(exclude=('tests', 'tests.*'))

# Parse dependencies from requirements.txt
install_requires = []
try:
with pathlib.Path('requirements.txt').open() as requirements_txt:
install_requires = [
str(requirement) \
for requirement in parse_requirements(requirements_txt)
]
except Exception as e:
warnings.warn(f"Unable to parse requirements! {type(e).__name__}: {str(e)}")

# Extras
extras_require = {}
extras_require['all'] = list(set(
dep for dep_list in extras_require.values() for dep in dep_list)) # magic: all except test

tests_require = []
extras_require['test'] = tests_require # magic: test only

# Setup with metadata
setup(
name='oneformer',
version=version(),
description='OneFormer: One Transformer to Rule Universal Image Segmentation',
url='https://github.com/SHI-Labs/OneFormer',
author='Jitesh Jain',
author_email='[email protected]',
packages=packages,
install_requires=install_requires,
extras_require=extras_require,
tests_require=tests_require
)
6 changes: 0 additions & 6 deletions tools/analyze_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
)
from detectron2.utils.logger import setup_logger

# fmt: off
import os
import sys
sys.path.insert(1, os.path.join(sys.path[0], '..'))
# fmt: on

from oneformer.data.build import *
from oneformer.data.dataset_mappers.dataset_mapper import DatasetMapper
from oneformer import (
Expand Down
6 changes: 0 additions & 6 deletions tools/calc_throughput.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
from detectron2.utils.logger import setup_logger
from trainers.trainer import TPDefaultTrainer

# fmt: off
import os
import sys
sys.path.insert(1, os.path.join(sys.path[0], '..'))
# fmt: on

from oneformer import (
COCOUnifiedNewBaselineDatasetMapper,
OneFormerUnifiedDatasetMapper,
Expand Down
4 changes: 1 addition & 3 deletions tools/setup_detectron2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sys, os, distutils.core, subprocess
import os, distutils.core, subprocess

if not os.path.exists('./detectron2'):
subprocess.run(['git', 'clone', 'https://github.com/facebookresearch/detectron2'])
Expand All @@ -7,5 +7,3 @@

for x in dist.install_requires:
subprocess.run(['python', '-m', 'pip', 'install', x])

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