open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.19k stars 9.39k forks source link

I ran demo/image_demo.py with QueryInst, but nothing is output. #6536

Closed Keiku closed 2 years ago

Keiku commented 2 years ago

Describe the bug A clear and concise description of what the bug is.

I ran demo/image_demo.py with QueryInst, but nothing is output.

Reproduction

  1. What command or script did you run?
python demo/image_demo.py data/tiny_coco/val2017/000000580410.jpg ../configs/queryinst/queryinst_r50_fpn_1x_coco.py checkpoints/queryinst_r50_fpn_1x_coco_20210907_084916-5a8f1998.pth --device cuda
  1. Did you make any modifications on the code or config? Did you understand what you have modified?

I set the dataset to tiny coco and used the officially distributed pretrained model.

  1. What dataset did you use?

tiny coco for coco verification.

Environment

  1. Please run python mmdet/utils/collect_env.py to collect necessary environment information and paste it here.
⋊> ~/l/c/Q/mmdetection-2.18.1 on main ◦ python mmdet/utils/collect_env.py    11:47:06
sys.platform: linux
Python: 3.8.6 (default, Nov 16 2021, 14:38:34) [GCC 7.5.0]
CUDA available: True
GPU 0,1: GeForce RTX 2080 Ti
CUDA_HOME: /usr/local/cuda-10.2
NVCC: Cuda compilation tools, release 10.2, V10.2.89
GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
PyTorch: 1.10.0+cu102
PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - C++ Version: 201402
  - Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.2.3 (Git Hash 7336ca9f055cf1bfa13efb658fe15dc9b41f0740)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX512
  - CUDA Runtime 10.2
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70
  - CuDNN 7.6.5
  - Magma 2.5.2
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=10.2, CUDNN_VERSION=7.6.5, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.10.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON,

TorchVision: 0.11.1+cu102
OpenCV: 4.5.4-dev
MMCV: 1.3.17
MMCV Compiler: GCC 7.3
MMCV CUDA Compiler: 10.2
MMDetection: 2.18.1+ffa0f07
⋊> ~/l/c/Q/mmdetection-2.18.1 on main ◦ 
  1. You may add addition that may be helpful for locating the problem, such as
    • How you installed PyTorch [e.g., pip, conda, source]
    • Other environment variables that may be related (such as $PATH, $LD_LIBRARY_PATH, $PYTHONPATH, etc.)

I am experimenting in the following repository. Keiku/QueryInst-Examples: Some examples on QueryInst

Error traceback If applicable, paste the error trackback here.

⋊> ~/l/c/Q/mmdetection-2.18.1 on main ◦ python demo/image_demo.py data/tiny_coco/val2017/000000580410.jpg ../configs/queryinst/queryinst_r50_fpn_1x_coco.py checkpoints/queryinst_r50_fpn_1x_coco_20210907_084916-5a8f1998.pth --device cuda
/home/keiichi.kuroyanagi/.pyenv/versions/3.8.6-queryinst/lib/python3.8/site-packages/mmcv/utils/misc.py:333: UserWarning: "dropout" is deprecated in `FFN.__init__`, please use "ffn_drop" instead
  warnings.warn(
load checkpoint from local path: checkpoints/queryinst_r50_fpn_1x_coco_20210907_084916-5a8f1998.pth
/home/keiichi.kuroyanagi/.pyenv/versions/3.8.6-queryinst/lib/python3.8/site-packages/mmdet/datasets/utils.py:65: UserWarning: "ImageToTensor" pipeline is replaced by "DefaultFormatBundle" for batch inference. It is recommended to manually replace it in the test data pipeline in your config file.
  warnings.warn(
/home/keiichi.kuroyanagi/.pyenv/versions/3.8.6-queryinst/lib/python3.8/site-packages/mmdet/models/roi_heads/sparse_roi_head.py:355: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
  bbox_pred_per_img = proposal_list[img_id][topk_indices //
⋊> ~/l/c/Q/mmdetection-2.18.1 on main ◦ 

Bug fix If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!

Keiku commented 2 years ago

I may have misused demo instead of a bug. I check https://github.com/open-mmlab/mmdetection/issues/1405 .

Keiku commented 2 years ago

I'm sorry. solved.

invincible-28 commented 2 years ago

I'm sorry. solved.

Hi! Were you able to train QueryInst with COCO dataset successfully? If yes, please let me know.

Keiku commented 2 years ago

@invincible-28

I executed the following command to save the image. I think that there is no problem with the same command in QueryInst.

python demo/image_demo.py data/tiny_coco/val2017/000000580410.jpg work_dirs/demo/000000580410.jpg configs/mask_rcnn/mask_rcnn_r50_fpn_1x_coco.py checkpoints/mask_rcnn_r50_fpn_1x_coco_20200205-d4b0c5d6.pth --device cuda

You can save the image by adding model.show_result(args.img, result, out_file=args.out_file) to image_demo.py. The following image_demo.py has been modified with version of mmdetection-2.18.1. Not the latest version.

# Copyright (c) OpenMMLab. All rights reserved.
import asyncio
from argparse import ArgumentParser

from mmdet.apis import (async_inference_detector, inference_detector,
                        init_detector, show_result_pyplot)

def parse_args():
    parser = ArgumentParser()
    parser.add_argument('img', help='Image file')
    parser.add_argument('out_file', help='Output Image file')
    parser.add_argument('config', help='Config file')
    parser.add_argument('checkpoint', help='Checkpoint file')
    parser.add_argument(
        '--device', default='cuda:0', help='Device used for inference')
    parser.add_argument(
        '--score-thr', type=float, default=0.3, help='bbox score threshold')
    parser.add_argument(
        '--async-test',
        action='store_true',
        help='whether to set async options for async inference.')
    args = parser.parse_args()
    return args

def main(args):
    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    # test a single image
    result = inference_detector(model, args.img)
    # show the results
    show_result_pyplot(model, args.img, result, score_thr=args.score_thr)
    model.show_result(args.img, result, out_file=args.out_file)

async def async_main(args):
    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    # test a single image
    tasks = asyncio.create_task(async_inference_detector(model, args.img))
    result = await asyncio.gather(tasks)
    # show the results
    show_result_pyplot(model, args.img, result[0], score_thr=args.score_thr)

if __name__ == '__main__':
    args = parse_args()
    if args.async_test:
        asyncio.run(async_main(args))
    else:
        main(args)
invincible-28 commented 2 years ago

Hi, Thanks for the quick reply.

But I want to train the network with this command: python tools/train.py configs/queryinst/queryinst_r50_fpn_1x_coco.py

I am facing a lot of issues even after setting up the environment correctly. So, just wanted to know if someone else has already tried to train QueryInst on COCO from scratch.

Keiku commented 2 years ago

In my environment, QueryInst was able to train and infer without any problems. Check if there is any problem in building the environment.

invincible-28 commented 2 years ago

okay great to know.

I followed these steps to setup the environment: • conda create -n e7 • conda activate e7 • conda install python=3.7 • source ../Add_to_Environment_Variables.sh • conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=11.0 -c pytorch • pip install mmcv-full==1.3.9 -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html • git clone https://github.com/NVIDIA/apex.git • pip install -r requirements.txt • export CUDA_HOME=/usr/local/cuda-11.0 • pip install -v --no-cache-dir --global-option="--cuda_ext" pytorch-extension • pip install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./ • cd QueryInst/ • python setup.py develop • mkdir data && cd data • ln -s /home/soumya_pf_pt/documents/coco coco • python tools/train.py configs/queryinst/queryinst_r50_fpn_1x_coco.py

Now I get this error when I try to train: 2022-03-31 11:27:51,839 - mmdet - INFO - workflow: [('train', 1)], max: 12 epochs Traceback (most recent call last): File "tools/train.py", line 187, in main() File "tools/train.py", line 183, in main meta=meta) File "/home/soumya_pf_pt/anaconda3/envs/e8/QueryInst/mmdet/apis/train.py", line 193, in train_detector runner.run(data_loaders, cfg.workflow) File "/home/soumya_pf_pt/anaconda3/envs/e8/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 127, in run epoch_runner(data_loaders[i], **kwargs) File "/home/soumya_pf_pt/anaconda3/envs/e8/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 47, in train for i, data_batch in enumerate(self.data_loader): File "/home/soumya_pf_pt/anaconda3/envs/e8/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 352, in iter return self._get_iterator() File "/home/soumya_pf_pt/anaconda3/envs/e8/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 294, in _get_iterator return _MultiProcessingDataLoaderIter(self) File "/home/soumya_pf_pt/anaconda3/envs/e8/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 827, in init self._reset(loader, first_iter=True) File "/home/soumya_pf_pt/anaconda3/envs/e8/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 857, in _reset self._try_put_index() File "/home/soumya_pf_pt/anaconda3/envs/e8/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1091, in _try_put_index index = self._next_index() File "/home/soumya_pf_pt/anaconda3/envs/e8/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 427, in _next_index return next(self._sampler_iter) # may raise StopIteration File "/home/soumya_pf_pt/anaconda3/envs/e8/lib/python3.7/site-packages/torch/utils/data/sampler.py", line 227, in iter for idx in self.sampler: File "/home/soumya_pf_pt/anaconda3/envs/e8/QueryInst/mmdet/datasets/samplers/group_sampler.py", line 36, in iter indices = np.concatenate(indices) File "<__array_function__ internals>", line 6, in concatenate ValueError: need at least one array to concatenate

Keiku commented 2 years ago

In cuda 10.2, I am running the following command.

pip install -U pip
pip install ipdb
pip install mmcv-full==1.3.17 -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.10.0/index.html
pip3 install torch torchvision
pip install mmdet==2.18.1
pip install scipy
pip install seaborn
pip install tensorboard
pip install jupyter notebook jupytext

In cuda 11.3, I am running the following command.

pip install -U pip
pip install ipdb
pip install mmcv-full==1.4.7 -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10.0/index.html
pip install torch==1.10.0+cu113 torchvision==0.11.0+cu113 -f https://download.pytorch.org/whl/torch_stable.html
pip install mmdet==2.22.0
pip install scipy
pip install seaborn
pip install tensorboard
pip install jupyter notebook jupytext
Keiku commented 2 years ago

@invincible-28 The version of mmcv-full may be out of date.

invincible-28 commented 2 years ago

okay, I will try to run with mmcv-full==1.4.7 and check.

invincible-28 commented 2 years ago

I was able to start training the network with my previous setup of the environment. (mmcv-full==1.3.9) But, it is interrupted after the completion of every epoch. Did you also face a similar issue?

Keiku commented 2 years ago

@invincible-28 QueryInst was released in mmdetection v2.18.0. For mmdetection v2.18.0, mmcv-full is supported in 1.3.17 or later.

Prerequisites — MMDetection 2.23.0 documentation https://mmdetection.readthedocs.io/en/latest/get_started.html

image
invincible-28 commented 2 years ago

@Keiku Thank you very much for pointing it out. I am able to train QueryInst with COCO now!

Keiku commented 2 years ago

@invincible-28 That's good. Which version did you use after all?

invincible-28 commented 2 years ago

I used mmcv-full==1.3.17

invincible-28 commented 2 years ago

@Keiku Hey! Have you trained QueryInst with custom dataset? If yes, could you please share which version of mmcv-full did you use?

Because, when I tried training on my custom data, I get this error: 'Ground Truth Not Found!'

Keiku commented 2 years ago

@invincible-28

Here are the steps to apply a simple custom dataset.

  1. Convert the target dataset to COCO format. I always do this.
  2. Define classes as follows:
dataset_type = 'CocoDataset'
# Define a classes
classes = ('class1', 'class2', '...', 'class_4', )
data_root = 'data/your_dataset/'
  1. Specify the converted COCO format dataset. Specify val and test in the same way.
data = dict(
    samples_per_gpu=2,
    workers_per_gpu=2,
    train=dict(
        type='CocoDataset',
        # Add a custom class definition
        classes=classes,
        ann_file='data/your_dataset/annotations/your_dataset.json',
        img_prefix='data/your_dataset/images/',
        pipeline=[
            dict(type='LoadImageFromFile'),
            dict(type='LoadAnnotations', with_bbox=True, with_mask=True),
            dict(type='Resize', img_scale=(1333, 800), keep_ratio=True),
            dict(type='RandomFlip', flip_ratio=0.5),
            dict(
                type='Normalize',
                mean=[123.675, 116.28, 103.53],
                std=[58.395, 57.12, 57.375],
                to_rgb=True),
            dict(type='Pad', size_divisor=32),
            dict(type='DefaultFormatBundle'),
            dict(
                type='Collect',
                keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks'])
        ]),

QueryInst takes a lot of time, so let's practice with Mask R-CNN first.

invincible-28 commented 2 years ago

Yes, I did follow all these steps. I referred to this tutorial: https://mmdetection.readthedocs.io/en/latest/2_new_data_model.html

invincible-28 commented 2 years ago

I was able to fix that error. https://github.com/open-mmlab/mmdetection/issues/7863#issue-1218544240

invincible-28 commented 2 years ago

Hi @Keiku I am training this network with a very small custom dataset, so wanted to use data augmentation to increase the size of the dataset. I see that it is already been implemented here: /home/soumya_pf_pt/anaconda3/envs/env_greenai/QueryInst/mmdet/datasets/pipelines/transforms.py. Is that correct what I have analysed or am I missing something? This network in itself is implementing various data augmentation techniques using the albumentations library. Is it?

Keiku commented 2 years ago

@invincible-28 Does "small" mean dataset size? Or is it image size? If it is dataset size, I think that there is not much change even if data augmentation is done. If it is an image size, I think that data augmentation that increases the resolution is good.

My recommendation is the strong_baselines strategy. The following will be helpful.

New, improved Detectron2 Mask R-CNN baselines https://ai.facebook.com/blog/advancing-computer-vision-research-with-new-detectron2-mask-r-cnn-baselines/

invincible-28 commented 2 years ago

@Keiku By 'small', I mean the dataset size. So, my question is: This network, queryinst in itself is implementing various data augmentation techniques using the albumentations library. Is it?

Keiku commented 2 years ago

@invincible-28 queryinst is loading '../_base_/datasets/coco_instance.py' , so it doesn't use albumations.

https://github.com/open-mmlab/mmdetection/blob/ca11860f4f3c3ca2ce8340e2686eeaec05b29111/configs/queryinst/queryinst_r50_fpn_1x_coco.py#L2

invincible-28 commented 2 years ago

@Keiku queryinst has 6 configuration files with test time augmentation. One of them is:

https://github.com/hustvl/QueryInst/blob/6b974876c6e13e9028c0bb755cf4af6444c48ae5/configs/queryinst/queryinst_r50_fpn_100_proposals_mstrain_480-800_3x_coco.py

(From line 9 to 14)

Keiku commented 2 years ago

@invincible-28 I'm not using hustvl/QueryInst so I'm not sure. Ask hustvl directly.

The following is train_pipeline, so it's not a test time augmentation.

    dict(
        type='Resize',
        img_scale=[(1333, value) for value in min_values],
        multiscale_mode='value',
        keep_ratio=True),
    dict(type='RandomFlip', flip_ratio=0.5),
    dict(type='Normalize', **img_norm_cfg),
    dict(type='Pad', size_divisor=32),
    dict(type='DefaultFormatBundle'),
invincible-28 commented 2 years ago

okay. Did you encounter this error anytime?

_cv2.error: OpenCV(4.5.5) /io/opencv/modules/core/src/copy.cpp:1026: error: (-215:Assertion failed) top >= 0 && bottom >= 0 && left >= 0 && right >= 0 && _src.dims() <= 2 in function 'copyMakeBorder'_