TFLearn vs Keras: Which One Should You Use?

  Programming

Using the TensorFlow framework directly is a lot of hard work. Its API is extremely verbose and prone to subtle, hard-to-catch bugs. The framework, in general, has a very steep learning curve too. That’s probably why many developers today prefer using third-party wrapper frameworks over it, which offer higher-level and more intuitive APIs. The most widely-used ones among them are TFLearn and Keras. Both do get the job done, and are extremely easy to learn. The code you write in them too tends to be very concise. So which one should you use? Well, I’ll try to answer that in this article. Note that this is only my opinion, based on my own experiences.

  • I prefer TFLearn because it allows me to use Python arrays directly. Keras needs NumPy arrays. If you’re already familiar with NumPy this is not a big deal, but if you aren’t that’s one more library you need to install and learn.

  • I prefer TFLearn because it lets me save my models as checkpoint, index, and meta files. I can use those files to create a frozen version of my model quite easily. By the way, frozen models are very important if you want to be able to use them in your Android apps or C++ programs. Keras, on the other hand, saves its models as HDF5 files, using which requires new skills again. Additionally, for it to work you must manually install the h5py library first.

  • I prefer TFLearn because its API is closer to that of TensorFlow. At any point, I can quickly switch from writing TFLearn code to TensorFlow code, and I won’t face any problems. Keras, however, is not as close to TensorFlow. Its API, for the most part, is quite opaque and at a very high level. So opaque that you could replace TensorFlow with other machine-learning frameworks such as Theano and Microsoft CNTK, with almost no changes to your code. This may be a good thing if you want to be able to switch frameworks at will, but I’ve never had to do that. Note, however, that Keras does allow you to get access to the TensorFlow session.

  • I prefer TFLearn because it seems to offer slightly better performance than Keras. For most of my requirements, the difference is quite miniscule, but it may be a factor in the future.

Conclusion

Now, as you might have guessed, I prefer TFLearn as my go-to framework for creating neural networks. But, you must know that Keras is an older and a much more popular library. It also has a lot of updates very regularly. TFLearn too does see updates regularly, but not as many. I mean, as I write this, I see that TFLearn was last updated 7 days ago, and Keras was last updated 2 hours ago.

And, most importantly, Keras(or a part of it?) is now included in TensorFlow as the tf.keras module. So, for long term projects, going with Keras might be a better idea. What do you think?

If you found this article useful, please share it with your friends and colleagues!