octiapp / KerasPersonLab

Keras-tensorflow implementation of PersonLab (https://arxiv.org/abs/1803.08225)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash on a call to cv2.warpAffine()

PavelPr opened this issue · comments

Hi!

First, thank you for your hard work!

I am trying to run training and some time after the first epoch begins, I am running into an issue where the following call (in transformer.py) fails:

masks = cv2.warpAffine(masks, M, cv_shape, flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_CONSTANT, borderValue=0)

Specifically, there is an OpenCV assertion error, stating that "error: (-215) _src.channels() <= 4 || (interpolation != INTER_LANCZOS4 && interpolation != INTER_CUBIC) in function cv::warpAffine". Could you please point me at what might be wrong here?

Thanks a lot!

N.B. Looking at the code, at first glace it would so seem that several Mats are passed into warpAffine(), is this intentional?

Hi @PavelPr , thanks for your interest.

I trained using opencv v2.4.9, which allows cubic interpolation for affine warping on an image with any number of channels. Apparently, later versions of opencv (including the current master branch) do not allow this. So, you can either step back to opencv 2.4.9 (which in my experience provides faster image resizing and is worthwhile); or remove this line from transformer.py:

masks = cv2.warpAffine(masks, M, cv_shape, flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_CONSTANT, borderValue=0)

and replace it with something like this:

out_masks = np.zeros(cv_shape[::-1]+(masks.shape[-1],))
for i in range(masks.shape[-1]):
    out_masks[:,:,i] = cv2.warpAffine(masks[:,:,i], M, cv_shape, flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_CONSTANT, borderValue=0)
masks = out_masks

That way, you're looping through the mask channels instead of warping them all at once.

Also, please pull the latest master branch to incorporate a new fix I just pushed to the data generation code.

I will give that a try! Thank you for your very quick response!