Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: cannot reshape array #36

Closed
yueqiw opened this issue Mar 14, 2018 · 2 comments
Closed

ValueError: cannot reshape array #36

yueqiw opened this issue Mar 14, 2018 · 2 comments

Comments

@yueqiw
Copy link

yueqiw commented Mar 14, 2018

Hi,

I got the following error when running style transfer with segmentation masks.

Elapsed time in stylization: 0.003414
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
...
...
/home/yueqi/Dropbox/lib/FastPhotoStyle/process_stylization.pyc in stylization(p_wct, content_image_path, style_image_path, content_seg_path, style_seg_path, output_image_path, cuda)
     60 
     61     with Timer("Elapsed time in stylization: %f"):
---> 62         stylized_img = p_wct.transform(cont_img, styl_img, cont_seg, styl_seg)
     63     utils.save_image(stylized_img.data.cpu().float(), output_image_path, nrow=1)
     64 

/home/yueqi/Dropbox/lib/FastPhotoStyle/photo_wct.py in transform(self, cont_img, styl_img, cont_seg, styl_seg)
     33         sF4 = sF4.data.squeeze(0)
     34         cF4 = cF4.data.squeeze(0)
---> 35         csF4 = self.__feature_wct(cF4, sF4, cont_seg, styl_seg)
     36         Im4 = self.d4(csF4, cpool_idx, cpool1, cpool_idx2, cpool2, cpool_idx3, cpool3)
     37 

/home/yueqi/Dropbox/lib/FastPhotoStyle/photo_wct.py in __feature_wct(self, cont_feat, styl_feat, cont_seg, styl_seg)
     86                 if self.label_indicator[l] == 0:
     87                     continue
---> 88                 cont_mask = np.where(t_cont_seg.reshape(t_cont_seg.shape[0] * t_cont_seg.shape[1]) == l)
     89                 styl_mask = np.where(t_styl_seg.reshape(t_styl_seg.shape[0] * t_styl_seg.shape[1]) == l)
     90                 if cont_mask[0].size <= 0 or styl_mask[0].size <= 0:

ValueError: cannot reshape array of size 4128 into shape (1376,)

Fixing these two lines

t_cont_seg = np.asarray(Image.fromarray(cont_seg, mode='RGB').resize((cont_w, cont_h), Image.NEAREST))
t_styl_seg = np.asarray(Image.fromarray(styl_seg, mode='RGB').resize((styl_w, styl_h), Image.NEAREST))

to the following resolved the issue.

t_cont_seg = np.asarray(Image.fromarray(cont_seg).resize((cont_w, cont_h), Image.NEAREST))
t_styl_seg = np.asarray(Image.fromarray(styl_seg).resize((styl_w, styl_h), Image.NEAREST))
@wesleyw72
Copy link
Contributor

Hi, This is also fixed in PR #33.

@yueqiw
Copy link
Author

yueqiw commented Mar 14, 2018

Thanks! didn't notice that before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants