nkarasiak / dzetsaka

dzetsaka : classification plugin for Qgis
GNU General Public License v3.0
80 stars 20 forks source link

plugin in gqis2 for osx doesn't recognize scikit-learn #10

Open knussear opened 6 years ago

knussear commented 6 years ago

Trying to run random forest for qgis2 on osx with your plugin. Says it needs scikit-learn. Following instructions with pip I get Requirement already satisfied: scikit-learn in ./anaconda2/lib/python2.7/site-packages

Yet the plugin doesn't recognize the installation.

nkarasiak commented 6 years ago

I never tried it on OSX. When you open QGIS, run the Python Console (https://docs.qgis.org/2.18/en/docs/user_manual/plugins/python_console.html) and enter : import sklearn Does this generate an error ? If yes, scikit learn is not well installed.

knussear commented 6 years ago

OK Had an error there. Looks like QGIS for mac includes its own python. I put a copy of sklearn in there and now it will accept random forest. Now I get an error:

Something went wrong during the training. Please make sure you respect these conditions : - Are you sure to have only integer values in your Roadi column ? - Do your shapefile and raster have the same projection ?

I have checked my shapfile - Roadi is an integer (tried versions of both integer and integer 64). Also tried cases where the values are three classes 1,2,3 , and a set where the values are two classes 0,1

Both projections are epsg 32611

Looks like the other models (Gaussian, Support Vector, etc)

Is there anything else I can try?

Ken

Nicolas Karasiak mailto:notifications@github.com April 10, 2018 at 2:11 AM

I never tried it on OSX. When you open QGIS, run the Python Console (https://docs.qgis.org/2.18/en/docs/user_manual/plugins/python_console.html) and enter : |import sklearn| Does this generate an error ? If yes, scikit learn is not well installed.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lennepkade/dzetsaka/issues/10#issuecomment-380030032, or mute the thread https://github.com/notifications/unsubscribe-auth/AC0QA4A986XPX7NsXW0hBYjqNBd-c30zks5tnHczgaJpZM4TL8fO.

nkarasiak commented 6 years ago

Hello Ken, Can you tell me what Qgis version are you using ?

Did this work when you use the sample dataset ?

I just upload a new version on Qgis repository (V2.5.3) which should be available to download asap.

PS : when you type : import scipy Did this generate an error ?

knussear commented 6 years ago

Hi Yes I'm using QGIS 2.18.15

RF works with your sample data

After upgrading the plugin on my data I get a different error when trying mine

2018-04-11T10:37:37 1 Traceback (most recent call last):

File "/Users/knussear/.qgis2/python/plugins/dzetsaka/dzetsaka.py", line 1114, in runMagic

temp.initPredict(inRaster,model,outRaster,inMask,confidenceMap,inClassifier)

File "/Users/knussear/.qgis2/python/plugins/dzetsaka/scripts/mainfunction.py", line 314, in initPredict

predictedImage=self.predict_image(inRaster,outRaster,tree,inMask,confidenceMap,-10000,SCALE=[M,m],classifier=classifier)

UnboundLocalError: local variable 'tree' referenced before assignment

Ken

Nicolas Karasiak mailto:notifications@github.com April 11, 2018 at 7:52 AM

Hello Ken, Can you tell me what Qgis version are you using ?

Did this work when you use the sample dataset https://github.com/lennepkade/dzetsaka/archive/docs.zip ?

I just upload a new version on Qgis repository (V2.5.3) which should be available to download asap.

PS : when you type : |import scipy| Did this generate an error ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lennepkade/dzetsaka/issues/10#issuecomment-380481024, or mute the thread https://github.com/notifications/unsubscribe-auth/AC0QA93pNEuDG2b0ANpuGmR-N5mDxHlkks5tnhiUgaJpZM4TL8fO.

jnederend commented 6 years ago

I'm getting a similar error on Windows 10. My setup is installed via osgeo4w.

I get the following error when testing the dzetsaka sample project.

Error loading result layer:
            Traceback (most recent call last):
              File "C:/OSGEO4~1/apps/qgis-ltr/./python/plugins\processing\gui\Postprocessing.py", line 85, in handleAlgorithmResults
                dataobjects.load(out.value, name, alg.crs,
            UnboundLocalError: local variable 'name' referenced before assignment
nkarasiak commented 6 years ago

If you tried with samples data and with RF/GMM algorithms and if it works, could you please send me a little sample of your data (shape/raster) to test it on my side ? If I can reproduce this error it will be more helpful. (mail : nicart @ gmail dot com)

Just to know, how many bands have your raster ? Does it have an alpha band ? If yes, try with removing it. Thanks.

jnederend commented 6 years ago

I successfully ran the sample data using RF and GMM from the plugin's panel. If I try to "train algorithm" from the processing toolbox, I get the above error on the sample data, and the same for my own data.

When I run my own data using the plugin's "perform the classification" button it immediately gives a python error:

Traceback (most recent call last):
              File "C:/Users/Jacob/.qgis2/python/plugins\dzetsaka\dzetsaka.py", line 1114, in runMagic
                temp.initPredict(inRaster,model,outRaster,inMask,confidenceMap,inClassifier)
              File "C:/Users/Jacob/.qgis2/python/plugins\dzetsaka\scripts\mainfunction.py", line 314, in initPredict
                predictedImage=self.predict_image(inRaster,outRaster,tree,inMask,confidenceMap,-10000,SCALE=[M,m],classifier=classifier)
            UnboundLocalError: local variable 'tree' referenced before assignment

My raster is singleband with no alpha band.

nkarasiak commented 6 years ago

I try with the sample dataset with just the first band and it goes well. For the processing toolbox (with GMM), everything worked fine under Windows 7.

Traceback (most recent call last): File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/plugins\processing\gui\Postprocessing.py", line 85, in handleAlgorithmResults dataobjects.load(out.value, name, alg.crs, UnboundLocalError: local variable 'name' referenced before assignment

Only this error, but I need to desactivate loading model/confusion matrix after algorithm has run. Error is shown but everything worked. RF/SVM/KNN are not optimized (and not planned) for raster with less than 3 bands.

jnederend commented 6 years ago

Ah I've made some rookie mistakes. I was attempting to run on temporary files to try to automate the process, and should not have chosen a non-GMM function for my NDVI rasters. The RF function works from the plugin panel using a locally-saved RGB composite.

If I train the algorithm from the processing toolbox, what should the file extension be for the model?

nkarasiak commented 6 years ago

Whatever you want. model.rf for example, or model.algo... It doesn't affect the process :)

SIGGIF commented 6 years ago

Hello, I work on Windows 7 and I'm using QGIS 2.18.13, Python 3.7. I would like to test the random forest method. I'm sorry but I can't install scikit-learn, even if I try to do the pip installed on osgeo4w-setup-x86_64.exe (explain there https://github.com/lennepkade/dzetsaka/#installation-of-scikit-learn/) and even if I enter import sklearn on Python Console. I don't understand why ? I always have the same error message when I run the classification : image Thank you for your help !

nkarasiak commented 6 years ago

Hello @SIGGIF , I just updated the how to install scikit-learn for Qgis 3. You say you use Qgis 2.18.13 with Python 3.7. But Qgis 2 is on Python 2 and Qgis 3 on Python 3. If you use Qgis 3, just check in OsGeo setup if you installed pip3, if so, just follow the howto process here : https://github.com/lennepkade/dzetsaka#installation-of-scikit-learn

vidlb commented 4 years ago

Most likely the same problem than #15, see my response