Experimenting with a Convolutional Neural Net

Its 11:00 PM at night and I have grown bored of revising for the upcoming exams. To alleviate my boredom, I think I am going to spend the next 12 hours or so hacking and blogging.

For a long time, I have been wanting to get my hands dirty with training a convolutional neural network on a GPU instance to recognise breast cell clusters and classify them to be benign or malignant. With the forthcoming days seeming to be terribly occupied with all sorts of revision frenzy, this seems the best time to dive in and see how far I can get with it. Before I dive into the code and setup, I must point out that this is my first attempt at setting up a neural network. A lot of what I will write here would be what I learn as I go along. I am not going to delve into the theoretical details and the math behind making convolutional neural nets work in this blog, I’d like to keep my focus narrowed on the implementation details.

Without further ado, lets get started.

23:34 – Got an Amazon EC2 GPU instance running. I tried installing the CS231N AMI, but I didn’t have GPU instance permissions there, so I reverted to the Oregon region and used the ami-dfb13ebf AMI for having pre installed deep learning frameworks like Tensorflow, Torch, Caffe, Theano, Keras, CNTK amongst others. As I write this, I am also installing Anaconda on the instance so I can put all of my code in a Jupyter notebook and access that remotely from my laptop. I found this guide quite useful on getting the Jupyter notebook up and running on a remote instance – https://chrisalbon.com/jupyter/run_project_jupyter_on_amazon_ec2.html

00:27 – GitHub Repository – Check, Packages Installed – Check, Data Transferred to EC2 Instance – Check.  The dataset I’ll be using today consists of ~45 histopathological images. The dataset is available at http://bioimage.ucsb.edu/research/bio-segmentation. Now, 45 images are no where near enough for training and testing a model. That’s why I’ll rely on Keras’ image augmentation features to generate synthetic training data. This would include create images that are flipped, blurred and rotated. To give an example of what the images look like, here are two from the original dataset.Screen Shot 2017-06-06 at 09.08.34 Histopathological Image Sample 1

When I first looked at these images, two conflicting feelings engulfed me. On one hand, I found these images quite fascinating; one of the smallest components of our body, undergoing mitosis. On the other hand, it was terrifying, a peek at a disease that is, as Harold Varmus put it, a distorted version of our normal selves.

01:54 – Managed to read the images into my notebook successfully and create the training arrays. Seems like all those all nighters at hackathons have made it easier for me to work well into the night without feeling particularly drowsy. Going to generate about 2500 new images per class.example

02:08 – Running into errors with generating new images. For some reason, its trying to find JPEG files, whereas my files are TIF. Managed to solve it, the error was arising due to an incorrectly specified path argument for the directory where the images were supposed to be saved. But now, I have a mix of TIF and JPEGs, not sure if that will be alright. Guess I’ll find out. With the augmented image generation done, I now have 5045 images in total. I used an 80:20 split on this.

02:50 – Transforming the images and labels was easy. Finally, after 4 hours of data processing, I can finally start training a model. For this, I’ll use an architecture with an input layer followed by convolution, maxpooling, convolution, convolution, max_pooling and fully connected layers. At this point, I’ll also add dropout to prevent over-fitting and then connect it to a fully connected layer that predicts one of the two classes. Will also use the ADAM optimiser and the loss function would be binary_crossentropy. I was predisposed to this architecture because it performed relatively well on the CIFAR-10 database. Enough talk now, time to train it.

model_description

03:39 –  The model has started training. The validation accuracy initially was looking quite encouraging, however, it remains to be seen how well it performs on the test set.evaluation training

03:46 – 87% accuracy on the test set. Not bad for a baseline model. Still, when I look at the training and validation loss, it seems the model started overfitting. I might have to play around with the parameters/model layers to see if I can make it fit better. However, going to do all that after the exams. This will require a lot of trial and error. Below are some examples that confounded the model.

Here’s an image that was predicted to be benign but is actually malignant.

malignant

On the other hand, this one was predicted to be malignant but is actually benign:

benign

The confusion matrix for the model was:

[[415  93]
[ 31 470]]

Giving this confusion matrix was important since the accuracy of the model by itself doesn’t tell us much. A better metric to use is precision and recall. Precision of a model refers to the percentage of true positives guessed, which in this case happens to be 93.04% ( Malignant Predicted and Malignant True / All Malignant Predicted). The recall percentage of the model comes out to 81.7%, which implies that the model was successful in finding the images with malignant tumours roughly 82 times out of 100.

Like I said earlier, this was primarily a learning experience for me. Spending the few hours wrangling with these images taught me:

  1. About the effectiveness of CNNs in image recognition tasks due to their ability to extract features without explicitly being given any.
  2. A few details about evaluating model performance using the training, validation and testing accuracy.
  3. How to leverage openCV and Keras to work with image data.
  4. Intuitive details about convolution, max pooling and activation functions.

Now I must call it a day on that and get back to revision, after getting some shut-eye! In the next blog post, I am going to talk about leveraging the Raspberry Pi and a few external components to turn it into a personal assistant device.

Until next time then!

A lot of code was adopted fromhttps://github.com/dhruvp/wbc-classification/blob/master/notebooks/binary_training.ipynb

Understanding Convolutional Neural Networkshttps://medium.com/@ageitgey/machine-learning-is-fun-part-3-deep-learning-and-convolutional-neural-networks-f40359318721

Further reading – Spanhol, Fabio Alexandre, Luiz S. Oliveira, Caroline Petitjean, and Laurent Heutte. “Breast Cancer Histopathological Image Classification Using Convolutional Neural Networks.” 2016 International Joint Conference on Neural Networks (IJCNN) (2016): n. pag. Web.

Code – https://github.com/achadha0111/tumor_classification/blob/master/Cell%20Classification.ipynb

Studying, Living and Working in Manchester

Over the past few weeks, a couple of Indian students wanting to study Computer Science/Engineering at Manchester got in touch with me to ask me about what it’s like to study, live and work here. Therefore, I decided on writing a (hopefully) comprehensive, guide, to answer most of the queries these students couldn’t find answers to on the University website. I hope to cover quality of education, finances, trade-offs one faces when they get here, tips on managing living costs, employment (in light of my 6 months of experience) and, of course, the weather!

But before I begin, I must point out that my ‘advice’ should only be used as a reference point. Also, my views about the education here only apply to the School of Computer Science.

Quality of Education:

In comparison to the education back home, I definitely think Manchester outclasses several domestic universities. The courses offered here are vast, often taught by people who are really passionate about their field. There are tremendous resources available for exclusive student use, be it well stocked libraries, computer clusters, support systems or sporting facilities. With the largest student body in the UK, the diversity is pretty high too.

The Alan Turing Building
The Alan Turing Building

However, I know, as an International student, the argument is seldom about the number of Nobel Prize winners in the Faculty, or the number of books in the library. Being a student who pays more than double the amount of a British/EU student, it does boil down to one important consideration, return on investment (ROI).

If you do decide to come and study here, then you should make the most of the university’s resources! Write to Faculty academic staff to try and engage in cutting edge research, devour the knowledge contained in the libraries, network through the university’s events and make the most of what’s on offer. The international student fee is high, but you can very well get the most out of it.

Finances: 

There are two major costs associated with studying here, tuition fees and accommodation fees. The university allows you to pay them in instalments, which can be quite convenient. But, also keep an eye out on the exchange rate, a favourable exchange rate might just make it easier to pay the fees in a lump sum.

Once you get here, you can work upto 20 hours a week during term time and full time during holidays to contribute towards your living costs (more on this later). You can read about the Tier-4 visa University work policy here.

Tradeoffs:

  1. Accommodation

With so many choices for accommodation, it does become a little bit overwhelming when deciding what is the best option. The way I dealt with this dilemma was looking at it in terms of implicit and explicit costs.

Before I go on, please be aware that these costs are estimated living costs for 2016/17 academic entry.

Catered accommodation means that you get 2 meals on the weekdays and fend for yourself on the weekends and during the holidays. In terms of explicit costs, you can get catered accommodation from £93 (Twin room accommodation @ Dalton Ellis) to £175 (Ensuite @ Ashburne Hall). In terms of implicit costs, this means that you have to adhere to the timings, 7:30 – 9:30 in the morning for breakfast and 17:30 – 19:15 for dinner. Then there is the cost of eating the same breakfast every day, and dinner on a 5 week rotation. On the bright side though, your food is generally healthy.

Ashburne Hall
Ashburne Hall

Self-catered on the other hand means that you can cook whenever you want, eat whatever you want and socialise over cooking with your flat mates. In terms of explicit costs the range is nearly the same. In addition to that, there are the costs of purchasing your ingredients. This can be between £20-£50 depending upon your tastes. It’s not the explicit costs that make it a tough decision, but the implicit costs. By cooking your own food, you are effectively spending time purchasing your ingredients and cooking them. While it might be an enticing idea, you should take into account your other commitments which will take a larger amount of time, such as classes and part time work. Also, more often than not, in order to save time, I have seen a lot of my friends just binge eating on processed and junk food day in, day out.

The university has a good mix of both self-catered and catered options. Some of the good catered halls are Dalton Ellis, Hulme Hall and Ashburne (this is the furthest away though from the main university campus). Similarly, some of the good self-catered halls are Denmark Road, Burkhardt House and Wright Robinson.

Denmark Road - Uncatered, swanky, close to the city, expensive
Denmark Road – Uncatered, swanky, close to the city, expensive

Then there is also the dilemma of going for private accommodation. This is another feasible choice and the university has great help available on this and all the types of accommodation on their website. 

  1. Travel

For travel within Manchester, you have plenty of options. You can walk, bike, take the bus or hail a taxi.

Stagecoach is one of the bus operators here and they offer an annual bus pass for £595 which allows unlimited travel on their buses. If you are an infrequent bus traveller and don’t want to buy a pass, a ticket for bus rides along Oxford Road cost between £1 (First) – £3.70 (Stagecoach).

I personally prefer cycling or walking though. Most of Manchester’s major roads have dedicated bike lanes. Buying a bike at one of the sales organised by the Students Union is way cheaper than investing in a bus pass, plus you can use the bike throughout your time here. Again, there is another alternative here. If you are new to biking in the city and don’t want to put money into a bike right away, you can rent one for £1/week from the Student Union’s Biko Bike project. That way, you can get your feet wet (in the Manchester rain) without burning a hole in your pocket.

One of the bikes at Biko
One of the bikes at Biko

Intercity travel in the UK is quite affordable if you book early enough. As a student, you might want to keep a look out for the Virgin Trains Seat Sale, when you can snap up a ticket for as low as £10 or the Mega Bus, which has outrageously low ticket prices at times. Apart from that, the 16-25 rail card from the National Rail gets you 1/3rd off your ticket, making it a good investment if you intend to travel and explore the country frequently.

A ride to London on one these can be as low as £10 if you make use of the sales
A ride to London on one these can be as low as £10 if you make use of the seat sale

Money Saving Tips

I already mentioned a few of these above, however, here are some more, I might update this list if I come across more:

  1. Haircuts are cheaper on the Curry Mile, in Rusholme (£6 upwards)
  2. There are two huge grocery stores on the Curry Mile as well which sell most of the things we take for granted back home. Do check out Manchester Super Store and Worldwide.
  3. Aldi is cheaper compared to Tesco
  4. Greenhouseand Vasio Cafe are probably the healthiest and most reasonable food outlets on the university campus.
  5. You can get student discounts at a bunch of stores and restaurants across the UK.
  6. There is a Gurudwara in Cheadle-Hulme that does a communal meal (Langar) at least every Sunday and on Indian religious holidays.

Employment

This is probably the elephant in the room when it comes to us Indian students and whatever I write in the next few paragraphs is only restricted to STEM degrees.

The short and simple answer to the great employment question is, if you have the skills, you will get hired, be it in the UK, in the EU or in the States.

The longer one is, you need to take initiative and put yourself out there. After all, there is no such thing as a free dinner. One of the reasons why students don’t get the right job is because they start too late, be it at cultivating their skills or searching for positions. I would recommend to undertake work that genuinely excites you and the rest will tend to fall in place.

The UK government allows for 20hrs of paid work per week during term time and full time work during the vacations. There are several places one can work part time, including the university, for instance, you can become a Student Ambassador for the School. Again, when it comes to jobs, its imperative that the notion of any job being beneath you should be left behind. Though I’d recommend that you first seek jobs relevant to your degree and once you have exhausted your options, only then move to jobs in retail/marketing.

I used a slightly different path in my job hunt though. Since I was keen on supplementing my CS education, I thought of sending speculative emails to tech startup founders in Manchester, so I could work as a developer at their companies, a few months into my ‘formal CS education’. Perhaps it was the audacity or a tool box slightly different from the others that clicked, but I got 3 offers, out of which one led to my current job.

Art in the Northern Quarter - Manchester's Art, Leisure and startup hub.
Art in the Northern Quarter – Manchester’s Art, Leisure and Startup hub.

All in all, there is a plethora of opportunities in Manchester, if you know where to look. Also, the additional money eases several of the international student costs.

Weather

“O Mancunion Weather, thou art a wundor” 

Having coming from a place where the weather is mostly sunny, the drastic weather changes in Manchester never ceases to amaze me..

A snowy Manchester morning - probably the only snow this year
A snowy Manchester morning – probably the only snow this year

There have been days when I have stepped out into bright, gleaming sunshine, only to return in a gentle snowfall. There have also been days when I have stepped into absolutely torrential rain and it has all cleared by the time I was done with classes.

A glorious, bright day in Manchester @ The Museum of Science and Industry
A glorious, bright day in Manchester @ The Museum of Science and Industry

Then there have been days when I have cursed my choice of studying in England, as I pedal furiously against a vile wind and rain duo hell bent on making me miserable!

Nonetheless, the variety definitely keeps it interesting!

On that bombshell, it’s time to end, I hope my rant + informative piece has made it easier for you to pick your university and has allayed some of the fears you may have about moving to Manchester or the UK. If there is something that you feel wasn’t covered, feel free to leave a comment below and I’ll do my best to answer!

Speak to you again soon,

Aayush

The n00b’s survival guide to hackathons

When I first started writing this post, I had only been to two hackathons. But now, with 7 hackathons under my belt, several fond memories and great friendships created, I think I can provide a more well-rounded view of attending hackathons. Despite that, I am still not getting rid of the n00b in the title. Even though my team and I built some really good stuff, it still doesn’t compare to the creative and technical brilliance one can see at some hackathons.

My main motivation behind talking about hackathons is to encourage current and incoming first years to put aside their misguided notions of being incompetent and dive head first into this crazy, energetic world of red bull and sugar driven development.

Without any further ado, here are seven things I have learnt from seven of my experiences

  1. Never go into a hackathon with a must win mindset

True, the Amazon Alexa and various drones make your mouth drool, nonetheless, hackathons are not about that! The way I see it now, it is about building cool hogwash (this was the closest substitute I could find for a certain four letter swear word starting with S), literally and figuratively. You create a product that (hopefully) works, which is cool, but your code is mostly spaghetti, spaghetti enough that TAs on COMP161 will give you zero for layout and code quality.

Out of the seven hackathons I attended, my worst two were the ones where we were only gunning for the prize and in the process, forgetting to have fun.  (More on this later)

2. Your first priority must be learning, learning fast 

Hackathons teach you a lot of things standard CS curriculums don’t. So you must see this as an opportunity to pick up frameworks, language paradigms, tools that you will probably never be formally taught. And the pace is dizzying. You have to learn things on the fly.

Some of the hackathon buzzwords
Some of the hackathon buzzwords

3. If you are the smartest person on the team, leave the team

This borrows from point 2. You are a first year student! You won’t learn unless someone pulls you out of your comfort zone and I believe that only happens when there is someone smart enough on the team to challenge you and your decisions.

4. Interact. Socialise. Network. 

There are ~300 people at a hackathon! Just imagine the amount of things you could learn and the experiences you could share if you spoke to them. People at hackathons are always keen to talk about what they are building, and that always serves as a great conversation starter, from there on, making friends is a cakewalk.

The attendees at HackCambridge (Courtesy: Major League Hacking)
The attendees at HackCambridge (Courtesy: Major League Hacking)

Apart from the hackers, also talk to the sponsors. Ask them about the work they do, the challenges they have brought, what have been their most memorable hacks and what free goodies are they offering today ;).

Some of the more interesting swag (Courtesy: Major League Hacking)
Some of the more interesting swag (Courtesy: Major League Hacking)

All of this not only helps build great rapport with them, but can also be useful to land you an internship when the time comes.

5. Don’t quit

Often, your code won’t be working as intended. For the first few hackathons, this is going to happen really often. But you must not get fazed by it! It’s part of the process. Sometimes, getting up and taking a stroll, talking to other hackers about their project works really well.

Another thing I would like to add over here is, don’t be afraid to pivot. Sometimes, what you might be trying to achieve is not possible in the given time frame (been there, done that, apparently, 50 epochs takes a long time). At one hackathon, my team came up with an idea about toilets at 1 A.M in the morning! And we ended up winning because of that.

6. Demo

At my first hackathon, I had created an Alexa skill that did nothing but looked for a word like funny, sad, boring in a sentence and told you something that would swing your mood the other way. All in all, it was a pretty basic thing. Compared to what my fellow hackers had made, my hack was a Commodore 64 compared to their Titans. Nonetheless, I demoed.

My team and I demoing are toilet hack. Yes, you can be happy and laugh after close to 30 hours of no sleep. (Courtesy: Major League Hacking)
My team and I demoing our toilet hack. Yes, you can be happy and laugh after close to 30 hours of no sleep. (Courtesy: Major League Hacking)

Since then, demoing has become my favourite part of the hackathon, it helps build character, especially when something doesn’t work as intended. Plus you get really cool hexagonal stickers that make a cool honeycomb on your laptop.

7. Have fun!

The jubilant HackSoc Manchester team at HackKings (Courtesy: Major League Hacking)
The jubilant HackSoc team at HackKings (Courtesy: Major League Hacking)

As a first year student, with practically no programming experience, hackathons can indeed seem really daunting. In all the frenzy surrounding the features to create, frameworks to learn, food to gobble, swag to pick up, one actually forgets about having fun. My fondest memories of hackathons have been where I have not been too serious, engaging in banter with my other hackers, getting Alexa to play Tunak Tunak at 12 in the morning or going out for impromptu walks in an amazing new city.

Panorama of Glasgow from the Necropolis
Panorama of Glasgow from the Necropolis

 

With all that said, stop reading this!!! Go sign up for your first hackathon on mlh.io (they really didn’t pay me to write this). A world of Node.js, Alexas, Red Bull, Sponsor Memorabilia and infinite fun awaits you! 😉

Happy Hacking.

Namaste, Manchester.

I hate clichés, I prefer to avoid them like the plague. However, I do not want to treat starting a blog as an NP complete problem and that’s why, I chose to resort to a known solution.

>> print (“Hello, world!”)

Slightly relevant XKCD comic

With that out of the way, here are a few bytes about me:

“All my details can be found here ->

(How I wish I could achieve that sort of memory optimisation for a few of my course units!)

Anyway, on to the more important things…

Firstly, how and why I ended up here in Manchester.

Truth be told, Manchester wasn’t actually my top choice at first, but when the list was whittled down to three, Manchester United certainly helped swing the gauntlet!

c1094cd6-2744-413d-91de-46cc555d0ff1

Moreover, its a university with a rich heritage, it has an entire degree programme option dedicated to the study of Artificial Intelligence and a lot of exciting research being undertaken. The city isn’t overwhelming (looking at you, London!) and has a lot of startup energy. Also the student community here in the CS school is very inclusive, hacker types who know how to have great fun.

The second important thing to tell you is what I intend to use this blog for.

  1. By letting me write this, I obviously owe the university some gratitude and naturally, I’ll be writing about things such as what it’s like to study here and what it’s like to be an international student at Manchester. I’ll also be honest about the things that I think could be better.
  2. Chronicling my time here – when I first got here, I thought about maintaining a journal, and I even got a fancy notebook for it! Alas, I couldn’t stick to it, however, this blog should drill some discipline into me on that front.
  3. Occasional discussion about studying in the UK given the economic and political situation. As an international student, it was one of my primary concerns about coming here and now I can hopefully impart some information about why it’s not such a bad idea after all!
  4. Data science projects. Every week, I try to take a dataset and derive some compelling insight from it. Now I have a platform to share some really good ones.
  5. Hackathons. Hackathons are my default weekend setting. Plus it’s a great way to travel the country, meet new people and build cool stuff (more on this next time).

Now, I must get back to my team (you guessed it, at a hackathon 😉 ) who have been giving me the glare as I have been yanking away at my keyboard and not writing anything that compiles to machine code.

Until next time!

Aayush

I am from Mumbai, India and am studying Artificial Intelligence here.