hukenovs / easyportrait

EasyPortrait - Face Parsing and Portrait Segmentation Dataset
https://arxiv.org/abs/2304.13509
185 stars 16 forks source link

Few Tips and Swift Core ML version. #22

Open john-rocky opened 5 months ago

john-rocky commented 5 months ago

Thank you for the great project.

3Tips for users of the pretrained models.

Tips0

Installation method that worked successfully

git clone https://github.com/hukenovs/easyportrait.git
cd easyportrait/pipelines/
pip install torch==1.13.1 torchvision==0.14.1
pip install -U openmim
mim install mmengine
mim install mmcv==1.7.1
mim install mmcv-full==1.7.1
pip install mmsegmentation==0.30.0
pip install ftfy

Tips1:

If you change line 281 of formatting.py, it will run smoothly.

# img_meta[key] = results[key]
img_meta[key] = results.get(key,None)

Tips2:

When plotting the results, set palette to None to plot the results.

show_result_pyplot(
   model,
   img,
   result,
   None,
   opacity=1,
   out_file=out)

Swift/iOS version

I converted segformer512fp to Core ML ( Swift / iOS format ).

https://github.com/john-rocky/easyportrait-coreml

And made Swift demo.

https://github.com/john-rocky/CoreML-Models?tab=readme-ov-file#easyportrait

Jan-18-2024 20-51-05

Thanks again!

hradec commented 4 months ago

Thank you Thank you Thank you!!!

A couple more tips for others:


Tips3:

if you see this error:

File "./pipelines/demo/image_demo.py", line 40, in main
get_palette(args.palette),
File "/root/miniconda3/envs/easyportrait/lib/python3.8/site-packages/mmseg/core/evaluation/class_names.py", line 324, in get_palette
raise ValueError(f'Unrecognized dataset: {dataset}')
ValueError: Unrecognized dataset: easy_portrait

Set the pipelines folder of this depot to the top of your PYTHONPATH, for example:

export PYTHONPATH=./pipelines:$PYTHONPATH

This depot has a copy of the mmseg python module source in the pipelines folder, that was modified to include the easy_portrait palette, so python needs to load this local copy of mmseg instead of the one installed.


Tips4:

If you get an AssertionError like this:

File "pipelines/mmseg/models/segmentors/base.py", line 267, in show_result
    assert palette.shape[0] == len(self.CLASSES)
AssertionError

just add a # to the start of the line 267 of pipelines/mmseg/models/segmentors/base.py and it should run:

266         palette = np.array(palette)
267 #        assert palette.shape[0] == len(self.CLASSES)
268         assert palette.shape[1] == 3
269         assert len(palette.shape) == 2
270         assert 0 < opacity <= 1.0
kleinsbotle commented 3 months ago

Hi, Thank you for sharing great tips!