10 Kg in 100 Days

This blog post is rather different from the usual AI/ML blogs I am writing about. This is more about Ketogenic Diet for weight loss.

[Inspired by Fat to Fit Amir Khan for Dangal]

Keto what ???

I got to know about Keto-Diet from a friend who used to weigh more than a 100 Kgs in college but now when I met him after ~10 years he looks like ~70Kgs. So I asked him what is the catch and he told me about the keto diet. I had never heard about the keto diet before so I thought he must be eating a lot of fruits, salads and other boring stuff which I know I can never follow for long period. But I was like :O when he told me that its about eating low carbs and high fat. So one can eat all the good spicy stuff like Non-Veg, Paneer and keep loosing weight.

I could not believe him, at first, but then I thought whats the harm in trying. On the contrary, I would love to eat such food all the time if I need not worry about my body-weight. So, I started exploring food items which are low in carbs and high in fat and proteins.

But then I realized that that most food-items which we consume in daily-diet in India are full on carbs. Going on Keto-Diet, religiously, means to cut all potato, rice, chapati from the daily diet which we eat almost daily in India. As a necessary requirement of Keto, one has to restrict carbs intake to 15~20 grams/ day. But one chapati alone contains about 25 grams of carbs. So one has to be very careful about what to eat and what not to. And in India it becomes even more difficult to find such food items.

keto-diet-food-to-eat

The picture above summarizes almost everything I eat when on Keto diet except some items like Ham, Pork which are not commonly available in India.

What I eat

My daily routine is: Eggs (Omelette or scrambled) in breakfast (8 am) with tea or coffee (without any sugar), have a glass of lassie around 11 am with cheese slice, then Paneer or Chicken curry for lunch and vice versa for dinner.

How I cook

I usually eat home cooked food so I had better control over which oil to use and I add cooking-cream to increase the fat intake. Sometimes I do add flakes of Tuna fish which can be bought in canned form at supermarkets.

Among vegetables, Onion-Tomato fried with spices and cooking cream is used to make curry and then cubes of Paneer or Chicken pieces can be added later. I do also add some other vegetables like Cauliflower or Cabbage or Capsicum, Carrot, Peas to the curry. Sometimes, I have Paneer with Pumpkin (Kaddu) or Brinjal (Baingan Bharta). Cheese is good to be added as topping.

I have also tried the butter-coffee with coconut oil or ghee with salt-less butter. I can not say for sure but its good to have and seems to be working for reducing the belly fat.

The key thing is to keep rotating among different recipes otherwise it becomes difficult to have the same meals in daily routine.

Results

After the first two weeks, I observed a loss of 2 Kgs which was very motivating for me. It takes a great deal of time, money and efforts to prepare all the food myself and it was good to see such positive results. I was 80. something Kgs when I started Keto diet and in about 100 days I was 70. something. The workout for me is just a casual evening or morning walk. I go for a 30 min. swim 2-3 days in a week which I do not think is a very hard workout.

Initially, I did feel some side-effects of Keto like constipation and weakness but nothing very odd. The effects disappeared after few weeks.

Why it works

For many of over-weight people, the body stores up all the fat while consuming only the carbohydrates. When one is on Keto diet, the body do not get any carbohydrates and so turns to burning fat for energy. Hence body weight reduces when fat is consumed by body.

Cholesterol Levels

It is common belief that eating high fat and fried food will cause increase in cholesterol levels. After some 6 months of Keto diet, I took a blood test and found all cholesterol levels as normal.

 

 

 

 

Install OpenCV-Contrib-Python on Ubuntu 14.04

download

This post will show you how to install opencv-python with contrib modules on Ubuntu 14.04 which is the default OS for most Ubuntu servers on AWS or Aliyun. This problem will struck you when you are ready to deploy your OpenCV apps on a server but you can not install latest opencv-python contrib module. Also, it will leave you hopeless because you will not receive any proper error messages when you try to install using convention method.

Most conventional way of installing OpenCV is via pipsudo pip install opencv-contrib-python. Visit here for more details. But this will work only for the latest Python 2.7. 12 (or higher) and Python 3 versions. By default Ubuntu 14.04 comes with old Python 2.7.6 which is not the best to install the latest opencv-contrib-python module.

To install opencv-contrib-python via pip on Ubuntu 14, first we have to upgrade Python to latest i.e. 2.7.14 (at the time of writing this blog-post). Follow these steps to upgrade Python to latest 2.7 version:

sudo add-apt-repository ppa:jonathonf/python-2.7
sudo apt-get update
sudo apt-get install python2.7
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py

To confirm Python is upgraded just switch to the Python console in your Ubuntu Terminal and it should show Python 2.7.14 or whatever is the latest at that time:

~ python
Python 2.7.14 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

 

Now you can install the opencv-contrib-python package using the command:

sudo pip install opencv-contrib-python
sudo apt update && apt install -y libsm6 libxext6

 

To confirm OpenCV installation switch back to Python console and try to import opencv package:

~ python
Python 2.7.14 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
>>> '3.4.3'

If you see the latest version of OpenCV then it should be correctly installed. To confirm installation of the contrib module try to create an object for SIFT:

>>> sift = cv2.xfeatures2d.SIFT_create()
>>>

If you do not see any errors then the contrib module is installed properly.

A commonly occurring error message is:

cv2.error: OpenCV(3.4.3) /io/opencv_contrib/modules/xfeatures2d/src/sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is pa
tented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'

This is because in the latest version of opencv-contrib-python 3.4.3.18 the environment variable OPENCV_ENABLE_NONFREE_CMake is not set properly. You can escape this by installing OpenCV 3.4.2 instead of the latest 3.4.3 because otherwise you will have to build OpenCV 3.4.3 from scratch which is a long and tedious process. To install some other version than the latest use following command:

$ sudo pip install opencv-contrib-python==3.4.2.17

This should resole the issue with the contrib module.

Tensorflow-FaceDetection-Multithreading

This blog post is about how to run fast face detection using Tensorflow FaceNet MTCNN for video frames on CPU. Refer to my repository for the code and requirements.

face_det_multithread

[Note: The displayed FPS somehow is always more than double of the actual FPS]

Here I will try to explain key things about how multi-threading helps in speeding up Face Detection for video frames. Usually, the following pseudo-code is used for face detection:


while True:

  frame = video_source.getFrame()  // get new frame from the video source

  faces = faceDetector(frame)         // get boxes of pixels for faces detected

  drawFaces(frame, faces)              // draw boxes on the frame

  show(frame)                                  // show frame on screen

At face detection step, a face detection model detects and locate boxes of pixels in frame where a face is likely to be present. To do this, the whole frame is processed which is a time taking step which blocks the execution of rest of the code making it slow and causing the display to stuck at one frame until face detection step is completed.

With Multi-threading, the face detection processing is de-coupled from the main process and it will not block the main process anymore. The pseudo-code below shows how to implement multi-threading to removing blocking calls:


worker(frame):

  return faceDetector(frame)

input_queue = Queue(n)         // define input queue to store inputs to worker threads

output_queue = Queue()

for i in range(1, N):      //N depends upon system hardware configuration

  t = Thread(target = worker, args = (input_queue, output_queue))

  t.start()

while True:

  frame = video_source.getNextFrame()

  input_queue.push(frame)     //add current frame to input queue

  if output_queue.empty():      //do nothing if output queue is empty

    continue

  else:

    faces = output_queue.pop()

    drawFaces(faces, frame)

  show(frame)

Here a worker method is defined which takes input as a single frame and returns boxes of faces detected for the input frame. Now this worker method is run in a separate thread so in the video loop, every time a new frame comes it is added to the input queue which will call worker method for the latest frame in the queue and the output faces will be stored in a separate output queue. This way the main loop is not blocked until a face output is available. If the output queue is empty it will just continue showing the current frame and as soon as some faces are detected these will be sent to the output queue and will be displayed on the current frame.

While this way a near-real time speed is achieved, but this is not real time as the face detected for an Nth frame will be displayed over some (N+M)th frame where M depends upon time taken by the face detector to complete face detection processing. Thus, in case the face is moving too fast, the boxes drawn for the face will appear not correct. For slow movements everything will appear to be fine.

Darknet – Yolo – Python

This blog post is about how to use original Darknet-Yolo library in Python2/3 for Object Detection in video frames. There is a script provided by original authors to run Darknet Yolo library in Python2/3 but it works only on single image read from file.

screen_shot_2018-03-24_at_10-48-42_pm

[Source: https://pjreddie.com/darknet/yolo/]

But what if someone wants to run on video frames from webcam or video file? I have provided an extension of original script which works on video frames as well for object detection. Refer to my repository for the script.

There are several Python wrappers available for Darknet-Yolo but I am not sure if they works as efficiently as directly using the darknet build in terms of speed and accuracy.

To run this script follow the steps:

  1. Clone original Darknet-Yolo repository and build as per instructions given by original authors.
  2. Once successfully build, a libdarknet.so will be created. Copy the .so file to your project folder or give its path in my script.
  3. I am assuming you already have trained weights or you may use pre-trained weights available at Darknet-Yolo website. Another requirement is to install OpenCV for Python. It can be easily installed using  pip install opencv-contrib-python
  4. Give path to darknet build .so file, yolo config file (.cfg), yolo weights file and video source in my python script and run it to see the magic of Darknet Yolo in Python.

First encounter with the middle east: Truly global experience

I work for a Danish engineering consultancy firm on a project by Govt. of Qatar in city of Doha. My team consists of a Pakistani team leader, a British Senior Engineer, a Draftsman from Phillipines and myself as an Engineer from India. The Project is headed by a Canadian Manager. Not just my office but this part of the world is full of people from different nationalities. This is a mini-world in itself.

After more than an year long stay at home, I got an opportunity to get out of the country and this one was much awaited. I was expecting it since few months but this opportunity knocked suddenly and the timing could not have been worse. It was a nice Tuesday and I had just began to adjust with the week with a mild viral fever. I was thinking of taking an off but little did I know that my boss is going to surprise me. I got an email from him that I have to leave for Doha office in Qatar as there is urgent requirement there for a project. By the evening, I came to know that I have to catch a Thursday early morning flight by Qatar Airways. I had one day to pack my bags for a 2-3 weeks stay and I had no clue what awaits for me there. Also, the mild viral fever got worse on Wednesday and I could not have even taken the day off because I had to deal with all the administrative paper work on the same day for my transfer to Doha.

2013-07-12 12.21.24 2013-07-12 17.33.142013-07-12 17.39.32

After a long sleepless night and smooth 3-4 hrs flight, I reached my destination and set my feet on what the world call as the Middle East for the first time. It was hot as hell with dry hot winds blowing at my face. Soon I entered the terminal building to get cooled down by the air-conditioning. This is the standard way of living in most of the Middle East urban cities. All the buildings even the elevators, bathrooms, toilets everything is air-conditioned. On streets, people can be found taking a nap inside their cars (mostly SUVs) with Air-Conditioning turned on.

DSCN3995 DSCN3993 DSCN3998 DSCN4000 DSCN4002

I reached the apartment that company booked for my stay and on my way I found wide roads with nicely designed medians with planted desert trees. I am a civil engineer by profession and so such things get my attention easily. It seems to be a well planned city as far as roads are concerned. The roads are another aspect of the middle east cities as they are full of rich people who love to drive expensive cars and so the one thing they really care about are the roads so that they can enjoy fast driving in their Porches,  Ferrari and SUVs. Every day on my way to office, I get to see cars like Audi, Camry, Accord, BMW, Land Cruiser and 10 other parked. The level of car brands can be estimated by the fact that every taxi is a Camry here. The drivers here are mostly Indians, Bengladeshi, Pakistani, Filipinos.

Heisenberg’s Principle: Uncertainty in Position and Time

After spending 5 years in a row at the same place for my college education I was full of energy and waiting to explore the outside world. And as I was feeling I exploded like a bomb and got scattered everywhere. For about 3 years just after my graduation,  there has not been a place where I could stay for more than 4 months in a row 😛

That is what exactly Sir Heisenberg said about a high energy sub-atomic particle whose exact location and velocity can not be known at the same time. Felt exactly the same moving from one city to another hopping jobs as time goes by.

9, June 2009 – 20 Aug 2009 : Magarpatta city, Pune

21 Aug 2009 – 1 Jan 2010: Somewhere on Solapur highway, Pune

1 Jan 2010 – 15 march 2010: Magarpatta city, Pune

15 march 2010 – 11 Aug 2010: Delhi ~ Gurgaon

12 Aug 2010 – 1 Nov 2010: Mumbai ~ Pune ~ Goa

1 Nov – 27 Nov 2010: Delhi

27 Nov 2010 – 15 Dec 2010: Lausanne, Switzerland

15 Dec 2010 – 1 April 2011: Renens, Switzerland

1 April – 20 April 2011: Renens ~ Lausanne, Switzerland

20 April 2011 – 31 October 2011: Lausanne, Switzerland

1 November 2011 – 25 February 2012: St. Sulpice, Switzerland

After living this wild nomad life for so long time, I decided to stay put at Home Sweet Home and recharge my batteries 🙂

26 February 2012 — Present day: Delhi ~ Gurgaon

Meanwhile I plan for the next adventure, I shall rest and spend time with my family.