def main(): """A simple demo showing how to run decafnet.""" from decaf.util import smalldata, visualize logging.getLogger().setLevel(logging.INFO) net = DecafNet() lena = smalldata.lena() scores = net.classify(lena) print 'prediction:', net.top_k_prediction(scores, 5) visualize.draw_net_to_file(net._net, 'decafnet.png') print 'Network structure written to decafnet.png'
def main(): """A simple demo showing how to run jeffnet.""" from decaf.util import smalldata, visualize logging.getLogger().setLevel(logging.INFO) net = JeffNet() lena = smalldata.lena() scores = net.classify(lena) print 'prediction:', net.top_k_prediction(scores, 5) visualize.draw_net_to_file(net._net, 'jeffnet.png') print 'Network structure written to jeffnet.png'
"""This demo will show how we do simple convolution on the lena image with a 15*15 average filter. """ from decaf import base from decaf.util import smalldata from decaf.layers import convolution, fillers import numpy as np from skimage import io """The main demo code.""" img = np.asarray(smalldata.lena()) img = img.reshape((1,) + img.shape).astype(np.float64) # wrap the img in a blob input_blob = base.Blob() input_blob.mirror(img) # create a convolutional layer layer = convolution.ConvolutionLayer( name='convolution', num_kernels=1, ksize=15, stride=1, mode='same', filler=fillers.ConstantFiller(value=1./15/15/3)) # run the layer output_blob = base.Blob() layer.forward([input_blob], [output_blob]) out = np.multiply(output_blob.data()[0, :, :, 0], 256).astype(np.uint8)
"""A bunch of test scripts to check the performance of jeffnet. Recommended running command: srun -p vision -c 8 --nodelist=orange6 python test_lena_prediction_pipeline.py """ from decaf.scripts import jeffnet from decaf import util from decaf.util import smalldata import numpy as np import cProfile as profile # We will use a larger figure size since many figures are fairly big. data_root='/u/vis/common/deeplearning/models/' net = jeffnet.JeffNet(data_root+'imagenet.jeffnet.epoch90', data_root+'imagenet.jeffnet.meta') lena = smalldata.lena() timer = util.Timer() print 'Testing single classification with 10-part voting (10 runs)...' # run a pass to initialize data scores = net.classify(lena) timer.reset() for i in range(10): scores = net.classify(lena) print 'Elapsed %s' % timer.total() print 'Testing single classification with center_only (10 runs)...' # run a pass to initialize data scores = net.classify(lena, center_only=True) timer.reset() for i in range(10): scores = net.classify(lena, center_only=True) print 'Elapsed %s' % timer.total()
import argparse import sys import numpy as np try: import matplotlib.pyplot as pylab except: import scipy.misc as pylab from decaf.scripts.jeffnet import JeffNet from decaf.util import smalldata data_root = '/home/rodner/data/deeplearning/models/' if len(sys.argv)<2:\ img = smalldata.lena() else: imgfn = sys.argv[1] img = pylab.imread(imgfn) net = JeffNet(data_root+'imagenet.jeffnet.epoch90', data_root+'imagenet.jeffnet.meta') print "Classify image" for i in range(5): scores = net.classify(img, center_only=True) print "Okay" #print net.top_k_prediction(scores, 10)[1]
"""A bunch of test scripts to check the performance of decafnet. Recommended running command: srun -p vision -c 8 --nodelist=orange6 python test_lena_prediction_pipeline.py """ from decaf.scripts import decafnet from decaf import util from decaf.util import smalldata import numpy as np import cProfile as profile # We will use a larger figure size since many figures are fairly big. data_root='/u/vis/common/deeplearning/models/' net = imagenet.DecafNet(data_root+'imagenet.decafnet.epoch90', data_root+'imagenet.decafnet.meta') lena = smalldata.lena() timer = util.Timer() print 'Testing single classification with 10-part voting (10 runs)...' # run a pass to initialize data scores = net.classify(lena) timer.reset() for i in range(10): scores = net.classify(lena) print 'Elapsed %s' % timer.total() print 'Testing single classification with center_only (10 runs)...' # run a pass to initialize data scores = net.classify(lena, center_only=True) timer.reset() for i in range(10): scores = net.classify(lena, center_only=True) print 'Elapsed %s' % timer.total()
"""This demo will show how we do simple convolution on the lena image with a 15*15 average filter. """ from decaf import base from decaf.util import smalldata from decaf.layers import convolution, fillers import numpy as np from skimage import io """The main demo code.""" img = np.asarray(smalldata.lena()) img = img.reshape((1, ) + img.shape).astype(np.float64) # wrap the img in a blob input_blob = base.Blob() input_blob.mirror(img) # create a convolutional layer layer = convolution.ConvolutionLayer( name='convolution', num_kernels=1, ksize=15, stride=1, mode='same', filler=fillers.ConstantFiller(value=1. / 15 / 15 / 3)) # run the layer output_blob = base.Blob() layer.forward([input_blob], [output_blob]) out = np.multiply(output_blob.data()[0, :, :, 0], 256).astype(np.uint8) io.imsave('out.png', out)