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

Feature/add environmentyml #290

Open
wants to merge 3 commits into
base: master
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ classification/convertor/
segmentation/convertor/
checkpoint_dir/
demo/
build/
dist/
DCNv3.egg-info/
141 changes: 141 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: internimage
channels:
- pytorch
- conda-forge
- defaults
dependencies:
- _libgcc_mutex=0.1=conda_forge
- _openmp_mutex=4.5=2_gnu
- blas=1.0=mkl
- brotlipy=0.7.0=py37h27cfd23_1003
- bzip2=1.0.8=h5eee18b_5
- ca-certificates=2024.3.11=h06a4308_0
- certifi=2024.2.2=pyhd8ed1ab_0
- cffi=1.15.1=py37h5eee18b_3
- charset-normalizer=2.0.4=pyhd3eb1b0_0
- cryptography=38.0.2=py37h5994e8b_1
- cudatoolkit=11.3.1=h2bc3f7f_2
- cudatoolkit-dev=11.3.1=py37h5e8e339_0
- ffmpeg=4.3=hf484d3e_0
- flit-core=3.6.0=pyhd3eb1b0_0
- freetype=2.12.1=h4a9f257_0
- giflib=5.2.1=h5eee18b_3
- gmp=6.2.1=h295c915_3
- gnutls=3.6.15=he1e5248_0
- idna=3.4=py37h06a4308_0
- intel-openmp=2021.4.0=h06a4308_3561
- jpeg=9e=h5eee18b_1
- lame=3.100=h7b6447c_0
- lcms2=2.12=h3be6417_0
- ld_impl_linux-64=2.38=h1181459_1
- lerc=3.0=h295c915_0
- libblas=3.9.0=12_linux64_mkl
- libcblas=3.9.0=12_linux64_mkl
- libdeflate=1.17=h5eee18b_1
- libffi=3.4.4=h6a678d5_0
- libgcc-ng=13.2.0=hc881cc4_6
- libgfortran-ng=13.2.0=h69a702a_6
- libgfortran5=13.2.0=h43f5ff8_6
- libgomp=13.2.0=hc881cc4_6
- libiconv=1.16=h7f8727e_2
- libidn2=2.3.4=h5eee18b_0
- liblapack=3.9.0=12_linux64_mkl
- libnsl=2.0.1=hd590300_0
- libpng=1.6.39=h5eee18b_0
- libstdcxx-ng=11.2.0=h1234567_1
- libtasn1=4.19.0=h5eee18b_0
- libtiff=4.5.1=h6a678d5_0
- libunistring=0.9.10=h27cfd23_0
- libuv=1.44.2=h5eee18b_0
- libwebp=1.2.4=h11a3e52_1
- libwebp-base=1.2.4=h5eee18b_1
- libzlib=1.2.13=hd590300_5
- lz4-c=1.9.4=h6a678d5_0
- mkl=2021.4.0=h06a4308_640
- mkl-service=2.4.0=py37h7f8727e_0
- mkl_fft=1.3.1=py37hd3c417c_0
- mkl_random=1.2.2=py37h51133e4_0
- ncurses=6.4=h6a678d5_0
- nettle=3.7.3=hbbd107a_1
- numpy=1.21.5=py37h6c91a56_3
- numpy-base=1.21.5=py37ha15fc14_3
- openh264=2.1.1=h4ff587b_0
- openssl=3.2.1=hd590300_1
- pillow=9.4.0=py37h6a678d5_0
- pip=24.0=pyhd8ed1ab_0
- pycparser=2.21=pyhd3eb1b0_0
- pyopenssl=23.0.0=py37h06a4308_0
- pysocks=1.7.1=py37_1
- python=3.7.12=hf930737_100_cpython
- python_abi=3.7=4_cp37m
- pytorch=1.11.0=py3.7_cuda11.3_cudnn8.2.0_0
- pytorch-mutex=1.0=cuda
- pyyaml=6.0=py37h540881e_4
- readline=8.2=h5eee18b_0
- scipy=1.7.3=py37hf2a6cf1_0
- six=1.16.0=pyhd3eb1b0_1
- sqlite=3.41.2=h5eee18b_0
- termcolor=2.3.0=pyhd8ed1ab_0
- tk=8.6.12=h1ccaba5_0
- torchaudio=0.11.0=py37_cu113
- torchvision=0.12.0=py37_cu113
- urllib3=1.26.14=py37h06a4308_0
- wheel=0.38.4=py37h06a4308_0
- xz=5.4.6=h5eee18b_0
- yacs=0.1.8=pyhd8ed1ab_0
- yaml=0.2.5=h7f98852_2
- zlib=1.2.13=hd590300_5
- zstd=1.5.5=hc292b87_0
- pip:
- addict==2.4.0
- aliyun-python-sdk-core==2.15.1
- aliyun-python-sdk-kms==2.16.2
- click==8.1.7
- colorama==0.4.6
- crcmod==1.7
- cycler==0.11.0
- dcnv3==1.0
- filelock==3.12.2
- fonttools==4.38.0
- fsspec==2023.1.0
- huggingface-hub==0.16.4
- importlib-metadata==6.7.0
- jmespath==0.10.0
- kiwisolver==1.4.5
- markdown==3.4.4
- markdown-it-py==2.2.0
- matplotlib==3.5.3
- mdurl==0.1.2
- mmcls==0.25.0
- mmcv-full==1.5.0
- mmdet==2.28.1
- mmsegmentation==0.27.0
- model-index==0.1.11
- opencv-python==4.9.0.80
- opendatalab==0.0.10
- openmim==0.3.9
- openxlab==0.0.10
- ordered-set==4.1.0
- oss2==2.17.0
- packaging==24.0
- pandas==1.3.5
- platformdirs==4.0.0
- prettytable==3.7.0
- pycocotools==2.0.7
- pycryptodome==3.20.0
- pygments==2.17.2
- pyparsing==3.1.2
- python-dateutil==2.9.0.post0
- pytz==2023.4
- requests==2.28.2
- rich==13.7.1
- setuptools==60.2.0
- tabulate==0.9.0
- terminaltables==3.1.10
- timm==0.6.11
- tomli==2.0.1
- tqdm==4.65.2
- typing-extensions==4.7.1
- wcwidth==0.2.13
- yapf==0.40.2
- zipp==3.15.0
36 changes: 7 additions & 29 deletions segmentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,22 @@ git clone https://github.com/OpenGVLab/InternImage.git
cd InternImage
```

- Install Nvidia driver which is compatible with `CUDA>=10.2` with `cudnn>=7` following
the [official installation instructions](https://developer.nvidia.com/cuda-downloads?)

(Note: CUDA and other Nvidia stufff will be automatically installed by the next step from the conda environment.yml file.)

- Create a conda virtual environment and activate it:

```bash
conda create -n internimage python=3.7 -y
conda env create -f environment.yml
conda activate internimage
```

- Install `CUDA>=10.2` with `cudnn>=7` following
the [official installation instructions](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html)
- Install `PyTorch>=1.10.0` and `torchvision>=0.9.0` with `CUDA>=10.2`:

For examples, to install torch==1.11 with CUDA==11.3 and nvcc:
```bash
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch -y
conda install -c conda-forge cudatoolkit-dev=11.3 -y # to install nvcc
```

- Install other requirements:

note: conda opencv will break torchvision as not to support GPU, so we need to install opencv using pip.

```bash
conda install -c conda-forge termcolor yacs pyyaml scipy pip -y
pip install opencv-python
```

- Install `timm` and `mmcv-full` and `mmsegmentation':

```bash
pip install -U openmim
mim install mmcv-full==1.5.0
mim install mmsegmentation==0.27.0
pip install timm==0.6.11 mmdet==2.28.1
```

- Compile CUDA operators
```bash
cd ./ops_dcnv3
cd segmentation/ops_dcnv3
sh ./make.sh
# unit test (should see all checking is True)
python test.py
Expand Down
26 changes: 18 additions & 8 deletions segmentation/image_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@


def test_single_image(model, img_name, out_dir, color_palette, opacity):
# check img_name is an image file or not
assumed_imgformat = ('.png', '.jpg', '.jpeg', '.tiff', '.bmp', '.gif')
if (not img_name.lower().endswith(assumed_imgformat)):
print(f"Skip {img_name} because it is not an image file.")
return

result = inference_segmentor(model, img_name)

# show the results
if hasattr(model, 'module'):
model = model.module
img = model.show_result(img_name, result,
palette=color_palette,
show=False, opacity=opacity)

# save the results
mmcv.mkdir_or_exist(out_dir)
out_path = osp.join(out_dir, osp.basename(img_name))
Expand All @@ -33,7 +39,8 @@ def test_single_image(model, img_name, out_dir, color_palette, opacity):

def main():
parser = ArgumentParser()
parser.add_argument('img', help='Image file or a directory contains images')
parser.add_argument(
'img', help='Image file or a directory contains images')
parser.add_argument('config', help='Config file')
parser.add_argument('checkpoint', help='Checkpoint file')
parser.add_argument('--out', type=str, default="demo", help='out dir')
Expand All @@ -58,13 +65,16 @@ def main():
model.CLASSES = checkpoint['meta']['CLASSES']
else:
model.CLASSES = get_classes(args.palette)

# check arg.img is directory of a single image.
if osp.isdir(args.img):
for img in os.listdir(args.img):
test_single_image(model, osp.join(args.img, img), args.out, get_palette(args.palette), args.opacity)
for img in sorted(os.listdir(args.img)):
test_single_image(model, osp.join(args.img, img),
args.out, get_palette(args.palette), args.opacity)
else:
test_single_image(model, args.img, args.out, get_palette(args.palette), args.opacity)
test_single_image(model, args.img, args.out,
get_palette(args.palette), args.opacity)


if __name__ == '__main__':
main()
main()