How To Extract Feature Vectors From Deep Neural Networks In Python Caffe

1 mainConvolutional Neural Networks are great at identifying all the information that makes an image distinct. When we train a deep neural network in Caffe to classify images, we specify a multilayered neural network with different types of layers like convolution, rectified linear unit, softmax loss, and so on. The last layer is the output layer that gives us the output tag with the corresponding confidence value. But sometimes it’s useful for us to extract the feature vectors from various layers and use it for other purposes. Let’s see how to do it in Python Caffe, shall we?   Continue reading “How To Extract Feature Vectors From Deep Neural Networks In Python Caffe”

How To Debug In Python

1 mainAs with all programming related tasks, debugging is an important part. If you are using an IDE, then you’ll have some kind debugging feature available. But most Python programmers like to use vim or any text editor to write code and then execute it from the terminal. So how can you debug in this situation? Whenever you are working on a project, it’s nice to have a set of tools that can be used to understand what’s happening during execution. Python has an inbuilt debugger called pdb, which stands for “Python DeBugger”. Big surprise, right? It’s a great tool to analyze your code. In this blog post, we’ll see how to use some of its most popular features. Let’s get started, shall we?   Continue reading “How To Debug In Python”

How To Create A Web Server In Python Using Flask

mainLet’s say you’ve built an interesting Python application that runs locally on your machine. Great! Now how can you make that application usable as a service or an API? A lot of times, people build many services that need to play well together to build a final application. An obvious solution to this is to build a web server like Django that can host your application and handle all the incoming requests. But building a full fledged web server seems like an overkill, especially when you are dealing with lightweight services that only need a couple of functionalities. This is where Flask comes into picture! Flask is a Python microframework that can be used to build web servers and create web applications. How do we do that? How do we build a server that can handle different types of requests?   Continue reading “How To Create A Web Server In Python Using Flask”

How To Read An Image From A URL In OpenCV-Python

1 mainReading an image from a file is fairly straightforward in OpenCV-Python. But a lot of times, we would like to read an image from a URL and process it in OpenCV. One way to do it is to download the image, save it as a jpeg file, and then read it in OpenCV. But that’s too tedious! Who wants to do manual labor? Not me! Another way would be to automatically download the image as a jpeg file using wget and then reading it in OpenCV. This is slightly better, but it’s again a roundabout way of doing it because there is an intermediate step of saving the image on disk. How do we circumvent this and directly load an image from a URL into OpenCV-Python?   Continue reading “How To Read An Image From A URL In OpenCV-Python”

Deep Learning With Caffe In Python – Part IV: Classifying An Image

4 mainIn the previous blog post, we learnt how to train a convolutional neural network (CNN). One of the most popular use cases for a CNN is to classify images. Once the CNN is trained, we need to know how to use it to classify an unknown image. The trained model files will be stored as “caffemodel” files, so we need to load those files, preprocess the input images, and then extract the output tags for those images. In this post, we will see how to load those trained model files and use it to classify an image. Let’s go ahead see how to do it, shall we?   Continue reading “Deep Learning With Caffe In Python – Part IV: Classifying An Image”

Deep Learning With Caffe In Python – Part III: Training A CNN

3 mainIn the previous blog post, we learnt about how to interact with a Caffe model. In this blog post, we will learn how to train a proper CNN. Up until now, we were dealing with a single layer network. We just defined it in a prototxt file and visualized it easily. If we want our CNN to perform any meaningful tasks, we should define a multilayer network and allow it to train on a large amount of data. Caffe makes it very easy for us to train a multilayer network. We can specify all the parameters in a prototxt file, create a training database, and just train the network. Let’s go ahead and see how to do that, shall we?   Continue reading “Deep Learning With Caffe In Python – Part III: Training A CNN”

Deep Learning With Caffe In Python – Part II: Interacting With A Model

2 mainI know that the title looks slightly misleading. If you are thinking that we will be talking about how to interact with fashion models at a coffee shop, you are in for a big surprise! In the previous blog post, we talked about how to define and visualize a single layer convolutional neural network (CNN). In this post, we will discuss how to interact with a Caffe model. This is a continuation of the previous blog post. So if you haven’t read it, you may want to take a quick glance at it before you proceed. In that post, we defined our CNN architecture in a prototxt file. Now how do we make it do stuff for us? When we load such a network using Caffe, it comes with a bunch of features. Let’s see how to work with our model, shall we?   Continue reading “Deep Learning With Caffe In Python – Part II: Interacting With A Model”

Deep Learning With Caffe In Python – Part I: Defining A Layer

1 mainCaffe is one the most popular deep learning packages out there. In one of the previous blog posts, we talked about how to install Caffe. In this blog post, we will discuss how to get started with Caffe and use its various features. We will then build a convolutional neural network (CNN) that can be used for image classification. Caffe plays very well with the GPU during the training process, hence we can achieve a lot of speed-up. For the purpose of this discussion, it is assumed that you have already installed Caffe on your machine. Let’s go ahead and see how to interact with Caffe, shall we?   Continue reading “Deep Learning With Caffe In Python – Part I: Defining A Layer”

How To Train A Neural Network In Python – Part III

ImageJ=1.44p unit=umIn the previous blog post, we learnt how to build a multilayer neural network in Python. What we did there falls under the category of supervised learning. In that realm, we have some training data and we have the associated labels. Now the goal is to train the neural network correctly label our training data. Once we train the model, we can use it to predict the labels of unknown datapoints. But what about unsupervised learning? In the real world, we also have to deal with a lot of unlabeled data. Can we train a neural network to recognize clusters in our data? Yes, we certainly can! Let’s go ahead and see how we can do that in Python, shall we?   Continue reading “How To Train A Neural Network In Python – Part III”

How To Train A Neural Network In Python – Part II

1 mainIn the previous blog post, we discussed about perceptrons. We learnt how to train a perceptron in Python to achieve a simple classification task. If you need a quick refresher on perceptrons, you can check out that blog post before proceeding further. In a way, perceptron is a single layer neural network with a single neuron. In this blog post, we will learn how to develop a multilayer neural network. A multilayer neural network consists of multiple layers and each layer consists of many perceptrons, and it is much better at classifying data that a single perceptron. So how exactly does a multilayer neural network function? How do we build it in Python?   Continue reading “How To Train A Neural Network In Python – Part II”