Giter Site home page Giter Site logo

structuredforests's Introduction

StructuredForests

Version 1.1

Updates:

  • Use compression to reduce model size.
  • Rewrite the histogram function by Cython to accelerate detection.
  • Finetune some parameters to slightly improve accuracy.

It seems the libjpeg package installed by Anaconda has some bugs in decoding images. The decoding result is different from the one outputted by Matlab's imread. Thus if you used Anaconda, you may consider uninstalling libjpeg and re-installing it by apt-get (for Ubuntu).

Version 1.0

A Python Implementation for Piotr's ICCV Paper "Structured Forests for Fast Edge Detection". The performance is almost the same as Piotr's original (Matlab) implementation (On BSDS500, Piotr's: [ODS=0.738, OIS=0.758, AP=0.795, R50=0.923], mine: [ODS=0.739, OIS=0.759, AP=0.796, R50=0.924]).

For the original implementation, please check the author's webpage: http://research.microsoft.com/en-us/um/people/larryz/publications.htm .

How to use

  • Platform: Ubuntu 14.04 + Anaconda is highly recommended. Nevertheless, I don't use any platform-dependent API. Hence the codes should work on Windows / Mac OS X as well. The only problem is related to Cython: it may not be easy to setup 64-bit Cython correctly on Windows, according to my previous experience ╮(╯▽╰)╭.

  • Toy Demo: A very small dataset "toy" was provided. You can run the code via "python StructureForests.py". This command will do the following things:

    • Extract 20,000 features from the training data, and save them in "model/data";
    • Train 8 decision trees on the above features, and save them in "model/trees";
    • Merge trees to build the final model, and save it in "model/forests".
    • Use the trained model to detect edges for the testing data, and save them in "edges".
    • Note: Currently a model trained on the BSDS500 dataset is provided. If you don't remove it, only the last step of the above will be executed. Just for reference, on my machine the performance on "toy" is [ODS=0.771, OIS=0.781, AP=0.843, R50=0.936], if this model is used.
  • Actual Usage:

    • You can use the provided model for prediction. If you want to train the model by yourself, remove the provided model and keep reading.
    • Download the BSDS500 dataset from http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/, and uncompress it. As a result, a directory named "BSR" is obtained, containing BSDS500, bench, and documentation.
    • Modify the bottom two lines in "StructuredForests.py" to: model.train(bsds500_train("BSR")) and bsds500_test("BSR", "edges"). That is, use the "BSR" dataset as input, instead of the "toy" dataset.
    • Also modify the model parameters, i.e., "n_pos" and "n_neg" in "StructuredForests.py" to 500,000. That is, use 1,000,000 features in total for training (the same as Piotr's ICCV paper).
    • Train and test the model via "python StructuredForests.py". On my machine, about 12 GB memory is required for training.

What is missing

  • Multi-scale detection. However, implementing it should only require several lines of codes.
  • Speed. I didn't strive for speed. The current implementation is slower than the author's Matlab version, since only one thread is used, and there is no stochastic optimization like SSE. Nonetheless, the speed is acceptable: for BSDS500, detection requires about 1.0s per testing image; training requires about 11 hours.
  • Depth images. I never tried the NYU depth dataset.

License

I took some C++ codes from Piotr's original implementation. Those codes are licensed as the author required (see the author's webpage).

For other codes, they are licensed under the BSD License.

structuredforests's People

Contributors

artaniscv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

structuredforests's Issues

Error:image not found

Hi!
Thanks for showing your code. I'm trying to run the StructureForests.py, but I have received this:
Traceback (most recent call last):
File "/Users/zhuzihao/anaconda3/python.app/Contents/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
runfile('/Users/zhuzihao/Desktop/StructuredForests/StructuredForests.py', wdir='/Users/zhuzihao/Desktop/StructuredForests')
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/zhuzihao/Desktop/StructuredForests/StructuredForests.py", line 5, in
import tables
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/zhuzihao/anaconda3/python.app/Contents/lib/python3.6/site-packages/tables/init.py", line 131, in
from .file import File, open_file, copy_file
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/zhuzihao/anaconda3/python.app/Contents/lib/python3.6/site-packages/tables/file.py", line 32, in
import numexpr
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/zhuzihao/anaconda3/python.app/Contents/lib/python3.6/site-packages/numexpr/init.py", line 38, in
from numexpr.expressions import E
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/zhuzihao/anaconda3/python.app/Contents/lib/python3.6/site-packages/numexpr/expressions.py", line 49, in
from numexpr import interpreter
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: dlopen(/Users/zhuzihao/anaconda3/python.app/Contents/lib/python3.6/site-packages/numexpr/interpreter.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libmkl_rt.dylib
Referenced from: /Users/zhuzihao/anaconda3/python.app/Contents/lib/python3.6/site-packages/numexpr/interpreter.cpython-36m-darwin.so
Reason: image not found

I don't know how to do next.

My Environment:
Python 3.6.8
Pycharm 2019.1.3
Mac OS Mojave 10.14.6

Trained model ported to yml is not compatible with pDollar implementation existing on <opencv2/ximgproc.hpp>

Hello,

I run the example from Opencv implementation https://docs.opencv.org/3.1.0/d0/da5/tutorial_ximgproc_prediction.html , with the model I provided in this repo (StructuredForests/model/forests/forest.h5) . For that, I created a python code to convert forests in h5 format to yml https://github.com/spacerober/foresth5toyml/blob/master/storeYaml.ipynb, which is correctly parsed by detectEdges function, but the result of detected edges is not correct.

Expected result:
pdollar

Obtained result:
ArtanisCV

I found out that in yml there exist: childs (cids), featureIds (fids), thresholds (thrs), edgeBoundaries (edge_bnds), edgeBins (?)

Does edge_pts calculation in ArtavisCV's implementation differ from edgeBins calculation in pDollar's implementation?

Is there any tool to convert forests in h5 to yml?

where is the evaluate.py

thanks for the code sharing, but i don't find any evaluating code like ODS, OIS, AP. Could you share the related contents?
Much appreciated!

invalid conversion from ‘__pyx_t_14_RandomForests_INT32* {aka long int*}’ to ‘const int*’

.pyxbld/temp.linux-i686-2.7/pyrex/_RandomForests.cpp:2112:861: error: invalid conversion from ‘__pyx_t_14_RandomForests_INT32* {aka long int*}’ to ‘const int*’ [-fpermissive]
 der.diminfo[1].strides))), __pyx_t_16, __pyx_v_fid, __pyx_v_thr, __pyx_v_gain);
                                                                              ^
In file included from .pyxbld/temp.linux-i686-2.7/pyrex/_RandomForests.cpp:451:0:
./_random_forests.h:3:6: note:   initializing argument 5 of ‘void forestFindThr(int, int, int, const float*, const int*, const float*, const int*, int, int&, float&, double&)’
 void forestFindThr(int H, int N, int F, const float *data, const int *hs,
      ^
.pyxbld/temp.linux-i686-2.7/pyrex/_RandomForests.cpp:2112:861: error: invalid conversion from ‘__pyx_t_14_RandomForests_INT32* {aka long int*}’ to ‘const int*’ [-fpermissive]
 der.diminfo[1].strides))), __pyx_t_16, __pyx_v_fid, __pyx_v_thr, __pyx_v_gain);

I have tried to run the example code but encounter the following error

Using the library externally is very difficult

I've been trying to use the model with my own set of images but every time I call the code from an external location, it tries to recompile itself and fails. I can only get it to work from within the directory.

I also tried creating my own StructuredForest from the base class but that also hasn't worked so far for the same reason.

any ideas?

ImportError: Building module _RandomForests failed?

when going to run, it gives the following error:
ImportError: Building module _RandomForests failed: ["distutils.errors.CompileError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.20.27508\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2\n"]

My environment:
python 3.7
Windows 10

error: no matching function for call to 'forestFindThr'

When I run python StructuredForests.py , it shows this:

.pyxbld/temp.macosx-10.13-intel-2.7/pyrex/_RandomForests.cpp:2315:5: error: no
      matching function for call to 'forestFindThr'
    forestFindThr(__pyx_t_3, __pyx_v_N, __pyx_v_F, (&(*__Pyx_BufPtrStrid...

What's wrong? @ArtanisCV

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.