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

Mask R-CNN error when changing aspect_ratios #7599

Closed
PandhaB opened this issue May 18, 2023 · 2 comments
Closed

Mask R-CNN error when changing aspect_ratios #7599

PandhaB opened this issue May 18, 2023 · 2 comments

Comments

@PandhaB
Copy link

PandhaB commented May 18, 2023

🐛 Describe the bug

I'm trying to make the maskrcnn_resnet50_fpn work on a custom simple dataset with 3 kind of objects. My learning works fine when using 3 aspect_ratios. When I'm trying to use more, I get errors. So, it's fine with :

from torchvision.models.detection import maskrcnn_resnet50_fpn
from torchvision.models.detection.rpn import AnchorGenerator
d_mask_model = maskrcnn_resnet50_fpn(num_classes = 3).to('cuda')
d_mask_model.rpn.anchor_generator = AnchorGenerator(
                                sizes = ((8,), (16,), (32,), (64,), (128,)),
                                aspect_ratios = tuple([(0.1, 1.0, 10.0) for i in range (5)]))

I get a RuntimeError: stack expects each tensor to be equal size, but got [1918584, 1] at entry 0 and [1918584, 0] at entry 1, when changing the aspect_ratios to :

                                aspect_ratios = tuple([(0.1, 0.2, 1.0, 10.0) for i in range (5)]))

And a RuntimeError: shape '[2398230, -1]' is invalid for input of size 5755752, with :

                                aspect_ratios = tuple([(0.1, 0.2, 1.0, 5.0, 10.0) for i in range (5)]))

As it works with 3 aspect ratios (I changed the values and it's fine), but not with more, I suspected the problem may be with the implemented RPN. Please tell me if it can come from my dataset or my learning loop definition.

Thanks for any help !

Versions

PyTorch version: 2.1.0a0+fe05266
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.5 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: version 3.24.1
Libc version: glibc-2.31

Python version: 3.8.10 (default, Mar 13 2023, 10:26:41) [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.15.0-72-generic-x86_64-with-glibc2.29
Is CUDA available: True
CUDA runtime version: 12.1.66
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3060 Ti
Nvidia driver version: 530.41.03
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 39 bits physical, 48 bits virtual
CPU(s): 16
On-line CPU(s) list: 0-15
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 167
Model name: 11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz
Stepping: 1
CPU MHz: 2500.000
CPU max MHz: 4900.0000
CPU min MHz: 800.0000
BogoMIPS: 4992.00
Virtualization: VT-x
L1d cache: 384 KiB
L1i cache: 256 KiB
L2 cache: 4 MiB
L3 cache: 16 MiB
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 and seccomp
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
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 vmx 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 tpr_shadow vnmi flexpriority ept vpid ept_ad 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

Versions of relevant libraries:
[pip3] numpy==1.22.2
[pip3] pytorch-quantization==2.1.2
[pip3] torch==2.1.0a0+fe05266
[pip3] torch-tensorrt==1.4.0.dev0
[pip3] torchsummary==1.5.1
[pip3] torchtext==0.13.0a0+fae8e8c
[pip3] torchvision==0.15.0a0
[pip3] triton==2.0.0
[conda] Could not collect

@NicolasHug
Copy link
Member

NicolasHug commented May 18, 2023

I haven't looked at it in details, but try passing your custom rpn to the model builder or to the class, instead of setting it as an attribute after instantiation. It's possible that some other components of the model get first defined based on the default rpn, which is incompatible with the one you set later. Try something like this (adapt it to MaskRCNN):

>>> model = FasterRCNN(backbone,
>>> num_classes=2,
>>> rpn_anchor_generator=anchor_generator,
>>> box_roi_pool=roi_pooler)

@PandhaB
Copy link
Author

PandhaB commented May 19, 2023

Yay, thanks a lot, just changed the few precedent lines to :

from torchvision.models.detection import maskrcnn_resnet50_fpn
from torchvision.models.detection.rpn import AnchorGenerator
anchor_generator = AnchorGenerator(
                                   sizes = ((8,), (16,), (32,), (64,), (128,)),
                                   aspect_ratios = tuple([(0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10.0) for i in range (5)]))

d_mask_model = maskrcnn_resnet50_fpn(num_classes = 3,
                                     rpn_anchor_generator = anchor_generator).to('cuda')

and my learning loop starts normally. I'll keep in mind that possible further incompatibilities and set the other Mask R-CNN components using the model builder from now on ! Thanks a lot for the help ! 👍

@PandhaB PandhaB closed this as completed May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants