You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to use SPy to train one model on multi images? #149
I'm new to hyperspectral image classification and find out SPy is really a useful tool. But I wonder how to use SPy to train one model on multi images, just like what usually do in RGB image classification.
A brute force way to do this would be to ravel each image and groundtruth labels so they have shape (1, N, n_bands) and (1, N), respectively. Then, concatenate them into a single flattened image of shape (1, M, <n_bands>) and groundtruth image of shape (1, M).
If you are feeling more ambitious, you could create a MultiImageIterator that wraps multiple spectral.algorithms.ImageIterator objects for an unsupervised classifier or create a MultiImageMaskIterator to wrap a list of spectral.algorithms.ImageMaskIterator objects to create a supervised classifier. It's probably not more than a dozen lines of code.
I will try out your suggestion for wrapping the ImageIterator objects. But another question is if this method is suitable for image classification algorithms such as CNN, where the image could be analyzed as batches by window sliding.
The methods I described above are iterating over pixels for training a model that does pixel-level classification. If you want to do classification of images (i.e., considering the spatial context of the spectra), then you need to load entire images (or regions of images) into memory so your convolutional layers can process the 3D data (rows, columns, & bands).
You could simply load all of the images into memory (e.g., using the load method of the SpyFile object) but if you have a large number of images, that may consume too much memory, in which case you might need to load them on-demand.
Activity
tboggs commentedon Dec 7, 2022
A brute force way to do this would be to ravel each image and groundtruth labels so they have shape
(1, N, n_bands)and(1, N), respectively. Then, concatenate them into a single flattened image of shape(1, M, <n_bands>)and groundtruth image of shape(1, M).If you are feeling more ambitious, you could create a
MultiImageIteratorthat wraps multiplespectral.algorithms.ImageIteratorobjects for an unsupervised classifier or create aMultiImageMaskIteratorto wrap a list ofspectral.algorithms.ImageMaskIteratorobjects to create a supervised classifier. It's probably not more than a dozen lines of code.Jasonwtw commentedon Dec 8, 2022
Thanks for the response.
I will try out your suggestion for wrapping the
ImageIteratorobjects. But another question is if this method is suitable for image classification algorithms such as CNN, where the image could be analyzed as batches by window sliding.tboggs commentedon Dec 9, 2022
The methods I described above are iterating over pixels for training a model that does pixel-level classification. If you want to do classification of images (i.e., considering the spatial context of the spectra), then you need to load entire images (or regions of images) into memory so your convolutional layers can process the 3D data (rows, columns, & bands).
You could simply load all of the images into memory (e.g., using the
loadmethod of theSpyFileobject) but if you have a large number of images, that may consume too much memory, in which case you might need to load them on-demand.