pytorch / pytorch/vision

```GeneralizedRCNN``` on GPU always detects degenerate bounding boxes

Open
#8,015 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🐛 Describe the bug

Existing issues:
There is no issue on this topic. Issue #6787 has a discussion on the assert statement on degenerate bboxes.

Problem description:
When running a model that makes use of GeneralizedRCNN on GPU bounding boxes are always detected as degenerate.
The model then throws the following error:
ValueError: All bounding boxes should have positive height and width. Found invalid box [x1, y1, x2, y2] for target index 0.

Cause of the problem:
The problem occurs because in generalized_rcnn.py on line 91. The problem is that '.any()' returns the correct values on CPU but not on GPU.

cpu_tensor = torch.tensor([[False, False], [False, False], [False, False]])
cpu_tensor.to('cpu')
gpu_tensor = cpu_tensor.to('cuda')

print(cpu_tensor)
# tensor([[False, False],
#         [False, False],
#         [False, False]])

print(gpu_tensor)
# tensor([[False, False],
#         [False, False],
#         [False, False]], device='cuda:0')

cpu_tensor.any()
# tensor(False)

gpu_tensor.any()
# tensor(True, device='cuda:0')

any(list(gpu_tensor.flatten()))
# False

Problem solution:
I solved the issue by manually going into the side packages (venv/lib/python3.10/site-packages/torchvision/models/detection/generalized_rcnn.py) and changing line 91 to:

if any(list(degenerate_boxes.flatten())):

I hope this helps anyone running into the same problem.

Question:
I am not sure if this is the most elegant solution and there is a TODO-comment wanting this part to be moved to a new function.
Should I nevertheless open a PR to just change this line or is there already work done on this?

Versions

> python collect_env.py

Collecting environment information...
<project_folder>/venv_ml/lib/python3.10/site-packages/torch/cuda/init.py:546: UserWarning: Can't initialize NVML
warnings.warn("Can't initialize NVML")
PyTorch version: 2.0.1+rocm5.4.2
Is debug build: False
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: 5.4.22803-474e8620

OS: Ubuntu 22.04.3 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.27.4
Libc version: glibc-2.35

Python version: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-5.19.0-45-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.5.119
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: AMD Radeon RX 6800 XT
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: 5.4.22803
MIOpen runtime version: 2.19.0
Is XNNPACK available: True

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: GenuineIntel
Model name: 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz
CPU family: 6
Model: 167
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
Stepping: 1
CPU max MHz: 5300.0000
CPU min MHz: 800.0000
BogoMIPS: 7008.00
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap avx512ifma clflushopt intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid fsrm md_clear flush_l1d arch_capabilities
L1d cache: 384 KiB (8 instances)
L1i cache: 256 KiB (8 instances)
L2 cache: 4 MiB (8 instances)
L3 cache: 16 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed: Mitigation; Enhanced IBRS
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] numpy==1.25.2
[pip3] pytorch-lightning==1.9.5
[pip3] pytorch-triton-rocm==2.0.1
[pip3] torch==2.0.1+rocm5.4.2
[pip3] torchaudio==2.0.2+rocm5.4.2
[pip3] torchdata==0.6.1
[pip3] torchmetrics==1.1.2
[pip3] torchsummary==1.5.1
[pip3] torchtext==0.15.2
[pip3] torchvision==0.15.2+rocm5.4.2
[pip3] triton==2.0.0
[conda] Could not collect

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with torchvision/models/detection/generalized_rcnn.py around line 91 and reproduce the reported difference between CPU and GPU any() behavior using the provided tensors. Compare the proposed flatten-and-list check with the discussion in issue #6787 and the TODO noted in the report; done means degenerate boxes are not falsely detected on the reported GPU setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.