Sunday, 17 December 2017

Tensorflow and AEM

It has been a while since google released Tensorflow support for java. Even though it is still in its infancy, I feel like it has everything we need. Build computation graphs - check, run session and compute stuff - check, GPU support - check. Now if you have all the time in the world to reinvent the wheel, you can pretty much build anything in java that we can build using python or c++.

So, I have been working on Adobe Experience Manager since I joined Adobe and recently, I started experimenting with several use cases where machine learning can help in content creation and discovery. As I have zero knowledge in building any deep learning models in java, I decided to build everything in java. How hard can it be? Right? Right? Sarcasm aside, as I mentioned earlier, Tensorflow for java has everything we need and as it internally uses JNI we can have interoperability with python and c++ (that's why I preferred this over deeplearning4j).

First off, I followed their official guide for the setup and had to face a lot of hurdles along the way. In this post I will show you how I managed to successfully setup Tensorflow on AEM (or any felix based systems).

Step 1

Add the dependency to your pom.xml file. Note that the scope set to compile.

Step 2

Add this configuration to your maven-bundle-plugin.

Step 3

Build and install to your AEM instance. Then, navigate to /system/console/bundles/ and look for the bundle which contains the dependency. See if the "Exported Packages" section has the following packages:

Step 4

Install JNI if necessary (this is mentioned in the link that I shared earlier).

Then place the library file in the appropriate place.


Lets write a simple sling servlet to check if everything is working as expected. Like I told earlier, Tensorflow for java is still in its infancy. So, I wrote a helper class a while back to manipulate the computation graph. Get and place it where it is accessible to the sling servlet.

The following sling servlet includes things like:
  • Creating a computation graph
  • Creating placeholders, constants etc
  • Arithmetic operations, matrix multiplication.
  • Feeding data and computing values of placeholders.

When you go to /services/tftest you should get something like this:

4 -2 3 0 FLOAT tensor with shape [3, 3] 14 Testing done!
Now you can start building any deep learning model on AEM. Also, I will be writing about some of the real life applications of deep learning in content creation and content discovery. So stay tuned!

1 comment:

  1. Did you know there's a 12 word sentence you can tell your partner... that will induce deep feelings of love and impulsive appeal to you buried inside his heart?

    Because deep inside these 12 words is a "secret signal" that fuels a man's impulse to love, cherish and look after you with his entire heart...

    12 Words Will Trigger A Man's Love Response

    This impulse is so hardwired into a man's mind that it will make him work better than before to make your relationship the best part of both of your lives.

    Matter-of-fact, triggering this dominant impulse is absolutely binding to achieving the best possible relationship with your man that once you send your man one of these "Secret Signals"...

    ...You will instantly notice him open his mind and heart to you in such a way he's never experienced before and he will see you as the only woman in the world who has ever truly fascinated him.