Skip to main content

How to use TensorBoard with TensorFlow 2.0 in Google Colaboratory?


Another post starts with you beautiful people!
It is quite a wonderful moment for me that many Aspiring Data Scientists like you have connected with me through my facebook page and have started their focused journey to be a Data Scientists by following my book. If you have not then I recommend to atleast visit my last post here.

In two of my previous posts we have learnt about keras and colab. In this post I am going to share with you all that TensorFlow 2.0 has been released and one quite interesting news about this release is that our beloved deep learning library keras is in built with it. Yes! You heard it right. If you know keras then using TensorFlow 2.0 library is quite easy for you. One of the interesting benefit of using TensorFlow library is it's visualization tool known as TensorBoard. In this post we are going to learn how to use TensorFlow 2.0 with MNIST dataset and then setup TensorBoard with Google Colaboratory.

Let's start this post learning by opening a new notebook in Google Colab and install TensorFlow 2.0 library as below-

This will take a minute and will install the TensorFlow 2.0 library in your notebook. After installing the library we can import this as below- 

Next, we will load the MNIST dataset from tensorflow keras library then split the dataset as training and test dataset and then we will normalize it like below- 

Now we will visualize the performance of our model in TensorBoard. For this first we will use keras.callbacks.TensorBoard function like below-
Here see the parameters we are passing in TensorBoard function./log folder is the location where tensorflow will create logs and other parameters are boolean flags with true values which allow us to visualize different types of properties in TensorBoard.

Next, we will define our sequential keras model and then compile it like below-

After compiling the model we will train and evaluate our model like below-

Our model has accuracy of 98%. Since TensorBoard runs on a server, we will learn the tricky part- how to access a localhost server from our colab notebook? For this purpose we will use ngrok. ngrok is a cross-platform application that enables developers to expose a local development server to the Internet with minimal effort. We will download ngrok like below- 

After downloading and installing ngrok in colab, we will fire up Tensorboard using ngrok like below-

Now we will start the server with ngrok like below-
Once your server is up, it will display the url like in above output cell. Copy this url and access it in a browser. You will see your TensorBoard page like below-

See the beautiful histograms showing in your board. Now explore it more by clicking on different tabs. Here I am seeing distributions and screen is like below-

If you click on the first tab- Scalars, you will see the performance of our model like below-

You can also get whole code as a notebook from this link.
That's it! with above steps you are able to setup TensorBoard with TensorFlow 2.0 in your colab notebook. We can use TensorBoard to visualize our TensorFlow graph, plot quantitative metrics about the execution of our graph, and show additional data like images that pass through it. This visualization tool is very flexible and useful so don't wait and explore as much as you can. Till then Go chase your dreams, have an awesome day, make every second count and see you later in my next post.











Comments

  1. It was really a nice article and i was really impressed by reading this, Thanks for sharing this information. Career3s provides Python training with real time experts. please go through our website once python Training

    ReplyDelete
  2. Awesome post. You Post is very informative. Thanks for Sharing.
    Data Science course in Noida

    ReplyDelete
  3. Thank for sharing this beautiful blog on Tensor board, well explained. keep sharing more like this.
    Scope of data science

    ReplyDelete

Post a Comment

Popular posts from this blog

How to deploy your ML model as Fast API?

Another post starts with you beautiful people! Thank you all for showing so much interests in my last posts about object detection and recognition using YOLOv4. I was very happy to see many aspiring data scientists have learnt from my past three posts about using YOLOv4. Today I am going to share you all a new skill to learn. Most of you have seen my post about  deploying and consuming ML models as Flask API   where we have learnt to deploy and consume a keras model with Flask API  . In this post you are going to learn a new framework-  FastAPI to deploy your model as Rest API. After completing this post you will have a new industry standard skill. What is FastAPI? FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints. It is easy to learn, fast to code and ready for production . Yes, you heard it right! Flask is not meant to be used in production but with FastAPI you can use you...

Learn the fastest way to build data apps

Another post starts with you beautiful people! I hope you have enjoyed and learned something new from my previous three posts about machine learning model deployment. In one post we have learned  How to deploy a model as FastAPI?  I n the second post, we have learned  How to deploy a deep learning model as RestAPI ? and in the third post, we have also learned  How to scale your deep learning model API?   If you are following my blog posts, you have seen how easily you have transit yourselves from aspiring to a mature data scientist. In this new post, I am going to share a new framework-  Streamlit which will help you to easily create a beautiful app with Python only. I will show here how had I used the Streamlit framework to create an app for my YOLOv3 custom model. What is Streamlit? Streamlit’s open-source app framework is the easiest way for data scientists and machine learning engineers to create beautiful, performant apps in only a few hours!...

How can I make a simple ChatBot?

Another post starts with you beautiful people! It has been a long time of posting a new post. But my friends in this period I was not sitting  where I got a chance to work with chatbot and classification related machine learning problem. So in this post I am going to share all about chatbot- from where I have learned? What I have learned? And how can you build your first bot? Quite interesting right! Chatbot is a program that can conduct an intelligent conversation based on user's input. Since chatbot is a new thing to me also, I first searched- is there any Python library available to start with this? And like always Python has helped me this time also. There is a Python library available with name as  ChatterBot   which is nothing but a machine learning conversational dialog engine. And yes that is all I want to start my learning because I always prefer inbuilt Python library to start my learning journey and once I learn this then only I move ahead for another...