The MegEngine implementation of BiSeNet.
pip install -r requirements.txt
If you don't want to compare the ouput error between the MegEngine implementation and PyTorch one, just ignore requirements.txt and install MegEngine from the command line:
python3 -m pip install --upgrade pip
python3 -m pip install megengine -f https://megengine.org.cn/whl/mge.html
Convert trained weights from torch to megengine, the converted weights will be saved in ./pretained/ , you need to specify the convert model architecture and path to checkpoint offered by official repo.
python convert_weights.py -m cityscapes-bisenetv1 -c /path/to/ckpt --num-classes 19
Use python compare.py
.
By default, the compare script will convert the torch state_dict to the format that megengine need.
If you want to compare the error by checkpoints, you neet load them manually.
Import from megengine.hub:
Way 1:
from megengine import hub
modelhub = hub.import_module(
repo_info='asthestarsfalll/BiSeNet-MegEngine:main', git_host='github.com')
# custom you own BiSeNet
bisenet = modelhub.BiSeNetV1(n_classes=150)
# load pretrained model
pretrained_model = modelhub.bisenetv1(pretrained=True)
Way 2:
from megengine import hub
# load pretrained model
model_name = 'bisenetv1'
pretrained_model = hub.load(
repo_info='asthestarsfalll/BiSeNet-MegEngine:main', entry=model_name, git_host='github.com', pretrained=True)
For those models which do not have pretrained model online, you need to convert weights mannaly, and load the model without pretrained weights like this:
model = modelhub.bisenetv1()
# or
model_name = 'bisenetv1'
model = hub.load(
repo_info='asthestarsfalll/BiSeNet-MegEngine:main', entry=model_name, git_host='github.com')
- add BiSeNet v2