menpo / menpofit

Menpo's 2D deformable modelling toolkit (AAMs/CLMs/SDMs)
http://www.menpo.org
Other
128 stars 63 forks source link

Training failed with ValueError: could not broadcast input array from shape (14444) into shape (43332) #114

Open nwatab opened 6 years ago

nwatab commented 6 years ago

I followed Menpofit basic tutorial but it threw an error.

I also tried following things but ended to the same result.

Executed Jupyter notebook is below:

Input 1

import menpo.io as mio
path_to_images = '/home/myname/work/data/LFPW/trainset/'
training_images = mio.import_images(path_to_images, verbose=True)

Output 1 Found 811 assets, index the returned LazyList to import.

Input 2

from menpofit.aam import HolisticAAM
from menpofit.aam import PatchAAM
from menpo.feature import igo

aam = HolisticAAM(training_images, reference_shape=None,
                  diagonal=150, scales=(0.9, 1.0),
                  holistic_features=igo, verbose=True,
                  batch_size=16
                 )
print(aam)

Output 2

- Computing reference shape                                                     Computing batch 0
- Building modelsges size: [==========] 100% (16/16) - done.                    
  - Scale 0: Computing feature space: [          ] 6% (1/16) - 00:00:00 remaining

/home/myname/.pyenv/versions/anaconda3-5.2.0/envs/menpo/lib/python3.5/site-packages/menpofit/aam/base.py:164: MenpoFitBuilderWarning: No reference shape was provided. The mean of the first batch will be the reference shape. If the batch mean is not representative of the true mean, this may cause issues.
  MenpoFitBuilderWarning)

  - Scale 0: Doneding appearance model                                          ing
  - Scale 1: Building shape model                                               

/home/myname/.pyenv/versions/anaconda3-5.2.0/envs/menpo/lib/python3.5/site-packages/menpofit/builder.py:338: MenpoFitModelBuilderWarning: The reference shape passed is not a TriMesh or subclass and therefore the reference frame (mask) will be calculated via a Delaunay triangulation. This may cause small triangles and thus suboptimal warps.
  MenpoFitModelBuilderWarning)
/home/myname/.pyenv/versions/anaconda3-5.2.0/envs/menpo/lib/python3.5/site-packages/menpo/image/boolean.py:711: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  copy.pixels[slices].flat = point_in_pointcloud(pointcloud, indices)

  - Scale 1: Doneding appearance model                                          
                                                              Computing batch 1
- Building modelsges size: [==========] 100% (16/16) - done.                    
  - Scale 0: Doneding appearance model                                          ning
  - Scale 1: Doneding appearance model                                          
                                                              Computing batch 2
- Building modelsges size: [==========] 100% (16/16) - done.                    
  - Scale 0: Doneding appearance model                                          ing
  - Scale 1: Doneding appearance model                                          
                                                              Computing batch 3
- Building modelsges size: [==========] 100% (16/16) - done.                    
  - Scale 0: Doneding appearance model                                          ing
  - Scale 1: Doneding appearance model                                          
                                                              Computing batch 4
- Building modelsges size: [==========] 100% (16/16) - done.                    
  - Scale 0: Doneding appearance model                                          ing
  - Scale 1: Doneding appearance model                                          
                                                              Computing batch 5
- Building modelsges size: [==========] 100% (16/16) - done.                    
  - Scale 0: Doneding appearance model                                          ning
  - Scale 1: Doneding appearance model                                          
                                                              Computing batch 6
- Building modelsges size: [==========] 100% (16/16) - done.                    
  - Scale 0: Doneding appearance model                                          ing
  - Scale 1: Doneding appearance model                                          
                                                              Computing batch 7
- Building modelsges size: [==========] 100% (16/16) - done.                    
  - Scale 0: Doneding appearance model                                          ing
  - Scale 1: Doneding appearance model                                          
                                                              Computing batch 8
- Building modelsges size: [==========] 100% (16/16) - done.                    
  - Scale 0: Doneding appearance model                                          ing
  - Scale 1: Doneding appearance model                                          
                                                              Computing batch 9
- Building modelsges size: [==========] 100% (16/16) - done.                    
  - Scale 0: Doneding appearance model                                          ing
  - Scale 1: Doneding appearance model                                          
                                                              Computing batch 10
- Building modelsges size: [==========] 100% (16/16) - done.                    
  - Scale 0: Building appearance model                                          ning

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-40-c5f48712ecae> in <module>()
      6                   diagonal=150, scales=(0.9, 1.0),
      7                   holistic_features=igo, verbose=True,
----> 8                   batch_size=16
      9                  )
     10 print(aam)

~/.pyenv/versions/anaconda3-5.2.0/envs/menpo/lib/python3.5/site-packages/menpofit/aam/base.py in __init__(self, images, group, holistic_features, reference_shape, diagonal, scales, transform, shape_model_cls, max_shape_components, max_appearance_components, verbose, batch_size)
    137         # Train AAM
    138         self._train(images, increment=False, group=group, verbose=verbose,
--> 139                     batch_size=batch_size)
    140 
    141     def _train(self, images, increment=False, group=None,

~/.pyenv/versions/anaconda3-5.2.0/envs/menpo/lib/python3.5/site-packages/menpofit/aam/base.py in _train(self, images, increment, group, shape_forgetting_factor, appearance_forgetting_factor, verbose, batch_size)
    181                 shape_forgetting_factor=shape_forgetting_factor,
    182                 appearance_forgetting_factor=appearance_forgetting_factor,
--> 183                 verbose=verbose)
    184 
    185     def _train_batch(self, image_batch, increment=False, group=None,

~/.pyenv/versions/anaconda3-5.2.0/envs/menpo/lib/python3.5/site-packages/menpofit/aam/base.py in _train_batch(self, image_batch, increment, group, verbose, shape_forgetting_factor, appearance_forgetting_factor)
    267                 self.appearance_models[j].increment(
    268                     warped_images,
--> 269                     forgetting_factor=appearance_forgetting_factor)
    270                 # trim appearance model if required
    271                 if self.max_appearance_components[j] is not None:

~/.pyenv/versions/anaconda3-5.2.0/envs/menpo/lib/python3.5/site-packages/menpo/model/pca.py in increment(self, samples, n_samples, forgetting_factor, verbose)
   1426         """
   1427         # build a data matrix from the new samples
-> 1428         data = as_matrix(samples, length=n_samples, verbose=verbose)
   1429         n_new_samples = data.shape[0]
   1430         PCAVectorModel.increment(self, data, n_samples=n_new_samples,

~/.pyenv/versions/anaconda3-5.2.0/envs/menpo/lib/python3.5/site-packages/menpo/math/linalg.py in as_matrix(vectorizables, length, return_template, verbose)
    151     i = 0
    152     for i, sample in enumerate(vectorizables, 1):
--> 153         data[i] = sample.as_vector()
    154 
    155     # we have exhausted the iterable, but did we get enough items?

ValueError: could not broadcast input array from shape (14444) into shape (43332)

PS.

visualize_images(training_images)

also failed with

AttributeError: module 'matplotlib.colors' has no attribute 'to_rgba'

, and it couldn't be addressed, which might also help to find the cause of this issue.

patricksnape commented 5 years ago

Is the mean of the first 16 images actually a sensible reference frame? Can you try creating the reference frame from all the shapes instead?