ValueError: Found array with 0 sample(s) (shape=(0, 26)) while a minimum of 1 is required.

Issue #134 closed
Benjamin Jakimow created an issue
Processing algorithm…
Algorithmus Predict Classification startet…
Eingabeparameter:
{ 'classifier' : 'O:/Student_Data/Dierkes/5. Semester/Kretastudie/Bachelor arbeit/Classification/Classification_brandnew/classifier_1.pkl', 'mask' : None, 'outClassification' : 'C:/Users/dierkesh/AppData/Local/Temp/15/processing_7a7bd308edb84fc3abba7cc89e9ad365/add64518f7524ec88d608e47adef4063/outClassification.bsq', 'raster' : 'O:/Student_Data/Dierkes/5. Semester/Kretastudie/Bachelor arbeit/Classification/Classification_brandnew/phenology_2017.tif' }

start EstimatorPredict, Size(x=9000, y=4000)
Traceback (most recent call last):
File "C:/Users/dierkesh/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\provider.py", line 117, in processAlgorithm
result = self.processAlgorithm_()
File "C:/Users/dierkesh/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\algorithms.py", line 297, in processAlgorithm_
estimator.predict(filename=filename, raster=raster, mask=mask, progressBar=self._progressBar)
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 2909, in _predict
applier.apply(operatorType=_EstimatorPredict, raster=raster, estimator=self, mask=mask)
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 30, in apply
overwrite=self.kwargs.get('overwrite', True), *ufuncArgs, **ufuncKwargs)
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1003, in apply
results = self._runProcessSubgrids()
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1065, in _runProcessSubgrids
blockResults.append(_Worker.processSubgrid(**kwargs))
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1144, in processSubgrid
nxblock=nx)
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1289, in _apply
blockResult = self.ufunc(*self._ufuncArgs, **self._ufuncKwargs)
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 2956, in ufunc
y = estimator.sklEstimator().predict(X=X)
File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 538, in predict
proba = self.predict_proba(X)
File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 578, in predict_proba
X = self._validate_X_predict(X)
File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 357, in _validate_X_predict
return self.estimators_[0]._validate_X_predict(X, check_input=True)
File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\tree\tree.py", line 373, in _validate_X_predict
X = check_array(X, dtype=DTYPE, accept_sparse="csr")
File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\utils\validation.py", line 462, in check_array
context))
ValueError: Found array with 0 sample(s) (shape=(0, 26)) while a minimum of 1 is required.

Traceback (most recent call last):
File "C:/Users/dierkesh/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\provider.py", line 117, in processAlgorithm
result = self.processAlgorithm_()
File "C:/Users/dierkesh/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\algorithms.py", line 297, in processAlgorithm_
estimator.predict(filename=filename, raster=raster, mask=mask, progressBar=self._progressBar)
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 2909, in _predict
applier.apply(operatorType=_EstimatorPredict, raster=raster, estimator=self, mask=mask)
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 30, in apply
overwrite=self.kwargs.get('overwrite', True), *ufuncArgs, **ufuncKwargs)
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1003, in apply
results = self._runProcessSubgrids()
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1065, in _runProcessSubgrids
blockResults.append(_Worker.processSubgrid(**kwargs))
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1144, in processSubgrid
nxblock=nx)
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1289, in _apply
blockResult = self.ufunc(*self._ufuncArgs, **self._ufuncKwargs)
File "C:\Users\dierkesh\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 2956, in ufunc
y = estimator.sklEstimator().predict(X=X)
File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 538, in predict
proba = self.predict_proba(X)
File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 578, in predict_proba
X = self._validate_X_predict(X)
File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 357, in _validate_X_predict
return self.estimators_[0]._validate_X_predict(X, check_input=True)
File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\tree\tree.py", line 373, in _validate_X_predict
X = check_array(X, dtype=DTYPE, accept_sparse="csr")
File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\utils\validation.py", line 462, in check_array
context))
ValueError: Found array with 0 sample(s) (shape=(0, 26)) while a minimum of 1 is required.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/dierkesh/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\provider.py", line 131, in processAlgorithm
raise Exception('unexpected error')
Exception: unexpected error

Ausführung nach 1.80 Sekunden gescheitert

Lade Ergebnis Layer
Algorithmus 'Predict Classification' beendet

Comments (9)

  1. Thang Hanam

    My classification has suffered the same error.

    My training polygon includes 4 classses. I conducted the following steps for RF classification (from Enmapbox menu):
    1. Classification from vector 2. Fit RandomForestClassifier 3. Predict Classification At the 3rd step, error appeared.

    Could anyone solved this?

    Thanks!

    Algorithm 'Predict Classification' starting
    Input parameters:
    { 'classifier' : 'C:/Users/hnt7/Desktop/tam/rf2.pkl', 'mask' : None, 'outClassification' : 'C:/Users/hnt7/AppData/Local/Temp/processing_d85b44638fa94c908b59164e0dbd389d/4a60c4179b344f0e8e452d66cb2f4739/outClassification.bsq', 'raster' : 'C:/Users/hnt7/Desktop/tam/tauenvi' }
    
    start EstimatorPredict, Size(x=1369, y=1428)
    Traceback (most recent call last):
    File "C:/Users/hnt7/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\provider.py", line 117, in processAlgorithm
    result = self.processAlgorithm_()
    File "C:/Users/hnt7/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\algorithms.py", line 297, in processAlgorithm_
    estimator.predict(filename=filename, raster=raster, mask=mask, progressBar=self._progressBar)
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 2909, in _predict
    applier.apply(operatorType=_EstimatorPredict, raster=raster, estimator=self, mask=mask)
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 30, in apply
    overwrite=self.kwargs.get('overwrite', True), *ufuncArgs, **ufuncKwargs)
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1003, in apply
    results = self._runProcessSubgrids()
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1065, in _runProcessSubgrids
    blockResults.append(_Worker.processSubgrid(**kwargs))
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1144, in processSubgrid
    nxblock=nx)
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1289, in _apply
    blockResult = self.ufunc(*self._ufuncArgs, **self._ufuncKwargs)
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 2956, in ufunc
    y = estimator.sklEstimator().predict(X=X)
    File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 538, in predict
    proba = self.predict_proba(X)
    File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 578, in predict_proba
    X = self._validate_X_predict(X)
    File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 357, in _validate_X_predict
    return self.estimators_[0]._validate_X_predict(X, check_input=True)
    File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\tree\tree.py", line 373, in _validate_X_predict
    X = check_array(X, dtype=DTYPE, accept_sparse="csr")
    File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\utils\validation.py", line 462, in check_array
    context))
    ValueError: Found array with 0 sample(s) (shape=(0, 3)) while a minimum of 1 is required.
    
    Traceback (most recent call last):
    File "C:/Users/hnt7/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\provider.py", line 117, in processAlgorithm
    result = self.processAlgorithm_()
    File "C:/Users/hnt7/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\algorithms.py", line 297, in processAlgorithm_
    estimator.predict(filename=filename, raster=raster, mask=mask, progressBar=self._progressBar)
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 2909, in _predict
    applier.apply(operatorType=_EstimatorPredict, raster=raster, estimator=self, mask=mask)
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 30, in apply
    overwrite=self.kwargs.get('overwrite', True), *ufuncArgs, **ufuncKwargs)
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1003, in apply
    results = self._runProcessSubgrids()
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1065, in _runProcessSubgrids
    blockResults.append(_Worker.processSubgrid(**kwargs))
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1144, in processSubgrid
    nxblock=nx)
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubdc\applier.py", line 1289, in _apply
    blockResult = self.ufunc(*self._ufuncArgs, **self._ufuncKwargs)
    File "C:\Users\hnt7\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\enmapboxplugin\site-packages\hubflow\core.py", line 2956, in ufunc
    y = estimator.sklEstimator().predict(X=X)
    File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 538, in predict
    proba = self.predict_proba(X)
    File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 578, in predict_proba
    X = self._validate_X_predict(X)
    File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\ensemble\forest.py", line 357, in _validate_X_predict
    return self.estimators_[0]._validate_X_predict(X, check_input=True)
    File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\tree\tree.py", line 373, in _validate_X_predict
    X = check_array(X, dtype=DTYPE, accept_sparse="csr")
    File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site-packages\sklearn\utils\validation.py", line 462, in check_array
    context))
    ValueError: Found array with 0 sample(s) (shape=(0, 3)) while a minimum of 1 is required.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
    File "C:/Users/hnt7/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxgeoalgorithms\provider.py", line 131, in processAlgorithm
    raise Exception('unexpected error')
    Exception: unexpected error
    
    Execution failed after 0.52 seconds
    
    Loading resulting layers
    Algorithm 'Predict Classification' finished
    
  2. Benjamin Jakimow reporter

    @janzandr the error can be reproduced with:

    #see https://bitbucket.org/hu-geomatics/enmap-box/issues/134/valueerror-found-array-with-0-sample-s
    
    pathClassifier = r'O:\Student_Data\Dierkes\5. Semester\Kretastudie\Bachelor arbeit\Classification\Classification_brandnew\classifier.pkl'
    pathImage = r'O:\Student_Data\Dierkes\5. Semester\Kretastudie\Bachelorarbeit\Classification\Classification_brandnew\phenology_2016_testBJ.vrt'
    pathDst = r'F:\Temp\Henrike\class.tif'
    
    
    import pickle
    from hubflow.core import FlowObject, Classifier, Estimator, Raster, ApplierOutputRaster, Applier
    
    f = open(pathClassifier, 'rb')
    classifier = pickle.load(file=f)
    f.close()
    assert isinstance(classifier, Classifier)
    classifier.predict(filename=pathDst, raster=Raster(filename=pathImage))
    
  3. Benjamin Jakimow reporter

    @janzandr it looks like the code in hubflow\core.py lines 2952ff does not consider that entire tiles might be masked / filled with data ignore values.

            prediction = self.full(value=noDataValues, bands=noutputs, dtype=dtype)
    
            valid = self.maskFromArray(array=self.features, noDataValueSource='raster')
            valid *= self.flowMaskArray('mask', mask=mask)
    
            X = np.float64(self.features[:, valid[0]].T)
            y = estimator.sklEstimator().predict(X=X) #here it fails!
    

    The sklearn prediction could be skipped with testing for "np.any(valid)" first.

  4. Thang Hanam

    I already updated to ther version on August 2nd but the error still exist.

    I tested a similar dataset of raster image and ROI in Enmapbox IDL (2.1) and Enmapbox 3 (in QGIS) for random forest classification. The IDL version just worked well whilst QGIS plugin caused the same error:

    ValueError: Found array with 0 sample(s) (shape=(0, 4)) while a minimum of 1 is required.
    

    Is it due to the python code of the plugin?

    Thanks.

  5. Benjamin Jakimow reporter

    @hnthang Until the piece of code described above is fixed, a possible workaround might be * to use an image without masked areas or * to increase the tile size to ensure that each tile has at least some valid / not-masked pixels

  6. Thang Hanam

    Thank you. Updated version of EnMap-Box solved the issue. Now RF can be implemented without error.

  7. Log in to comment