Shark-ML / Shark

The Shark Machine Leaning Library. See more:
http://shark-ml.github.io/Shark/
GNU Lesser General Public License v3.0
508 stars 131 forks source link

Build error with Linalg vector_expressions #225

Closed inglada closed 6 years ago

inglada commented 6 years ago

Hi,

I am recompiling some code we wrote last year using autoencoders, and the current version of Shark produces the following output:

include/shark/Models/Neurons.h:83:96: error: wrong number of template arguments (1, should be 2)
   blas::vector_unary<E, Function<typename E::value_type> > operator()(blas::vector_expression<E> const& x)const{

I am a little bit lost among the compiler messages, but I don't think this is an error in my code.

Any idea?

Thanks.

Ulfgard commented 6 years ago

what is the context? Is it on master? We are changing a whole lot there! Please compare with the current autoencoder tutorial in

https://github.com/Shark-ML/Shark/blob/master/examples/Unsupervised/AutoEncoderTutorial.tpp

inglada commented 6 years ago

Hi, We use Shark in OTB (http://www.orfeo-toolbox.org) for supervised classification (RF), clustering (k-means) and dimensionality reduction (PCA, Autoencoders). We moved from a release branch of Shark to the master branch in order to benefit from the last version of RF and this broke our Autoencoder code.

OTB is used in many different contexts for satellite remote sensing image processing (from teaching in universities and training professionals to operational production centers at CNES, the French space agency and the European Space Agency).

Most of our ML algorithms came from OpenCV, but recently we found that Shark provided a more convenient modeling of ML problems and would like to use it more often. We were not attending massive spring cleaning as this https://github.com/Shark-ML/Shark/commit/c3b98add34503e23afb82268ff64635676871f4c ;)

We have finally been able to build again our project https://gitlab.orfeo-toolbox.org/jinglada/otb/tree/update-shark-rf but we lost some features because of SparseAutoencoderError and ImpulseNoiseModel.

We don't know how to continue to follow interesting additions to Shark without having this kind of issue. What do you suggest?

Thanks.

Ulfgard commented 6 years ago

Hi,

Sorry for the inconveniences our change caused. Unfortunately, we have to adapt to technological and research progress in our everyday work. This includes a long term endeavor to make Shark GPU friendly(See the GPU branch), which required some changes in the deepest internals up to the main public interfaces.

Moreover, as Shark is developed by 1 person divided roughly as 0.8 me and 0.2 a college in Germany, every feature added must either be code-neutral, save code, or another feature must go.

In this case, I decided to get rid of the sparse autoencoders, They are replaced by a more advanced algorithm: the variational autoencoder. It works better in practice and we use it ourselves. FFNet and dedicated autoencoder classes also had to go because we can simply stack linear models.

I could offer you some help in notifying you what is planned and on our todo list. Unfortuantely, i do not see a nice way to publish a roadmap on github, otherwise i would put it there.

In turn you can tell me what you use and where we should tread carefully with our changes. Further, we can just release new versions more often, so that you can update every once in a while instead of having to follow our changes on master. I think current master (+- a fewbug-fixes) could be released right now.

Our current development goal is to able to get

https://www.tensorflow.org/versions/r1.4/get_started/mnist/pros

to run in shark on GPU. CPU already works (commits not checked in). GPU requires max-pooling kernels.

inglada commented 6 years ago

Hi, Thanks for the complete answer. Can we just replace the sparse autoencoder error function by the variational autoencoder one?

For us, it would be useful to be warned when beaking changes to the algorithms we use (RF, Kmeans, PCA, autoencoders) have API changes. We have also been surprised by the fact that you don't use a separate "develop" branch for integrating changes and keep "master" as a stable branch for releases (http://nvie.com/posts/a-successful-git-branching-model/). But now we know ;)

Other than that, we are thrilled to see Shark moving forward.

By the way, what is exactly what you want to do wrt TensorFlow? Is it reading TF trained models (as it is done in OpenCV), or replicating the CNN algorithms? What would be the benefit of coding CNNs in Shark wrt using TensorFlow's (or Caffe) C++ API?

Thanks!

Ulfgard commented 6 years ago

Hi,

wrt tensorflow, we want to be able to simply port their experiments to shark. Not all is possible, because automatic differentiation allows to do quite nifty stuff. Until recently we did not have conv-Nets. now, we do. So we should show that we get the same results.


From: inglada [notifications@github.com] Sent: Thursday, March 08, 2018 3:55 PM To: Shark-ML/Shark Cc: Oswin Krause; Comment Subject: Re: [Shark-ML/Shark] Build error with Linalg vector_expressions (#225)

Hi, Thanks for the complete answer. Can we just replace the sparse autoencoder error function by the variational autoencoder one?

For us, it would be useful to be warned when beaking changes to the algorithms we use (RF, Kmeans, PCA, autoencoders) have API changes. We have also been surprised by the fact that you don't use a separate "develop" branch for integrating changes and keep "master" as a stable branch for releases (https://wiki.orfeo-toolbox.org/index.php/Git#Workflow). But now we know ;)

Other than that, we are thrilled to see Shark moving forward.

By the way, what is exactly what you want to do wrt TensorFlow? Is it reading TF trained models (as it is done in OpenCV), or replicating the CNN algorithms? What would be the benefit of coding CNNs in Shark wrt using TensorFlow's (or Caffe) C++ API?

Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/Shark-ML/Shark/issues/225#issuecomment-371510653, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOWTBskNSbGUjSjYHBuj_eLzYyH2P0bYks5tcUZTgaJpZM4SaMwI.

inglada commented 6 years ago

On Thu 08-Mar-2018 at 19:20:46 +0100, Oswin Krause notifications@github.com wrote:

Hi,

wrt tensorflow, we want to be able to simply port their experiments to shark. Not all is possible, because automatic differentiation allows to do quite nifty stuff. Until recently we did not have conv-Nets. now, we do. So we should show that we get the same results.

This is interesting. We mostly do image classification for land cover mapping (an example using RF here http://osr-cesbio.ups-tlse.fr/~oso/ui-ol/S2_2016/layer.html) and have started evaluating CNNs with tensorflow. So we would be very interested in testing CNNs in Shark.

Is there any example code to get us started?

Thanks.


From: inglada [notifications@github.com] Sent: Thursday, March 08, 2018 3:55 PM To: Shark-ML/Shark Cc: Oswin Krause; Comment Subject: Re: [Shark-ML/Shark] Build error with Linalg vector_expressions (#225)

Hi, Thanks for the complete answer. Can we just replace the sparse autoencoder error function by the variational autoencoder one?

For us, it would be useful to be warned when beaking changes to the algorithms we use (RF, Kmeans, PCA, autoencoders) have API changes. We have also been surprised by the fact that you don't use a separate "develop" branch for integrating changes and keep "master" as a stable branch for releases (https://wiki.orfeo-toolbox.org/index.php/Git#Workflow). But now we know ;)

Other than that, we are thrilled to see Shark moving forward.

By the way, what is exactly what you want to do wrt TensorFlow? Is it reading TF trained models (as it is done in OpenCV), or replicating the CNN algorithms? What would be the benefit of coding CNNs in Shark wrt using TensorFlow's (or Caffe) C++ API?

Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/Shark-ML/Shark/issues/225#issuecomment-371510653, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOWTBskNSbGUjSjYHBuj_eLzYyH2P0bYks5tcUZTgaJpZM4SaMwI.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

Ulfgard commented 6 years ago

Hi,

Before I start, a few words of caution:

  1. This is not intended for production purposes, yet.
  2. This is still without full GPU support, as Pooling only has a naive CPU implementation so far.
  3. Even on CPU, the convolution is not well optimized.
  4. I have actually never tried it out on a real GPU, only OpenCL-CPU devices. Your GPU might burst into flames or make your Alexa laugh manically in the middle of the night.

[ ] Sign here that you understood the above :)

Everything is on the branch GPU. Deep-ML with Conv-nets https://github.com/Shark-ML/Shark/blob/GPU/examples/Supervised/MNISTForExperts.tpp

Variational Autoencoders

https://github.com/Shark-ML/Shark/blob/GPU/examples/Unsupervised/VariationalAutoencoder.tpp

difference to master: VariationalAutoencoderError has a template parameter for GPU support. (this can also run on GPU already).

For GPU support:

  1. you need OpenCL 2.0, I think. might work with earlier OpenCL versions as well.

  2. It is highly advisable to use clBLAST https://github.com/CNugteren/CLBlast

  3. In the example above, enable GPU support by

3.1 replace FloatVector ->GPUFloatVector 3.2 #include <shark/Data/DeviceSupport.h> 3.3 replace the loading of the data by LabeledData<FloatVector,unsigned int> data_cpu; importSparseData( data_cpu, argv[1] , 784 , 50); auto data = toGPU(data_cpu);

note that this is not intended for large datasets as we can not stream data to GPU but only copy the full dataset, yet. Reworkin the Data<>/LabeledData class to allow streaming is on our todo,

Ulfgard commented 6 years ago

Just to notify you: CrossEntropy is going to be changed to require another template argument for the label. This is in line with ZeroOneLoss and SquaredLoss

CrossEntropy -> CrossEntropy<unsigned int, RealVector>

Ulfgard commented 6 years ago

i will close this as this is not really an issue. We now know how to inform each other :)