pca scoring: ValueError operands could not be broadcast together with shapes

67 views
Skip to first unread message

Tim Morawietz

unread,
Jan 19, 2018, 5:42:14 AM1/19/18
to bob-devel
Hi,

I'm doing some experiments using eigenface( preprocessor = 'face-detect' extractor = 'linearize' algorithm = 'pca').
I have to use face-detect instead of face-crop-eyes. If i use a very small sample seize (the same images are also present in my normal test) no errors thrown. Using all front face images available for train_world.lst a ValueError appears.  

This works: 367 Images train_world = for_models (the same amount and the same images).

(awesome-project) tim@ubuntu:~$ verify.py testdb.py
bob.bio.base@2018-01-19 09:24:18,232 -- INFO: - Preprocessing: processing 367 data files from directory '/home/tim/TimCopy/' to directory 'temp/100feret/preprocessed'
bob.bio.base@2018-01-19 09:33:55,990 -- INFO: - Extraction: extracting 367 features from directory 'temp/100feret/preprocessed' to directory 'temp/100feret/./extracted'
bob.bio.base@2018-01-19 09:33:56,196 -- INFO: - Projection: loading training data
bob.bio.base@2018-01-19 09:33:56,273 -- INFO: - Projection: training projector 'temp/100feret/./Projector.hdf5' using 367 training files: 
bob.bio.base@2018-01-19 09:33:56,276 -- INFO:   -> Training LinearMachine using PCA
bob.bio.base@2018-01-19 09:33:56,479 -- INFO:     ... Keeping 110 PCA dimensions
bob.bio.base@2018-01-19 09:33:56,494 -- INFO: - Projection: projecting 367 features from directory 'temp/100feret/./extracted' to directory 'temp/100feret/./projected'
bob.bio.base@2018-01-19 09:33:57,382 -- INFO: - Enrollment: enrolling models of group 'dev'
bob.bio.base@2018-01-19 09:33:57,510 -- INFO: - Scoring: computing scores for group 'dev'
bob.bio.base@2018-01-19 09:33:57,620 -- INFO: - Scoring: concatenating score files for group 'dev'
bob.bio.base@2018-01-19 09:33:57,652 -- INFO: - Scoring: wrote score file 'results/100feret/100feret/nonorm/scores-dev'

Error: 2722 images for train_world and 367 (who are also part of train_world) in for_models. 3089 are processed because the images in train_world are in a different subdir(that way its less time consuming to generate file lists with find and index them).
e.g        
00006/face/00006_930831_fb_a xxx     (train_world small size 367)
FrontColor/00006/00006_931230_fa xxx (train_world)

Dir tree:
myimagedir/
...
-----00006/face/...      (contains 1 identity 1-10 imgs) 
-----00007/face/...
...
-----FrontColor/...       (contains >1000 dir and in each dir 1 identity 1-10 imgs)
Can that cause problems?
(awesome-project) tim@ubuntu:~$ verify.py testdb.py
bob.bio.base@2018-01-19 08:23:59,608 -- INFO: - Preprocessing: processing 3089 data files from directory '/home/tim/TimCopy/' to directory 'temp/eudist100feret/preprocessed'
bob.bio.base@2018-01-19 08:57:39,630 -- INFO: - Extraction: extracting 3089 features from directory 'temp/eudist100feret/preprocessed' to directory 'temp/eudist100feret/./extracted'
bob.bio.base@2018-01-19 08:57:41,928 -- INFO: - Projection: loading training data
bob.bio.base@2018-01-19 08:57:42,593 -- INFO: - Projection: training projector 'temp/eudist100feret/./Projector.hdf5' using 2722 training files: 
bob.bio.base@2018-01-19 08:57:42,706 -- INFO:   -> Training LinearMachine using PCA
bob.bio.base@2018-01-19 08:57:56,584 -- INFO:     ... Keeping 311 PCA dimensions
bob.bio.base@2018-01-19 08:57:56,655 -- INFO: - Projection: projecting 3089 features from directory 'temp/eudist100feret/./extracted' to directory 'temp/eudist100feret/./projected'
bob.bio.base@2018-01-19 08:58:36,543 -- INFO: - Enrollment: enrolling models of group 'dev'
bob.bio.base@2018-01-19 08:58:36,547 -- INFO: - Scoring: computing scores for group 'dev'
bob.bio.base@2018-01-19 08:58:36,549 -- ERROR: During the execution, an exception was raised: operands could not be broadcast together with shapes (5120,) (311,) 
Traceback (most recent call last):
  File "/home/tim/miniconda3/envs/awesome-project/bin/verify.py", line 6, in <module>
    sys.exit(bob.bio.base.script.verify.main())
  File "/home/tim/miniconda3/envs/awesome-project/lib/python3.6/site-packages/bob/bio/base/script/verify.py", line 435, in main
    verify(args, command_line_parameters)
  File "/home/tim/miniconda3/envs/awesome-project/lib/python3.6/site-packages/bob/bio/base/script/verify.py", line 415, in verify
    if not execute(args):
  File "/home/tim/miniconda3/envs/awesome-project/lib/python3.6/site-packages/bob/bio/base/script/verify.py", line 336, in execute
    write_compressed = args.write_compressed_score_files)
  File "/home/tim/miniconda3/envs/awesome-project/lib/python3.6/site-packages/bob/bio/base/tools/scoring.py", line 305, in compute_scores
    _scores_a(algorithm, reader, model_ids, group, compute_zt_norm, force, write_compressed, allow_missing_files)
  File "/home/tim/miniconda3/envs/awesome-project/lib/python3.6/site-packages/bob/bio/base/tools/scoring.py", line 141, in _scores_a
    a = _scores(algorithm, reader, model, current_probe_objects, allow_missing_files)
  File "/home/tim/miniconda3/envs/awesome-project/lib/python3.6/site-packages/bob/bio/base/tools/scoring.py", line 51, in _scores
    scores[0,i] = algorithm.score(model, probe)
  File "/home/tim/miniconda3/envs/awesome-project/lib/python3.6/site-packages/bob/bio/base/algorithm/PCA.py", line 199, in score
    return self.score_for_multiple_models(model, probe)
  File "/home/tim/miniconda3/envs/awesome-project/lib/python3.6/site-packages/bob/bio/base/algorithm/Algorithm.py", line 211, in score_for_multiple_models
    return self.model_fusion_function([self.score(models[i,:], probe) for i in range(models.shape[0])])
  File "/home/tim/miniconda3/envs/awesome-project/lib/python3.6/site-packages/bob/bio/base/algorithm/Algorithm.py", line 211, in <listcomp>
    return self.model_fusion_function([self.score(models[i,:], probe) for i in range(models.shape[0])])
  File "/home/tim/miniconda3/envs/awesome-project/lib/python3.6/site-packages/bob/bio/base/algorithm/PCA.py", line 205, in score
    return self.factor * self.distance_function(model, probe)
  File "/home/tim/miniconda3/envs/awesome-project/lib/python3.6/site-packages/scipy/spatial/distance.py", line 433, in euclidean
    dist = norm(u - v)
ValueError: operands could not be broadcast together with shapes (5120,) (311,)

All images are 512x768 and saved as jpg.
My initial thought was: maybe some images are failure to enrolls. Can't be the case here as it can be seen that all images are used so passed face-detect and enrollment phase.  

Thanks,
Tim
condaenv.txt

Tim Morawietz

unread,
Jan 19, 2018, 8:02:52 AM1/19/18
to bob-devel
Hi,

Update:
I tried running it in parallel locally with jman and it has created the scores successful.
Have not changed anything file or dir related.

It's "fixed" for now.
I'll try to reproduce it and post an update if I can gather some additional information.

Thanks,
Tim   

Manuel Günther

unread,
Jan 22, 2018, 1:29:17 PM1/22/18
to bob-devel
Dear Tim,

the only thing that I can imagine is that you have run two experiments -- one with and one without PCA, or with different PCA resolutions -- and outputted temporary files into the same directory. Since files do not get overwritten when they already exist (by default), your second run did not re-compute the projected features and, hence, used the original features.

The guide should be: one experiment, one directory.

The behavior should be identical whether you run it in sequence or parallel. I assume that you used the --force option when running in parallel, so that files are actually forced to be overwritten.

Manuel
Reply all
Reply to author
Forward
0 new messages