irfanICMLL / structure_knowledge_distillation

The official code for the paper 'Structured Knowledge Distillation for Semantic Segmentation'. (CVPR 2019 ORAL) and extension to other tasks.
BSD 2-Clause "Simplified" License
694 stars 104 forks source link

How can I run build.py in pytorch1.9? #63

Closed BBBBchan closed 2 years ago

BBBBchan commented 2 years ago

When I run python build.py to build the native CUDA implementation of InPlace-ABN, I got this error message:

Traceback (most recent call last):
  File "build.py", line 3, in <module>
    from torch.utils.ffi import create_extension
  File "/home/bbchan/anaconda3/envs/pytorch19/lib/python3.7/site-packages/torch/utils/ffi/__init__.py", line 1, in <module>
    raise ImportError("torch.utils.ffi is deprecated. Please use cpp extensions instead.")

I consider that I got this error due to different pytorch version. I run this command in pytorch1,9 and torch.utils.ffi is deprecated. So I change the bulid.py file:

import os

# from torch.utils.ffi import create_extension
from torch.utils.cpp_extension import BuildExtension

sources = ['src/lib_cffi.cpp']
headers = ['src/lib_cffi.h']
extra_objects = ['src/bn.o']
with_cuda = True

this_file = os.path.dirname(os.path.realpath(__file__))
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]

ffi = BuildExtension(
    '_ext',
    headers=headers,
    sources=sources,
    relative_to=__file__,
    with_cuda=with_cuda,
    extra_objects=extra_objects,
    extra_compile_args=["-std=c++14"]
)

if __name__ == '__main__':
    ffi.build()

However, when I run python build.py command again, I got this error message:

Traceback (most recent call last):
  File "/home/disk/structure_knowledge_distillation/libs/build.py", line 21, in <module>
    extra_compile_args=["-std=c++14"]
  File "/home/anaconda3/envs/pytorch19/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 361, in __init__
    super(BuildExtension, self).__init__(*args, **kwargs)
  File "/home/anaconda3/envs/pytorch19/lib/python3.7/site-packages/setuptools/__init__.py", line 172, in __init__
    _Command.__init__(self, dist)
  File "/home/anaconda3/envs/pytorch19/lib/python3.7/distutils/cmd.py", line 57, in __init__
    raise TypeError("dist must be a Distribution instance")
TypeError: dist must be a Distribution instance

I consider this error is due to the higher pytorch version too. How can I modify the build.py file to get rid of this problem?

My environment: python 3.7 pytorch 1.9 cuda 11.1

GeneralJing commented 2 years ago

+1. same question.

BBBBchan commented 2 years ago

I have solved this. The build.py is used to build InplaceABN in kd_model.py, so I just replaced InplaceABN with official implement https://github.com/mapillary/inplace_abn. In this way, we don't need build.py and can run the project in pytorch1.9.1. In my condition, this works well and can get similar performance in paper.

GeneralJing commented 2 years ago

through pip install inplace-abn, i can use import inplace-abn. but how to import inplace_abn_sync? This doesn't seem to work. How do you do it?

GeneralJing commented 2 years ago

can you give me some specific operation?

BBBBchan commented 2 years ago

through pip install inplace-abn, i can use import inplace-abn. but how to import inplace_abn_sync? This doesn't seem to work. How do you do it?

Well, you can just from inplace_abn import InPlaceABNSync. BatchNorm2d = functools.partial(InPlaceABNSync, activation='identity')

GeneralJing commented 2 years ago

thank you. I will try that.

Liuhao-128 commented 2 years ago

Could you give a more detail operation about how to deal with :TypeError: dist must be a Distribution instance, and how to put the inplace-abn? i don't understand, I have pip install inplace-abn, thanks!

Liuhao-128 commented 2 years ago

I also has an error --ModuleNotFoundError: No module named 'libs._ext.__ext' QQ图片20220324110736 )

xuyuxiu83 commented 1 month ago

thank you. I will try that.

Hi, the website provided by the author for downloading the weight files is currently inaccessible, so I'm unable to download the weights. Could you please share the weight files with me? My email is xuyuxiu83@gmail.com.

xuyuxiu83 commented 1 month ago

activation='identity'

hello,I cannot enter the website of the pretrained model now.Could you please share it with me?My email is xuyuxiu83@gmail.com.