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

Error on Converting 300W dataset in class Landmarks300WConverter with message UFuncTypeError: Cannot cast ufunc 'subtract' output... #60

Open
nunenuh opened this issue Aug 13, 2022 · 0 comments

Comments

@nunenuh
Copy link
Contributor

nunenuh commented Aug 13, 2022

Example code

from torchlm.data import LandmarksWFLWConverter, Landmarks300WConverter
# setup your path to the original downloaded dataset from official 
converter = Landmarks300WConverter(
    data_dir="/data/extended/landmark/ibug_300W_dlib/", save_dir="/data/extended/landmark/ibug_300W_dlib/converted",
    extend=0.2, rebuild=True, target_size=256, keep_aspect=False,
    force_normalize=True, force_absolute_path=True
)
converter.convert()
converter.show(count=30)  # show you some converted images with landmarks for debugging

Error Message

Converting 300W Train Annotations:   0%|                                                                                                                                          | 0/3148 [00:00<?, ?it/s]
---------------------------------------------------------------------------
UFuncTypeError                            Traceback (most recent call last)
Input In [1], in <cell line: 8>()
      2 # setup your path to the original downloaded dataset from official 
      3 converter = Landmarks300WConverter(
      4     data_dir="/data/extended/landmark/ibug_300W_dlib//", save_dir="/data/extended/landmark/ibug_300W_dlib/converted",
      5     extend=0.2, rebuild=True, target_size=256, keep_aspect=False,
      6     force_normalize=True, force_absolute_path=True
      7 )
----> 8 converter.convert()
      9 converter.show(count=30)

File /opt/anaconda/envs/facial/lib/python3.9/site-packages/torchlm/data/_converters.py:329, in Landmarks300WConverter.convert(self)
    322 test_anno_file = open(self.save_test_annotation_path, "w")
    324 for annotation in tqdm.tqdm(
    325         self.train_annotations,
    326         colour="GREEN",
    327         desc="Converting 300W Train Annotations"
    328 ):
--> 329     crop, landmarks, new_img_name = self._process_annotation(annotation=annotation)
    330     if crop is None or landmarks is None:
    331         continue

File /opt/anaconda/envs/facial/lib/python3.9/site-packages/torchlm/data/_converters.py:493, in Landmarks300WConverter._process_annotation(self, annotation)
    491 crop = image[int(ymin):int(ymax), int(xmin):int(xmax), :]
    492 # adjust according to left-top corner
--> 493 landmarks[:, 0] -= float(xmin)
    494 landmarks[:, 1] -= float(ymin)
    496 if self.target_size is not None and self.resize_op is not None:

UFuncTypeError: Cannot cast ufunc 'subtract' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

Solution

Change this line

# adjust according to left-top corner
landmarks[:, 0] -= float(xmin)
landmarks[:, 1] -= float(ymin)

Use this line instead

# adjust according to left-top corner
landmarks[:, 0] = landmarks[:, 0] - float(xmin)
landmarks[:, 1] = landmarks[:, 1] - float(ymin)

Environment

  • conda 4.10.3
  • Python 3.9.12 (main, Jun 1 2022, 11:38:51)
  • numpy version 1.23.1
  • torch version 1.12.1
  • Operating system Ubuntu 20.04.3 LTS
@nunenuh nunenuh changed the title Error on Converting 300W dataset with Landmarks300WConverter with message UFuncTypeError: Cannot cast ufunc 'subtract' output Error on Converting 300W dataset in class Landmarks300WConverter with message UFuncTypeError: Cannot cast ufunc 'subtract' output Aug 13, 2022
@nunenuh nunenuh changed the title Error on Converting 300W dataset in class Landmarks300WConverter with message UFuncTypeError: Cannot cast ufunc 'subtract' output Error on Converting 300W dataset in class Landmarks300WConverter with message UFuncTypeError: Cannot cast ufunc 'subtract' output... Aug 13, 2022
nunenuh added a commit to nunenuh/torchlm that referenced this issue Aug 13, 2022
DefTruth added a commit that referenced this issue Aug 14, 2022
Fixing Issue #60 Error on Converting 300W dataset in class Landmarks300WConverter with message UFuncTypeError: Cannot cast ufunc 'subtract' output...
DefTruth added a commit that referenced this issue Aug 14, 2022
fix(converters): fixed error when converting dataset 300W (#60)
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

1 participant