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

Class to predict per patch #27

Closed
wouellette opened this issue Oct 29, 2018 · 2 comments
Closed

Class to predict per patch #27

wouellette opened this issue Oct 29, 2018 · 2 comments

Comments

@wouellette
Copy link
Contributor

I worked through the python notebooks and I got it to work the way I wanted. So a big thanks for sharing it!

In the process, I thought of something which would be particularly useful, and that is a class which performs the prediction on a patch basis instead of on the reshaped raster for the entire AOI. The problem is that if the time series used is very long, and the AOI is very large, MemoryError is almost guaranteed.

I came up with this instead:

    class PredictOutput(EOTask):
        """
        The task performs the ML prediction patch-wise.
        """
        def __init__(self, model):
            self.model = model

        def execute(self, eopatch):
            feature = eopatch.data['FEATURES']
            t, w, h, f = feature.shape
            feature = np.swapaxes(feature,0,2).reshape(h*w,t*f)
            plabels = self.model.predict(feature)
            plabels = np.swapaxes(plabels.reshape(h,w),0,1)
            plabels = plabels[...,np.newaxis]
            eopatch.add_feature(FeatureType.DATA_TIMELESS, 'PRED', plabels)

            return eopatch

I do not know if you think it is worth including in the eo-learn framework, or should just be included in the notebook as a way to show how to implement patch-wise prediction. Of course, only 9 patches were predicted, so there is no real need for it in the notebook, but they are all about showcasing what eo-learn is capable of.

Regards

@wouellette wouellette changed the title Class to predict classifications per patch Class to predict per patch Oct 29, 2018
@mlubej
Copy link
Contributor

mlubej commented Oct 30, 2018

Hi @wouellette!

This was planned to be implemented, but we were pressed with time and wanted to work on this a bit later, but since you shared this code, we can already use it to update the example :)

Thanks a lot!

@mlubej
Copy link
Contributor

mlubej commented Feb 27, 2019

I added the prediction task in the LULC example, but probably this is too specific to the model and the task at hand to add it to the code, I guess (perhaps some custom code would still be needed to clean some features or idk what)

Thanks for providing a template task!

@mlubej mlubej closed this as completed Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants