Problem loading saved SVM machine

26 views
Skip to first unread message

Marta Gomez-Barrero

unread,
Nov 24, 2017, 5:28:21 AM11/24/17
to bob-devel
Hi,

I just trained an SVM machine using bob.learn.libsvm and saved it like this:

with bob.io.base.HDF5File("svm_machine.h5", 'w') as f:
machine.save(f)

Now I was trying to load it as

with bob.io.base.HDF5File("svm_machine.h5", 'r') as f:
machine = bob.learn.libsvm.Machine(f)

but got the following error:

Traceback (most recent call last):
  File "pruebas.py", line 12, in <module>
    machine = bob.learn.libsvm.Machine(f)
RuntimeError: call to HDF5 C-function H5Aopen() returned error -1. HDF5 error statck follows:
 H5Aopen() @ H5A.c+407: unable to load attribute info from object header for attribute: 'version'
 H5O_attr_open_by_name() @ H5Oattribute.c+537: can't locate attribute: 'version'

Any idea what I'm doing wrong and how I can solve it?

Thanks,
Marta

Olegs Nikisins

unread,
Nov 24, 2017, 6:06:33 AM11/24/17
to bob-devel
Hello Marta,

Once SVM machine is trained, for example, as follows:

trainer = bob.learn.libsvm.Trainer(
    machine_type=machine_type,
    kernel_type=kernel_type)
machine = trainer.train(training_data)  # train the machine

The following code for saving the SVM machine should work:

import bob.io.base
f = bob.io.base.HDF5File(projector_file, 'w')  # projector_file - the name of hdf5 file to save to
machine.save(f)  # save the machine
del f

You can load the machine from file as follows:

f = bob.io.base.HDF5File(projector_file, 'a')
machine = bob.learn.libsvm.Machine(f)
del f

Kind regards,
Olegs



Marta Gomez-Barrero

unread,
Nov 24, 2017, 6:09:00 AM11/24/17
to bob-devel
ok, problem solved quiet easily: by renaming the file to hdf5 instead of h5

Here the updated code:

with bob.io.base.HDF5File("svm_machine.hdf5", 'w') as f:
machine.save(f)

...

with bob.io.base.HDF5File("svm_machine.hdf5", 'r') as f:
machine = bob.learn.libsvm.Machine(f)

André Anjos

unread,
Nov 24, 2017, 7:58:25 AM11/24/17
to bob-...@googlegroups.com
Marta,

It surprises me that the change in filename fixes the issue as there should not be a relationship between the filename and what is saved inside.

Maybe you had a dangling file somewhere?

Anyways, I'm happy that you found a solution for this.

Cheers, A

--
-- You received this message because you are subscribed to the Google Groups bob-devel group. To post to this group, send email to bob-...@googlegroups.com. To unsubscribe from this group, send email to bob-devel+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/bob-devel or directly the project website at http://idiap.github.com/bob/
---
You received this message because you are subscribed to the Google Groups "bob-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bob-devel+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Dr. André Anjos
Idiap Research Institute
Centre du Parc - rue Marconi 19
CH-1920 Martigny, Suisse
Phone: +41 27 721 7763
Fax: +41 27 721 7712
http://andreanjos.org

Marta Gomez-Barrero

unread,
Nov 24, 2017, 9:06:41 AM11/24/17
to bob-devel
Hi,

@Olegs, thanks for the reply!

@André, yes, it surprised me A LOT, but now it's working. First I tried separating the code into two files, which it's how it's gonna work any way in the end: in one I do the training and save the machine, and in the other I read the machine and do the label prediction. I tried it with h5 and it didn't work, and then I did that naive change to hdf5 and it worked... so it may be the combination of both things? No idea

--
-- You received this message because you are subscribed to the Google Groups bob-devel group. To post to this group, send email to bob-...@googlegroups.com. To unsubscribe from this group, send email to bob-devel+...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/bob-devel or directly the project website at http://idiap.github.com/bob/

---
You received this message because you are subscribed to the Google Groups "bob-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bob-devel+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

André Anjos

unread,
Feb 15, 2018, 9:17:19 AM2/15/18
to bob-...@googlegroups.com
Hello Marta, all,

Regarding this issue, I implemented a test on bob.learn.libsvm (https://gitlab.idiap.ch/bob/bob.learn.libsvm/merge_requests/8) to check arbitrary filenames can be used to save/load SVM machines. These are now merged and will be part of the release.

From the tests on the CI, I cannot reproduce the reported problem. Saving and loading with any arbitrary extension seems to work fine.

If you can provide more information, then maybe we can figure out the reason for this error.

Best, André

--
-- You received this message because you are subscribed to the Google Groups bob-devel group. To post to this group, send email to bob-...@googlegroups.com. To unsubscribe from this group, send email to bob-devel+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/bob-devel or directly the project website at http://idiap.github.com/bob/

---
You received this message because you are subscribed to the Google Groups "bob-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bob-devel+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Dr. André Anjos
Idiap Research Institute
Centre du Parc - rue Marconi 19
CH-1920 Martigny, Suisse
Phone: +41277217763

Amir Mohammadi

unread,
Feb 15, 2018, 10:09:27 AM2/15/18
to bob-...@googlegroups.com
I have seen people recently have errors with HDF5 files when they mix different C++ ABI libraries.
If you send the output of `conda list`, maybe i can check and confirm.
running `conda install bob-devel` for now is a temporary workaround.
Reply all
Reply to author
Forward
0 new messages