Monday, December 31, 2018

My 2018 in unordered lists

Places explored and loved:

  • Goa
  • Gokarna
  • Home
  • Delhi
  • Udaipur
  • Ooty
  • Surat, Bilimora
  • Mumbai
  • Halebeedu, Belur

All the books read:


Books loved and cherished:

  • When breath becomes air
  • Robot visions
  • The buried giant
  • The Hundred-Year-Old Man Who Climbed Out of the Window and Disappeared
  • Nation

Languages explored:

  • Node.js
  • Octave
  • Python
  • Tensorflow.js
  • Solidity
  • React.js

Things learnt/started:

  • Learnt and used Deep Learning
  • Made super cool Rest APIs
  • Unleashed the power of ORMs
  • Started exploring Ethereum
  • Published an online class
  • Wrote tech blogs (kind of) for the first time
  • Took boxing classes
  • Took Zumba classes
  • Practised Yoga  more often

Mistakes made:

  • Watched too many nonsensical reality shows
  • Didn't get into crypto soon enough
  • Postponed personal projects
  • Didn't learn about containers

Wednesday, November 14, 2018

Review: Death Note Box Set

Death Note Box Set Death Note Box Set by Tsugumi Ohba
My rating: 4 of 5 stars

The book is a masterpiece and I would love to give it five stars but I cannot overlook the fact that in the span of twelve books, no two named female characters have a conversation that's not about men, i.e., this series fails the bechdel test.

View all my reviews

Thursday, September 27, 2018

Review: The Guernsey Literary and Potato Peel Pie Society

The Guernsey Literary and Potato Peel Pie Society The Guernsey Literary and Potato Peel Pie Society by Mary Ann Shaffer
My rating: 5 of 5 stars

I thoroughly enjoyed reading this book. Yes, the characters are too black and white, yes the plot isn't much of a plot, and yes, the World War II cannot be felt, however, this a perfect book when you're home alone and sick in bed :)
And why can we not like perfect characters?! I absolutely love letters and this book gave me so many of them.

View all my reviews

Wednesday, September 26, 2018

Review: Robot Visions

Robot Visions Robot Visions by Isaac Asimov
My rating: 5 of 5 stars



View all my reviews

Review: Brave New World

Brave New World Brave New World by Aldous Huxley
My rating: 4 of 5 stars

In this Brave New World, society wants one to be happy. Happy by any means, by conditioning one to be satisfied by menial jobs, easy sex, meaningless lives... In case one doesn't agree, he/she is removed from society or ridiculed till they commit suicide... not quite different from the world today.

Makes me wonder what people sent away do? I would like to think it's something like 'Atlas Shrugged'.

View all my reviews

Monday, July 23, 2018

Using MobileNet with TensorFlow.js

What?

We are going to build an image classifier with MobileNet in TensorFlow js from scratch (installing python included)

Why?

I wanted to learn how to use a pre-trained model in javascript.

How?

Find complete code here and demo

Installing Python and TensorFlow

Follow this https://www.tensorflow.org/install/install_windows for windows installation.
  1. Download python 3.5 or 3.6. Version 3.7 will NOT work out as of July 2018. It doesn't download tensorflow js (henceforth referred to as tfjs)
  2. Run pip3 install --upgrade tensorflow (for CPU only)
    Or 
    pip3 install --upgrade tensorflow-gpu (for GPU)

Convert MobileNet model to tfjs model

  1. Get the MobileNet model from here
  2. This model is in tensorflow and needs to be converted to a tfjs model. Refer https://github.com/tensorflow/tfjs-converter

    tensorflowjs_converter \
        --input_format=tf_frozen_model \
        --output_node_names='MobilenetV1/Predictions/Reshape_1' \
        --saved_model_tags=serve \
        F:/image/image-
        classifier/mobilenet_v1_1.0_224/mobilenet_v1_1.0_224_frozen.pb \
        F:/image/image-classifier/modelv1
    

Load the frozen model

I use GitHub as a fast and dirty way to host static files. Upload your model to a GitHub repository and use the raw path in your code.

const MODEL_URL =
  "https://raw.githubusercontent.com/shivangidas/image-
  classifier/master/modelv1/tensorflowjs_model.pb";
const WEIGHTS_URL =
  "https://raw.githubusercontent.com/shivangidas/image-
  classifier/master/modelv1/weights_manifest.json";
let model;
(async () => {
  model = await tf.loadFrozenModel(MODEL_URL, WEIGHTS_URL);
})();

Get ImageNet classes

ImageNet Dataset has 1000 classes. You can read more here.

let IMAGENET_CLASSES = [];
$.getJSON(
    "https://raw.githubusercontent.com/shivangidas/image-
     classifier/master/mobilenet/imagenet_classes.json",
    function(data) {
      $.each(data, function(key, val) {
        IMAGENET_CLASSES.push(val);
      });
    }
  );

Make Predictions

  1. We get the image from the image tag. Refer full code for image selection part.
    let imageData = document.getElementById("imageSrc");
  2. Make tensor from the image using tfjs inbuilt function fromPixels()
    Resize the tensor to 224x224 and make the datatype float.
    The MobileNet version we are using (MobileNet_v1_1.0_224) takes an input of size [batchSize,224,224, 3]
  3. let pixels = tf.fromPixels(imageData)
                   .resizeNearestNeighbor([224, 224])
                   .toFloat();
  4. Normalize tensors to values between -1 and 1. Add a dimension as we have just one image to predict, no batch.
    let offset = tf.scalar(128);
    pixels = pixels.sub(offset).div(offset).expandDims();
  5. Call predict on the tensor
    const output = await model.predict(pixels);
  6. We get probabilities of 1000 classes.
    Sort and map to the classes we imported at the beginning.
    Here we are showing the top ten classes.

    const predictions = Array.from(output.dataSync())
                           .map(function(p, i) {
                              return {
                                probabilty: p,
                                classname: IMAGENET_CLASSES[i]
                              };
                           })
                           .sort((a, b) => b.probabilty - a.probabilty)
                           .slice(0, 10);
    
    console.log(predictions);
Putting it together:

let offset = tf.scalar(128);
let imageData = document.getElementById("imageSrc");
let pixels = tf.fromPixels(imageData)
               .resizeNearestNeighbor([224, 224])
               .toFloat();

pixels = pixels.sub(offset).div(offset).expandDims();
      
const output = await model.predict(pixels);
const predictions = Array.from(output.dataSync())
                         .map(function(p, i) {
                          return {
                            probabilty: p,
                            classname: IMAGENET_CLASSES[i]
                          };
                       })
                       .sort((a, b) => b.probabilty - a.probabilty)
                       .slice(0, 10);

console.log(predictions);

That's it!

Well not really. We are making 7 extra tensors that we need to dispose to prevent a memory leak. That means the tensors created will persist in GPU and take up space. I went to great lengths to dispose of them individually but if you come up with a better solution (maybe using tidy), do let me know.

References

All the links above

Sunday, July 22, 2018

Review: George's Secret Key to the Universe

George's Secret Key to the Universe George's Secret Key to the Universe by Lucy Hawking
My rating: 5 of 5 stars

I thoroughly enjoyed this adventure.
Reading such children's books as an adult makes me wish I had them when I was kid, too. I know my past self would have loved it.

View all my reviews

Sunday, July 1, 2018

Review: The Buried Giant

The Buried Giant The Buried Giant by Kazuo Ishiguro
My rating: 5 of 5 stars

There was a dragon and there were Knights and Warriors. There was love and hatred and revenge. And there were Boatmen and an old couple.

View all my reviews

Thursday, June 21, 2018

How to install Ubuntu

As seen on Windows 10 (now Ubuntu)


What?

This is the story of the time I installed Linux / Ubuntu (and lost all my pictures and also my Windows Operating System)


Why?

Windows was occupying a lot of space and not letting me do cool stuff. And what exactly is it updating every week?! Also I thought somehow Ubuntu would allow to me train my Deep Learning Models. (Nope, doesn't work, need more CPU power, and a GPU, not just free Hard Disk space or a different OS :) 


How


  1. Save your precious stuff because even if you think you are going to keep Windows, you may end up formatting your other disks!
  2. Get Ubuntu from https://www.ubuntu.com/desktop
  3. Get https://unetbootin.github.io/ to boot 
  4. Save these two things on a USB drive (e.g. pen-drive)
  5. Use unetbootin to extract ubuntu iso on pen-drive or hard disk(if you want to remove windows)
  6. Restart Computer
  7. On my dell, pressing F12 took me to boot up settings.
  8. Select booting from pen-drive
  9. Install Ubuntu or try out first (did both)
  10. During installation it will ask if you want to format your disk. I formatted it, but if you want to keep Windows, too, choose not to format.
Installation takes 30-45 minutes

Oh look! So much free space! 


Wednesday, June 20, 2018

How to change the link to your blog post when you change its title

You can change the link in Permalink -> Custom Permalink



https://www.blogger.com makes links to your blog post with the date of creation(month and year) and title of your blog, automatically.

If you end up changing your title and want it to reflect in the link, use 'Revert to draft' and 'Publish' again.

If you have already shared the link, create a post with the old title and in the content add the new link. Change schedule to the date of the original blog and publish :)



How not to install Ubuntu

Changed and moved to How to install Ubuntu

Saturday, June 16, 2018

Teach your computer XOR function with Tensorflow.js

Disclaimer: I am not qualified to teach you. But while you're here, let's learn something together.


What is XOR?


XOR or exclusive-OR is a logical operation that returns true if only one of the inputs is true. (only considering for two input combination)
https://en.wikipedia.org/wiki/Exclusive_or

Behold my bad handwriting : )


It's difficult to teach a computer XOR because the output cannot be separated by a straight line. However, now that we have the power of Machine Learning, we are going to do exactly that.

Visualize the Neural Network using TensorFlow Playground


I really enjoy trying out different Neural Networks(NN) on https://playground.tensorflow.org
Here is the NN I use for XOR playground.tensorflow.org




Bring out the power of Tensorflow.js


(Find the full code on github )

Here we are building a 2 layer NN, 1 hidden layer with 4 units and an output layer with 1 unit (the output should be between 0 and 1)

Get tensorflow.js
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.6">

Input :
const train_xs = tf.tensor2d([
[0, 0],
[0, 1],
[1, 0],
[1, 1]
]);

Output:
const train_ys = tf.tensor2d([0, 1, 1, 0], [4, 1]);
These will stay the same :)

We'll use a sequential model - that means the output of one layer is fed into the input for the next layer.
const model = tf.sequential();

Add a fully connected hidden layer. It is mandatory to give the input shape. Our inputs will be two numbers between 0 and 1. (Fully connected- each input unit is mapped to each output unit). I'll probably write about neural networks, activations, weights, and biases soon (or not), till then follow the references.
model.add(
tf.layers.dense({
inputShape: [2],
units: 4,
activation: "sigmoid",
useBias: true })
);
The activation function sigmoid was giving much better results than relu :D

Add a fully connected output layer
model.add(
tf.layers.dense({
units: 1,
activation: "sigmoid" })
);

Our model is ready! Time to compile.
Learning rate should be small, you can experiment with different values. 0.1 worked for me.
const LEARNING_RATE = 0.1;
const optimizer = tf.train.adam(LEARNING_RATE);
model.compile({
optimizer: optimizer,
loss: tf.losses.meanSquaredError,
metrics: ["accuracy"]
});

I was trying to make things work with sgd(stochastic gradient descent) optimizer, but adam worked so much better for XOR. It's a lot about hit and trial.

To fit the training data we train the model on our input multiple times. Ask the fit function to shuffle the input.

You'll notice the loss decreasing and the accuracy increasing after each round. That's it! You're done!

Make predictions


Input can be as simple as
var input = tf.tensor2d([[0, 1]]);

Use the predict function of model to make predictions
var output = model.predict(input);
console.log(output.dataSync());


I am using a canvas to depict my predictions for different inputs.
(I should write a blog on that alone because man, is that difficult!)
Find the full code on github

My canvas looked like this after 20 epochs

Inspiration


I was inspired to build a model for XOR on watching a coding challenge on 'The Coding Train' by Daniel Shiffman (https://twitter.com/shiffman)
While you're on twitter, here's my handle @iShivangiDas


Did not understand everything?


If you want to learn about TensorFlow APIs go to https://js.tensorflow.org/api/0.11.6/
Neural Networks can be learned from Coursera - https://www.coursera.org/learn/neural-networks-deep-learning (I loved these courses and would highly recommend to everyone)



Friday, June 8, 2018

Review: The Hundred-Year-Old Man Who Climbed Out of the Window and Disappeared

The Hundred-Year-Old Man Who Climbed Out of the Window and Disappeared The Hundred-Year-Old Man Who Climbed Out of the Window and Disappeared by Jonas Jonasson
My rating: 5 of 5 stars

It's funny, it's interesting, it's feel-good, it's everything you expect in a novel with a crazy title like that.
Reminded me of the movie 'Forrest Gump' but I liked the book more:)

View all my reviews

Saturday, April 7, 2018

Review: When Breath Becomes Air

When Breath Becomes Air When Breath Becomes Air by Paul Kalanithi
My rating: 5 of 5 stars

If you read one book this year, make it this one.

View all my reviews

Review: The Vegetarian

The Vegetarian The Vegetarian by Han Kang
My rating: 3 of 5 stars

It was strange. I liked it in bits and parts.

View all my reviews

Review: 1Q84

1Q84 1Q84 by Haruki Murakami
My rating: 4 of 5 stars

There are more pages in my book. :)
I liked it. It was a week I had to endure with very little sleep but 1Q84 is worth it.

It has so many 1984 references, not that I was expecting any less.

View all my reviews

Friday, March 23, 2018

What I learned from my job search

I'm going to complete a year in my new job. I work as a UI designer and full stack developer. I had written down some notes while searching for jobs that you might find fun. Here goes:

  1. Read - The more you read, the more you know and the more advantageous your position.Read about the company, read about the skills in your resume on Medium, read fiction if you're exhausted, just read. You can never go wrong with it. In one of my interviews, the interviewer and I ended up discussing the Hitchhiker's Guide to The Galaxy. I'm currently working in that company with the most amazing people who love to read.
  2. Start preparing before you even think about a job change -  Last day cramming doesn't work. Interview questions on the internet can only help you answer the initial questions, not the discussion that follows. You have to start studying way before. Moreover, it's fun since you're not studying for exams you don't have to stick to one topic. There is never a not-right-now moment when you find something interesting and would normally have to put it off till after the exams or interviews.
  3. Learn from your current project - There is always so much happening in a project, so many things you might not have worked on or something you took for granted. Even if it doesn't relate to the skills in your resume, having a couple extra things in your bag is a huge plus. It also shows you like taking new responsibilities.
  4. Make an excellent resume - Having a good academic record does make things easy, but what you put forth is what most people would see. Highlight your best points. Putting in a lot of keywords would get you a lot of interviews, however, if you're looking for something specific (and I hope you are), don't panic and put in the famous keywords (java, c#). Wait! Add what you want to work in and follow up on every interesting opportunity. 
  5. Show and tell - make projects that you can talk about in interviews (or make them anyway because they are fun). This holds for a coding job, not sure about other vocations. Code away on Github, Codepen, Freecodecamp, or anywhere else you like. The resources are endless.
Good luck with your job hunting. I hope you enjoy the process as much as I did. 

Monday, February 5, 2018

Review: Ready Player One

Ready Player One Ready Player One by Ernest Cline
My rating: 4 of 5 stars

It's an absolutely marvelous book, definitely a page-turner, a delight for all the geeks out there.
Oh I hope the movie does it justice.

View all my reviews

Friday, February 2, 2018

Review: The Raven King

The Raven King The Raven King by Maggie Stiefvater
My rating: 4 of 5 stars

No one dies. Thank god for that. I would hopefully not get more nightmares.

View all my reviews

Review: The Dream Thieves

The Dream Thieves The Dream Thieves by Maggie Stiefvater
My rating: 4 of 5 stars

Oh these books are absolutely fantastical!

View all my reviews

Review: The Raven Boys

The Raven Boys The Raven Boys by Maggie Stiefvater
My rating: 4 of 5 stars

Refreshing contemporary fantasy. I enjoyed it a lot. I used to read before bed and dream all the magical things from the books. What an amazing experience it was reading this series :)

View all my reviews

Wednesday, January 10, 2018