Skip to content

Latest commit

 

History

History

mnist

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

LeNet Example

Thanks to @Russell91 for this example

This example showns you how to finetune code from the Caffe MNIST tutorial using Tensorflow. First, you can convert a prototxt model to tensorflow code:

$ ./convert.py examples/mnist/lenet.prototxt --code-output-path=mynet.py

This produces tensorflow code for the LeNet network in mynet.py. The code can be imported as described below in the Inference section. Caffe-tensorflow also lets you convert .caffemodel weight files to .npy files that can be directly loaded from tensorflow:

$ ./convert.py examples/mnist/lenet.prototxt --caffemodel examples/mnist/lenet_iter_10000.caffemodel --data-output-path=mynet.npy

The above command will generate a weight file named mynet.npy.

Inference:

Once you have generated both the code weight files for LeNet, you can finetune LeNet using tensorflow with

$ ./examples/mnist/finetune_mnist.py

At a high level, finetune_mnist.py works as follows:

# Import the converted model's class
from mynet import MyNet

# Create an instance, passing in the input data
net = MyNet({'data':my_input_data})

with tf.Session() as sesh:
    # Load the data
    net.load('mynet.npy', sesh)
    # Forward pass
    output = sesh.run(net.get_output(), ...)