F beta score for Keras

I’m a newbie in Deep Learning, so it makes sense to practice a bit at simple problems. So I’ve decided to join the contest Planet: Understanding the Amazon from Space at Kaggle. The contest looks promising and not too complicated comparing to other deep learning competitions: not too much data, no image segmentation or image localization required, data is preprocessed properly. The goal is to assign tags (e.g. forest, agriculture, roads etc.) to satellite image patches. Nice problem for the beginner, isn’t it?

The competition uses F2 score as a metric - custom case of F beta score. F1 score is more popular choice, so I wonder why they chose beta = 2. However this metric is available in scikit-learn, which is not suitable for deep learning. So it makes sense to create one for Keras which is easiest DL framework for prototyping. The code was tested with tensorflow backend for Keras.

Same code at Kaggle