ykdai / BasicPBC

Official Implementation of "Learning Inclusion Matching for Animation Paint Bucket Colorization"
Other
233 stars 23 forks source link

Error with --seg_type trappedball #12

Closed nathanshipley closed 4 months ago

nathanshipley commented 5 months ago

Thanks for your previous help! I've managed to get the previous commit working, but it didn't do well for my particular animation because the lines aren't closed. I've pulled the latest and tried --seg_type trappedball as suggested but I'm getting the following error now:

Any ideas?

(basicpbc) nathan@nathan-ThinkStation-P620:~/AI/code/27_Basic_PBC_Paint/BasicPBC$ python inference_line_frames.py --path dataset/test/your_data/trinity02 \
        --save_color_seg \
        --seg_type trappedball

dataset/test/your_data/trinity02/seg/0000.png created.
Traceback (most recent call last):
  File "/home/nathan/AI/code/27_Basic_PBC_Paint/BasicPBC/inference_line_frames.py", line 114, in <module>
    generate_seg(path, seg_type, radius, save_color_seg, multi_clip)
  File "/home/nathan/AI/code/27_Basic_PBC_Paint/BasicPBC/inference_line_frames.py", line 78, in generate_seg
    trappedball_fill(line_path, seg_color_path, radius, contour=True)
  File "/home/nathan/AI/code/27_Basic_PBC_Paint/BasicPBC/paint/lineart.py", line 148, in trappedball_fill
    fill = trapped_ball_fill_multi(result, radius, method="max")
  File "/home/nathan/AI/code/27_Basic_PBC_Paint/BasicPBC/linefiller/linefiller/trappedball_fill.py", line 115, in trapped_ball_fill_multi
    area_size_filter = np.max(filled_area_size)
  File "/home/nathan/anaconda3/envs/basicpbc/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 2810, in max
    return _wrapreduction(a, np.maximum, 'max', axis, None, out,
  File "/home/nathan/anaconda3/envs/basicpbc/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 88, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
ValueError: zero-size array to reduction operation maximum which has no identity
ykdai commented 5 months ago

We did not meet this error before, and this error seems to come from the np.max() function. Do you mind share your data (first two or three frames are quite enough) with us and I will test it for you. My e-mail address is 'ydai005@e.ntu.edu.sg'

nathanshipley commented 5 months ago

Thank you. Sent!

ykdai commented 5 months ago

Thank you so much for your data. I find that this error occurs because we extract the line based on the RGB value rather than the alpha value. I have preprocessed the data for you and sent it to you through e-mail. We are going to update our repository to support your previous data soon (Maybe tomorrow).

Besides, I notice that our current segmentation method cannot function very well. We are trying to fix it in our recent update. Please stay tuned : )

Thank you again for your support.

JinAnReji commented 4 months ago

Greeting, thank you guys for this amazing project.

I am running into a different but similar array shape ValueError when running option --seg_type trappedball on my test data, too. When I try to run this option on the given testdata laughing_girl, the error also happened.

The command I ran: python inference_line_frames.py --path dataset/test/laughing_girl --use_light_model --seg_type trappedball --save_color_seg

The error message I got:

C:\Users\user\anaconda3\envs\PBC\Lib\site-packages\torchvision\io\image.py:13: UserWarning: Failed to load image Python extension: '[WinError 127] 找不到指定的程序。'If you don't plan on using image functionality from `torchvision.io`, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have `libjpeg` or `libpng` installed before building `torchvision` from source?
  warn(
Traceback (most recent call last):
  File "C:\Users\user\Documents\BasicPBC\inference_line_frames.py", line 186, in <module>
    generate_seg(path, seg_type, radius, save_color_seg, multi_clip)
  File "C:\Users\user\Documents\BasicPBC\inference_line_frames.py", line 142, in generate_seg
    extract_seg_from_color(seg_color_path, line_path, seg_path)
  File "C:\Users\user\Documents\BasicPBC\inference_line_frames.py", line 41, in extract_seg_from_color
    color_label.extract_label_map(color_img_path, seg_save_path, line_path, extract_seg=True)
  File "C:\Users\user\DocumentsBasicPBC\paint\colorlabel.py", line 163, in extract_label_map
    img[region_mask] = [0, 0, 0, 255]
    ~~~^^^^^^^^^^^^^
ValueError: shape mismatch: value array of shape (4,) could not be broadcast to indexing result of shape (1,3)

Perhaps this is also a current segmentation method issue?

Note: I've modified the source code a little bit to eliminate cuda-related errors and a numpy-dtype-related error (may due to numpy version, I am using numpy 1.26.4), and that's all. Non of the modification I made seem to directedly related to this shape mismatch ValueError.

My environment: anaconda3, Win11, Python 3.11.9

All I've modified:

# line 211 in inference_line_frames.py
# model = model.cuda() # command this temparary to test on Notebook PC

# line 571 in basicpbc_arch.py
state_dict = torch.load(args["ckpt"], map_location=torch.device('cpu')) # add cpu mapping for local PC test

# line 152 in inference_line_frames.py
full_model = torch.load(model_path, map_location=torch.device('cpu')) # add cpu

# line 150 in basicpbc_light_arch.py
state_dict = torch.load(args["ckpt"], map_location=torch.device('cpu')) # add cpu

# around line 273 and 230 in pbc_model.py
match_tensor = self.model(test_data) # for local cpu test

# line 207 in linefiller/trappedball_fill.py
result = np.zeros(image.shape[:2], np.int8) # AttributeError: module 'numpy' has no attribute 'int'.
ykdai commented 4 months ago

@JinAnReji Sorry for replying late. However, I cannot reproduce this error. Maybe you can test it using our google colab script: https://colab.research.google.com/drive/1kJKLdFXY0O6jRxQCYS4xjaEcOTu7sLPu?usp=sharing

JinAnReji commented 4 months ago

@JinAnReji Sorry for replying late. However, I cannot reproduce this error. Maybe you can test it using our google colab script: https://colab.research.google.com/drive/1kJKLdFXY0O6jRxQCYS4xjaEcOTu7sLPu?usp=sharing

Thank you for the reply.
Actually I ended up changing my environment into python 3.9.12, with pytorch 1.12.1, then everything works fine now. I guess my problem was resulted from some version issues.

'd love trying the colab script, best.