Skip to main content
1. Let's start learning Caffe
I am sharing my experiences while I learn Caffe here. If you need any info please comment. Let's get started with caffe.
Machine Learning: If you cannot code something, learn from data, like the way humans learn. Recall how we learned A to Z.
Deep Learning: Include Neural Networks as machine learning model.
Neural network: A combination of neurons, each of which fire when the weighted sum of its inputs exceed a threshold. A network has many layers of neurons. Representation: network(input), where input can be an image or a vector reperesenting a character or a word.
Loss function: Objective or Mathematical function to be minimized. E.g. for A to Z image classification you can have norm(network(image), ohe(label)) as a loss function.
E.g.: norm(network(imageA), [1 0 0 ... ]26X1); where [1 0 0 ... ]26X1 is a one hot encoded vector represnting label A at desired output of network. For label B it would be [0 1 0 ... ]26X1 and so on to [0 0 0 ... 0 1 ]26X1 for label Z.
Backpropogation: Chain rule of derivatives by which network updates its weights while training.
Caffe: A deep learning framework made with three aspects:
1. Expression.
2. Speed.
3. Modularity.
Caffe is developed by BVLC(Berkley Vision and Learning Centere) and by community contributors.
Caffe is written in C++ with wrappers of python and Matlab.
Blobs: A standard array and unified memory interface for the framework. It stores, communicates and manipulates the information across the layers and nets during forward and backward pass.
Let's get started with a small caffe code to store information in a blob and getting it back. We will use numpy to store arrays in python.
#Load numpy and caffe:
import numpy as np
import caffe as caffe
# Let's declare a blob:-
blob = caffe.proto.caffe_pb2.BlobProto()
# store an array np.ones((3,1)) i.e. [1 1 1] in blob
blob.data.extend(list(np.ones((3,1)).flatten()))
#store 2 zeros
blob.data.extend(list(np.zeros((1,2)).flatten()))
#read and then print contents of a blob
blob.num, blob.channels, blob.height, blob.width = (1,1,1,5)
print(caffe.io.blobproto_to_array(blob))
#this will print [[[[1. 1. 1. 0. 0.]]]], change (1,1,1,5) to (1,1,5,1) and retry.. store matrices array np.ones((2,2)) and retry..
So, we learned some basics about machine learning, neural networks and caffe. We learned a python code to store and read information to/from a blob in caffe.
Comments
Post a Comment