Loading a PyML multiclass classifier... why isn't this working?
- by Michael Aaron Safyan
This is a followup from "Save PyML.classifiers.multi.OneAgainstRest(SVM()) object?". I am using PyML for a computer vision project (pyimgattr), and have been having trouble storing/loading a multiclass classifier. When attempting to load one of the SVMs in a composite classifier, with loadSVM, I am getting:
ValueError: invalid literal for float(): rest
Note that this does not happen with the first classifier that I load, only with the second. What is causing this error, and what can I do to get around this so that I can properly load the classifier?
Details
To better understand the trouble I'm running into, you may want to look at pyimgattr.py (currently revision 11). I am invoking the program with "./pyimgattr.py train" which trains the classifier (invokes train on line 571, which trains the classifier with trainmulticlassclassifier on line 490 and saves it with storemulticlassclassifier on line 529), and then invoking the program with "./pyimgattr.py test" which loads the classifier in order to test it with the testing dataset (invokes test on line 628, which invokes loadmulticlassclassifier on line 549).
The multiclass classifier consists of several one-against-rest SVMs which are saved individually. The loadmulticlassclassifier function loads these individually by calling loadSVM() on several different files. It is in this call to loadSVM (done indirectly in loadclassifier on line 517) that I get an error. The first of the one-against-rest classifiers loads successfully, but the second one does not. A transcript is as follows:
$ ./pyimgattr.py test
[INFO] pyimgattr -- Loading attributes from "classifiers/attributes.lst"...
[INFO] pyimgattr -- Loading classnames from "classifiers/classnames.lst"...
[INFO] pyimgattr -- Loading dataset "attribute_data/apascal_test.txt"...
[INFO] pyimgattr -- Loaded dataset "attribute_data/apascal_test.txt".
[INFO] pyimgattr -- Loading multiclass classifier from "classifiers/classnames_from_attributes"...
[INFO] pyimgattr -- Constructing object into which to store loaded data...
[INFO] pyimgattr -- Loading manifest data...
[INFO] pyimgattr -- Loading classifier from "classifiers/classnames_from_attributes/aeroplane.svm"....
scanned 100 patterns
scanned 200 patterns
read 100 patterns
read 200 patterns
{'50': 38, '60': 45, '61': 46, '62': 47, '49': 37, '52': 39, '53': 40, '24': 16, '25': 17, '26': 18, '27': 19, '20': 12, '21': 13, '22': 14, '23': 15, '46': 34, '47': 35, '28': 20, '29': 21, '40': 32, '41': 33, '1': 1, '0': 0, '3': 3, '2': 2, '5': 5, '4': 4, '7': 7, '6': 6, '8': 8, '58': 44, '39': 31, '38': 30, '15': 9, '48': 36, '16': 10, '19': 11, '32': 24, '31': 23, '30': 22, '37': 29, '36': 28, '35': 27, '34': 26, '33': 25, '55': 42, '54': 41, '57': 43}
read 250 patterns
in LinearSparseSVModel
done LinearSparseSVModel
constructed model
[INFO] pyimgattr -- Loaded classifier from "classifiers/classnames_from_attributes/aeroplane.svm".
[INFO] pyimgattr -- Loading classifier from "classifiers/classnames_from_attributes/bicycle.svm"....
label at None
delimiter ,
Traceback (most recent call last):
File "./pyimgattr.py", line 797, in
sys.exit(main(sys.argv));
File "./pyimgattr.py", line 782, in main
return test(attributes_file,classnames_file,testing_annotations_file,testing_dataset_path,classifiers_path,logger);
File "./pyimgattr.py", line 635, in test
multiclass_classnames_from_attributes_classifier = loadmulticlassclassifier(classnames_from_attributes_folder,logger);
File "./pyimgattr.py", line 529, in loadmulticlassclassifier
classifiers.append(loadclassifier(os.path.join(filename,label+".svm"),logger));
File "./pyimgattr.py", line 502, in loadclassifier
result=loadSVM(filename,datasetClass = SparseDataSet);
File "/Library/Python/2.6/site-packages/PyML/classifiers/svm.py", line 328, in loadSVM
data = datasetClass(fileName, **args)
File "/Library/Python/2.6/site-packages/PyML/containers/vectorDatasets.py", line 224, in __init__
BaseVectorDataSet.__init__(self, arg, **args)
File "/Library/Python/2.6/site-packages/PyML/containers/baseDatasets.py", line 214, in __init__
self.constructFromFile(arg, **args)
File "/Library/Python/2.6/site-packages/PyML/containers/baseDatasets.py", line 243, in constructFromFile
for x in parser :
File "/Library/Python/2.6/site-packages/PyML/containers/parsers.py", line 426, in next
x = [float(token) for token in tokens[self._first:self._last]]
ValueError: invalid literal for float(): rest