@@ -0,0 +1,1480 @@
+'''%0ACreated on Dec 3, 2015%0A%0A@author: kashefy%0A'''%0Aimport numpy as np%0Aimport h5py%0Aimport caffe%0A%0Adef infer_to_h5_fixed_dims(net, keys, n, dst_fpath, preserve_batch=False):%0A    %22%22%22%0A    Run network inference for n batches and save results to file%0A    %22%22%22%0A    dc = %7Bk:%5B%5D for k in keys%7D%0A    for _ in range(n):%0A        d = forward(net, keys)%0A        for k in keys:%0A            if preserve_batch:%0A                dc%5Bk%5D.append(np.copy(d%5Bk%5D))%0A            else:%0A                dc%5Bk%5D.extend(np.copy(d%5Bk%5D))%0A            %0A    with h5py.File(dst_fpath, %22w%22) as f:%0A        for k in keys:%0A            f%5Bk%5D = dc%5Bk%5D%0A            %0A    return %5Blen(dc%5Bk%5D) for k in keys%5D%0A%0Adef forward(net, keys):%0A    %0A    net.forward()%0A    return %7Bk: net.blobs%5Bk%5D.data for k in keys%7D%0A%0Aif __name__ == '__main__':%0A    %0A    import os%0A    fpath_net = os.path.expanduser('~/models/dark/mnist/t0/lenet_train_test.prototxt')%0A    fpath_weights = os.path.expanduser('~/models/dark/mnist/t0/lenet_iter_10000.caffemodel')%0A    net = caffe.Net(fpath_net, fpath_weights, caffe.TEST)%0A    fpath = os.path.expanduser('~/models/dark/mnist/t0/x.h5')%0A    infer_to_h5_fixed_dims(net, %5B'data', 'label'%5D, 4, fpath)%0A    %0A    %0A#     with h5py.File(fpath, %22w%22) as f:%0A#     %0A#         f%5B'a'%5D = 0%0A#         %0A#         %0A#         f%5B'b'%5D = %5B1, 2%5D%0A#         f%5B'c'%5D = np.arange(3)%0A#         f%5B'd'%5D = %5Bnp.array(%5B%5B1,2%5D,%5B4,5%5D%5D, dtype=float), np.array(%5B%5B1,2%5D,%5B4, 5%5D%5D, dtype=float)+10%5D%0A            %0A    #infer_to_h5(net, 1, %5B'accuracy'%5D, fpath)%0A    %0A    pass

add module with functions for running inference on net over dataset