LeslieZhoa / HeadSwap

This is a HeadSwap project not only face
MIT License
28 stars 9 forks source link

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part. #9

Closed rarahaha2 closed 3 weeks ago

rarahaha2 commented 7 months ago

Does anyone meet this problem? I've done everything before the final step and finally met this.

ValueError Traceback (most recent call last) Cell In[5], line 1 ----> 1 oup = model.run_single(src,tgt,crop_align=True,cat=True) 2 cv2.imshow("",oup)

Cell In[2], line 50 47 src_inp = self.preprocess(src_align) 48 tgt_inp = self.preprocess(tgt_align) ---> 50 tgt_params = self.get_params(cv2.resize(tgt_align,(256,256)), 51 info['rotated_lmk']/2.0).unsqueeze(0) 53 gen = self.forward(src_inp,tgt_inp,tgt_params) 55 gen = self.postprocess(gen[0])

File d:\HeadSwap\process\process_func.py:45, in Process.get_params(self, img, lmk) 43 def getparams(self,img,lmk): ---> 45 img,,crop_param = self.preprocess_params(img,lmk) 46 with torch.no_grad(): 47 coeff_3dmm = self.ParamsModel(img)

File d:\HeadSwap\process\process_func.py:73, in Process.preprocess_params(self, img, lm) 69 W,H = images.size 71 lm[:, -1] = H - 1 - lm[:, -1] ---> 73 transparams, img, lm, = align_img(images, lm, self.lm3d_std)
74 img = torch.tensor(np.array(img)/255., dtype=torch.float32).permute(2, 0, 1) ... 76 img_new, lm_new, mask_new = resize_n_crop_img(img, lm, t, s, target_size=target_size, mask=mask) ---> 77 trans_params = np.array([w0, h0, s, t[0], t[1]],dtype=np.float32) 79 return trans_params, img_new, lm_new, mask_new

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part.

rarahaha2 commented 7 months ago

The problem will not occur when using google colab. Is it the problem of different version of pytorch?

timchenxiaoyu commented 7 months ago

same err with python 3.8 and torch 2.1.2

kampelmuehler commented 6 months ago

@rarahaha2 Having this issue in colab.

kampelmuehler commented 6 months ago

You have to replace the respective line with trans_params = np.array([w0, h0, s, t[0].item(), t[1].item()],dtype=np.float32). Also you need to do this straight after cloning the repo, or at least before importing any libraries.

poinne commented 5 months ago

You have to replace the respective line with trans_params = np.array([w0, h0, s, t[0].item(), t[1].item()],dtype=np.float32). Also you need to do this straight after cloning the repo, or at least before importing any libraries.

thanks, it work

HoangDuy09042001 commented 1 month ago

trans_params = np.array([w0, h0, s, t[0].item(), t[1].item()],dtype=np.float32)

When I replaced with this line, it still appeared the same error


ValueError Traceback (most recent call last) in <cell line: 1>() ----> 1 oup = model.run_single(src,tgt,crop_align=True,cat=True) 2 cv2_imshow(oup)

3 frames /content/HeadSwap/model/third/Deep3dRec/preprocess.py in align_img(img, lm, lm3D, mask, target_size, rescale_factor) 75 # processing the image 76 img_new, lm_new, mask_new = resize_n_crop_img(img, lm, t, s, target_size=target_size, mask=mask) ---> 77 # trans_params = np.array([w0, h0, s, t[0], t[1]],dtype=np.float32) 78 trans_params = np.array([w0, h0, s, t[0].item(), t[1].item()],dtype=np.float32) 79

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part.