WaterKnight1998 / SemTorch

Apache License 2.0
162 stars 15 forks source link

Error training HRNet with numpy>=1.24 #14

Open Nathx opened 11 months ago

Nathx commented 11 months ago

Hi,

The numpy aliases for builtin types (e.g. np.int) have been deprecated. This breaks the instantiation of the HRNet model.

The deprecation was announced in Numpy 1.20 Release Notes and expired with version 1.24.0.

Error message running with numpy v1.24 or later:

  File "C:\Users\adm.nkiner\AppData\Local\mambaforge\envs\beam\lib\site-packages\semtorch\learner.py", line 148, in get_segmentation_learner
    model = HRNet(nclass=number_classes, backbone_name=backbone_name, pretrained=pretrained)
  File "C:\Users\adm.nkiner\AppData\Local\mambaforge\envs\beam\lib\site-packages\semtorch\models\archs\hrnet_seg.py", line 48, in __init__
    super(HRNet, self).__init__(backbone_name=self.backbone_name, nclass=self.nclass, pretrained=pretrained)
  File "C:\Users\adm.nkiner\AppData\Local\mambaforge\envs\beam\lib\site-packages\semtorch\models\archs\segbase.py", line 25, in __init__
    self.get_backbone()
  File "C:\Users\adm.nkiner\AppData\Local\mambaforge\envs\beam\lib\site-packages\semtorch\models\archs\segbase.py", line 28, in get_backbone
    self.backbone = get_segmentation_backbone(self.backbone, self.norm_layer)
  File "C:\Users\adm.nkiner\AppData\Local\mambaforge\envs\beam\lib\site-packages\semtorch\models\archs\backbones\build.py", line 72, in get_segmentation_backbone
    model = BACKBONE_REGISTRY.get(backbone)(norm_layer)
  File "C:\Users\adm.nkiner\AppData\Local\mambaforge\envs\beam\lib\site-packages\semtorch\models\archs\backbones\hrnet.py", line 697, in hrnet_w18
    model = HighResolutionNet(config=backbone_config["hrnet_w18"], norm_layer=norm_layer)
  File "C:\Users\adm.nkiner\AppData\Local\mambaforge\envs\beam\lib\site-packages\semtorch\models\archs\backbones\hrnet.py", line 312, in __init__
    self.last_inp_channels = np.int(np.sum(pre_stage_channels))
  File "C:\Users\adm.nkiner\AppData\Local\mambaforge\envs\beam\lib\site-packages\numpy\__init__.py", line 324, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`,
you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'inf'?

The suggested solution is to replace every occurence of the type aliases by the builtin function they refer to. (np.int -> int)

In the meantime downgrading to numpy<1.24 solves the issue locally.