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

GaussianClassifier fails with TransformedImage object #49

Closed
tboggs opened this issue Jun 18, 2016 · 0 comments
Closed

GaussianClassifier fails with TransformedImage object #49

tboggs opened this issue Jun 18, 2016 · 0 comments
Labels
Milestone

Comments

@tboggs
Copy link
Member

tboggs commented Jun 18, 2016

When a GaussianClassifier is created and the classify_image method is called on a TransformedImage object, and AttributeError is raised because the object does not have a reshape method (classify_image is expecting a numpy.ndarray object). The exception can be reproduced as follows:

>>> from spectral import *
>>> img = open_image('92AV3C.lan')
>>> gt = open_image('92AV3GT.GIS').read_band(0)
>>> data = img.load()
>>> pc = principal_components(data)
>>> pc_0999 = pc.reduce(fraction=0.999)
>>> img_pc = pc_0999.transform(img)
>>> classes = create_training_classes(img_pc, gt)
>>> gmlc = GaussianClassifier(classes)
>>> clmap = gmlc.classify_image(img_pc)
AttributeError                            Traceback (most recent call last)
<ipython-input-11-6488a72f9e73> in <module>()
----> 1 clmap = gmlc.classify_image(img_pc)
/home/thomas/src/spectral/spectral/algorithms/classifiers.pyc in classify_image(self, image)
    200         status.display_percentage('Processing...')
    201         shape = image.shape
--> 202         image = image.reshape(-1, shape[-1])
    203         scores = np.empty((image.shape[0], len(self.classes)), np.float64)
    204         delta = np.empty_like(image, dtype=np.float64)

AttributeError: 'TransformedImage' object has no attribute 'reshape'

This will also occur with the MahalanobisDistanceClassifier. The bug can be avoided by using the load method of the TransformedImage object (img_pc in the example above) to load the data into an ndarray (if sufficient memory is available). This bug will be fixed by using the parent class method Classifier.classify_image when the argument is not an ndarray.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant