summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Yantis2015-06-11 08:39:29 -0700
committerJonathan Yantis2015-06-11 08:39:29 -0700
commit346903354565f25d4773283df4c161c806473af4 (patch)
treeaecbda02755ba5ab51e81ab47f1318c943680d26
downloadaur-346903354565f25d4773283df4c161c806473af4.tar.gz
Initial import
-rw-r--r--.SRCINFO55
-rw-r--r--Makefile.config76
-rw-r--r--PKGBUILD168
-rwxr-xr-xclassify-print-results.py170
4 files changed, 469 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..72a302b50191
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,55 @@
+pkgbase = caffe-git
+ pkgdesc = A fast framework for deep learning built in C++ for speed with a Python 2 interface
+ pkgver = r3035.543afd3
+ pkgrel = 2
+ url = https://github.com/BVLC/caffe
+ arch = x86_64
+ license = custom
+ makedepends = git
+ makedepends = python2-setuptools
+ makedepends = gcc-fortran
+ depends = cuda
+ depends = opencv
+ depends = openblas-lapack
+ depends = google-glog
+ depends = gflags
+ depends = liblmdb
+ depends = cython2
+ depends = ipython2
+ depends = python2-pillow
+ depends = python2-numpy
+ depends = python2-yaml
+ depends = python2-numpy
+ depends = python2-scipy
+ depends = python2-scikit-image
+ depends = python2-scikit-learn
+ depends = python2-matplotlib
+ depends = python2-h5py
+ depends = python2-leveldb-svn
+ depends = python2-networkx
+ depends = python2-nose
+ depends = python2-pandas
+ depends = python2-dateutil
+ depends = python2-protobuf
+ depends = python2-gflags
+ depends = python2-pandas
+ depends = boost
+ depends = boost-libs
+ depends = bc
+ provides = caffe
+ provides = pycaffe
+ provides = python2-pycaffe
+ conflicts = caffe
+ conflicts = pycaffe
+ conflicts = python2-pycaffe
+ conflicts = pycaffe-git
+ conflicts = python2-pycaffe-git
+ source = git+https://github.com/BVLC/caffe.git
+ source = classify-print-results.py
+ source = Makefile.config
+ sha256sums = SKIP
+ sha256sums = SKIP
+ sha256sums = SKIP
+
+pkgname = caffe-git
+
diff --git a/Makefile.config b/Makefile.config
new file mode 100644
index 000000000000..0cdacbf20d88
--- /dev/null
+++ b/Makefile.config
@@ -0,0 +1,76 @@
+## Refer to http://caffe.berkeleyvision.org/installation.html
+# Contributions simplifying and improving our build system are welcome!
+
+# cuDNN acceleration switch (uncomment to build with cuDNN).
+# USE_CUDNN := 1
+
+# CPU-only switch (uncomment to build without GPU support).
+# CPU_ONLY := 1
+
+# To customize your choice of compiler, uncomment and set the following.
+# N.B. the default for Linux is g++ and the default for OSX is clang++
+# CUSTOM_CXX := g++
+
+# CUDA directory contains bin/ and lib/ directories that we need.
+CUDA_DIR := /opt/cuda
+# On Ubuntu 14.04, if cuda tools are installed via
+# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
+# CUDA_DIR := /usr
+
+# CUDA architecture setting: going with all of them.
+# For CUDA < 6.0, comment the *_50 lines for compatibility.
+CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
+ -gencode arch=compute_20,code=sm_21 \
+ -gencode arch=compute_30,code=sm_30 \
+ -gencode arch=compute_35,code=sm_35 \
+ -gencode arch=compute_50,code=sm_50 \
+ -gencode arch=compute_50,code=compute_50
+
+# BLAS choice:
+# atlas for ATLAS (default)
+# mkl for MKL
+# open for OpenBlas
+BLAS := open
+# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
+# Leave commented to accept the defaults for your choice of BLAS
+# (which should work)!
+# BLAS_INCLUDE := /path/to/your/blas
+# BLAS_LIB := /path/to/your/blas
+
+# This is required only if you will compile the matlab interface.
+# MATLAB directory should contain the mex binary in /bin.
+# MATLAB_DIR := /usr/local
+# MATLAB_DIR := /Applications/MATLAB_R2012b.app
+
+# NOTE: this is required only if you will compile the python interface.
+# We need to be able to find Python.h and numpy/arrayobject.h.
+PYTHON_INCLUDE := /usr/include/python2.7 \
+ /usr/lib/python2.7/site-packages/numpy/core/include
+# Anaconda Python distribution is quite popular. Include path:
+# PYTHON_INCLUDE := $(HOME)/anaconda/include \
+ # $(HOME)/anaconda/include/python2.7 \
+ # $(HOME)/anaconda/lib/python2.7/site-packages/numpy/core/include
+
+# We need to be able to find libpythonX.X.so or .dylib.
+PYTHON_LIB := /usr/lib
+# PYTHON_LIB := $(HOME)/anaconda/lib
+
+# Uncomment to support layers written in Python (will link against Python libs)
+WITH_PYTHON_LAYER := 1
+
+# Whatever else you find you need goes here.
+INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/include
+LIBRARY_DIRS := $(PYTHON_LIB) /usr/lib
+
+BUILD_DIR := build
+DISTRIBUTE_DIR := distribute
+
+# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
+# DEBUG := 1
+
+# The ID of the GPU that 'make runtest' will use to run unit tests.
+TEST_GPUID := 0
+
+# enable pretty build (comment to see full commands)
+Q ?= @
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..6cfc068d7443
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,168 @@
+# Maintainer: jyantis <yantis@yantis.net>
+
+pkgname=caffe-git
+pkgver=r3035.543afd3
+pkgrel=2
+pkgdesc='A fast framework for deep learning built in C++ for speed with a Python 2 interface'
+arch=(x86_64)
+url='https://github.com/BVLC/caffe'
+license=('custom')
+
+# if using an AWS EC2 make sure to use the community repo for cuda and not the ec2 repo.
+depends=('cuda'
+ 'opencv'
+ 'openblas-lapack'
+ 'google-glog'
+ 'gflags'
+ 'liblmdb'
+ 'cython2'
+ 'ipython2'
+ 'python2-pillow'
+ 'python2-numpy'
+ 'python2-yaml'
+ 'python2-numpy'
+ 'python2-scipy'
+ 'python2-scikit-image'
+ 'python2-scikit-learn'
+ 'python2-matplotlib'
+ 'python2-h5py'
+ 'python2-leveldb-svn'
+ 'python2-networkx'
+ 'python2-nose'
+ 'python2-pandas'
+ 'python2-dateutil'
+ 'python2-protobuf'
+ 'python2-gflags'
+ 'python2-pandas'
+ 'boost'
+ 'boost-libs'
+ 'bc'
+ )
+
+source=('git+https://github.com/BVLC/caffe.git'
+ 'classify-print-results.py'
+ 'Makefile.config')
+makedepends=('git' 'python2-setuptools' 'gcc-fortran')
+provides=('caffe' 'pycaffe' 'python2-pycaffe' )
+conflicts=('caffe' 'pycaffe' 'python2-pycaffe' 'pycaffe-git' 'python2-pycaffe-git')
+sha256sums=('SKIP'
+ 'SKIP'
+ 'SKIP')
+
+pkgver() {
+ cd caffe
+ set -o pipefail
+ _gitversion=$( git describe --long | sed -r 's/([^-]*-g)/r\1/;s/-/./g' ||
+ printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" )
+ printf "%s" $_gitversion
+}
+
+build() {
+ # You can modify this file and do some stuff like turn off using the GPU etc
+ cp Makefile.config caffe
+
+ # Modified classify.py for testing that will output results
+ cp classify-print-results.py caffe/python/
+
+ cd caffe
+
+ # Patch any #!/usr/bin/python to #!/usr/bin/python2
+ for file in $(find . -name '*.py' -print); do
+ sed -r -i 's_^#!.*/usr/bin/python(\s|$)_#!/usr/bin/python2_' $file
+ sed -r -i 's_^#!.*/usr/bin/env(\s)*python(\s|$)_#!/usr/bin/env python2_' $file
+ done
+ # Do the same for python examples
+ for file in $(find . -name '*.py.example' -print); do
+ sed -r -i 's_^#!.*/usr/bin/python(\s|$)_#!/usr/bin/python2_' $file
+ sed -r -i 's_^#!.*/usr/bin/env(\s)*python(\s|$)_#!/usr/bin/env python2_' $file
+ done
+
+ # If the user has colormake installed then use that instead of make.
+ if hash colormake 2>/dev/null; then
+ colormake all
+ colormake pycaffe
+ else
+ make all
+ make pycaffe
+ fi
+
+ msg "Downloading the ImageNet Caffe model and labels"
+ python2 scripts/download_model_binary.py models/bvlc_reference_caffenet # 232 MB
+ sh data/ilsvrc12/get_ilsvrc_aux.sh # 17 MB
+
+ msg "Downloading the mnist data"
+ sh data/mnist/get_mnist.sh #10 MB
+}
+
+# check() {
+# cd caffe
+
+# # Unrem these next two lines to run the 838 tests
+# # make test
+# # make runtest
+
+# # A simple test to make sure its working (Attempt to classify a picture of a cat)
+# # Expected result: [('tabby', '0.27933'), ('tiger cat', '0.21915'), ('Egyptian cat', '0.16064'), ('lynx', '0.12844'), ('kit fox', '0.05155')]
+# python2 python/classify-print-results.py --print_results examples/images/cat.jpg foo
+# msg "Tested that everything works.. you should see some cat type classifiations above this message"
+# }
+
+package() {
+ cd caffe
+
+ # We don't need anything related to git in the package
+ rm -rf .git*
+
+ # Setup Python by hand since no setup.py
+ mkdir -p $pkgdir/usr/lib/python2.7/site-packages/caffe/
+ cp -R python/caffe/* $pkgdir/usr/lib/python2.7/site-packages/caffe/
+
+ # Add missing __init__.py file to ensure that the modules are detected.
+ find "$pkgdir/usr/lib/python2.7/site-packages/caffe" -type d -exec touch '{}'/__init__.py \;
+
+ # Still leaving a copy of the python code in the main caffe directory since it might be useful for some
+ # Though because of that namcap will give this error:
+ # caffe-git E: ELF file ('opt/caffe/python/caffe/_caffe.so') outside of a valid path.
+
+ # Install shared libraries
+ mkdir -p $pkgdir/usr/lib/
+ install -Dm644 .build_release/lib/* "${pkgdir}/usr/lib/"
+
+ ### Install all the execulables ###
+ mkdir -p $pkgdir/usr/bin/
+
+ # Primary executable
+ install -D -m755 .build_release/tools/caffe.bin "$pkgdir/usr/bin/caffe"
+
+ # Conversion executables
+ install -D -m755 .build_release/examples/cifar10/convert_cifar_data.bin "$pkgdir/usr/bin/convert_cifar_data"
+ install -D -m755 .build_release/examples/mnist/convert_mnist_data.bin "$pkgdir/usr/bin/convert_mnist_data"
+ install -D -m755 .build_release/examples/siamese/convert_mnist_siamese_data.bin "$pkgdir/usr/bin/convert_mnist_siamese_data"
+
+ # Depreciated executables. All in caffe executable now but included here for backwards compatiblity
+ install -D -m755 .build_release/tools/finetune_net.bin "$pkgdir/usr/bin/finetune_net"
+ install -D -m755 .build_release/tools/train_net.bin "$pkgdir/usr/bin/train_net"
+ install -D -m755 .build_release/tools/device_query.bin "$pkgdir/usr/bin/device_query"
+ install -D -m755 .build_release/tools/net_speed_benchmark.bin "$pkgdir/usr/bin/net_speed_benchmark"
+ install -D -m755 .build_release/tools/compute_image_mean.bin "$pkgdir/usr/bin/compute_image_mean"
+ install -D -m755 .build_release/tools/convert_imageset.bin "$pkgdir/usr/bin/convert_imageset"
+ install -D -m755 .build_release/tools/test_net.bin "$pkgdir/usr/bin/test_net"
+ install -D -m755 .build_release/tools/upgrade_net_proto_text.bin "$pkgdir/usr/bin/upgrade_net_proto_text"
+ # install -D -m755 .build_release/tools/dump_network.bin "$pkgdir/usr/bin/dump_network"
+ install -D -m755 .build_release/tools/extract_features.bin "$pkgdir/usr/bin/extract_features"
+
+ # clean up before copying over
+ rm -r .build_release
+ rm -r build
+
+ mkdir -p $pkgdir/opt/caffe
+ cp -r . $pkgdir/opt/caffe
+
+ # Install BSD2 License (not in common licenses so lets make it custom)
+ install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
+
+ # Install Documentation
+ install -D -m644 README.md "${pkgdir}/usr/share/doc/${pkgname}/README.md"
+}
+
+# vim:set ts=2 sw=2 et:
diff --git a/classify-print-results.py b/classify-print-results.py
new file mode 100755
index 000000000000..e356c94f653c
--- /dev/null
+++ b/classify-print-results.py
@@ -0,0 +1,170 @@
+#!/usr/bin/env python2
+"""
+classify.py is an out-of-the-box image classifer callable from the command line.
+
+By default it configures and runs the Caffe reference ImageNet model.
+"""
+import numpy as np
+import os
+import sys
+import argparse
+import glob
+import time
+import pandas as pd
+import caffe
+
+
+def main(argv):
+ pycaffe_dir = os.path.dirname(__file__)
+
+ parser = argparse.ArgumentParser()
+ # Required arguments: input and output files.
+ parser.add_argument(
+ "input_file",
+ help="Input image, directory, or npy."
+ )
+ parser.add_argument(
+ "output_file",
+ help="Output npy filename."
+ )
+ # Optional arguments.
+ parser.add_argument(
+ "--model_def",
+ default=os.path.join(pycaffe_dir,
+ "../models/bvlc_reference_caffenet/deploy.prototxt"),
+ help="Model definition file."
+ )
+ parser.add_argument(
+ "--pretrained_model",
+ default=os.path.join(
+ pycaffe_dir,
+ "../models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel"),
+ help="Trained model weights file.")
+
+ # parser.add_argument(
+ # "--gpu",
+ # action='store_true',
+ # help="Switch for gpu computation."
+ # )
+
+ parser.add_argument(
+ "--center_only",
+ action='store_true',
+ help="Switch for prediction from center crop alone instead of " +
+ "averaging predictions across crops (default)."
+ )
+ parser.add_argument(
+ "--images_dim",
+ default='256,256',
+ help="Canonical 'height,width' dimensions of input images."
+ )
+ parser.add_argument(
+ "--mean_file",
+ default=os.path.join(pycaffe_dir,
+ 'caffe/imagenet/ilsvrc_2012_mean.npy'),
+ help="Data set image mean of H x W x K dimensions (numpy array). " +
+ "Set to '' for no mean subtraction."
+ )
+ parser.add_argument(
+ "--input_scale",
+ type=float,
+ help="Multiply input features by this scale to finish preprocessing."
+ )
+ parser.add_argument(
+ "--raw_scale",
+ type=float,
+ default=255.0,
+ help="Multiply raw input by this scale before preprocessing."
+ )
+ parser.add_argument(
+ "--channel_swap",
+ default='2,1,0',
+ help="Order to permute input channels. The default converts " +
+ "RGB -> BGR since BGR is the Caffe default by way of OpenCV."
+ )
+ parser.add_argument(
+ "--ext",
+ default='jpg',
+ help="Image file extension to take as input when a directory " +
+ "is given as the input file."
+ )
+ parser.add_argument(
+ "--labels_file",
+ default=os.path.join(pycaffe_dir,
+ "../data/ilsvrc12/synset_words.txt"),
+ help="Readable label definition file."
+ )
+ parser.add_argument(
+ "--print_results",
+ action='store_true',
+ help="Write output text to stdout rather than serializing to a file."
+ )
+
+ args = parser.parse_args()
+
+ image_dims = [int(s) for s in args.images_dim.split(',')]
+
+ mean, channel_swap = None, None
+ if args.mean_file:
+ mean = np.load(args.mean_file)
+ if args.channel_swap:
+ channel_swap = [int(s) for s in args.channel_swap.split(',')]
+
+ # Make classifier.
+
+ classifier = caffe.Classifier(args.model_def, args.pretrained_model,
+ image_dims=image_dims, mean=mean,
+ input_scale=args.input_scale, raw_scale=args.raw_scale,
+ channel_swap=channel_swap)
+ # # Make classifier.
+ # classifier = caffe.Classifier(args.model_def, args.pretrained_model,
+ # image_dims=image_dims, gpu=args.gpu, mean=mean,
+ # input_scale=args.input_scale, raw_scale=args.raw_scale,
+ # channel_swap=channel_swap)
+
+ # if args.gpu:
+ # print 'GPU mode'
+
+ # Load numpy array (.npy), directory glob (*.jpg), or image file.
+ args.input_file = os.path.expanduser(args.input_file)
+ if args.input_file.endswith('npy'):
+ inputs = np.load(args.input_file)
+ elif os.path.isdir(args.input_file):
+ inputs = [caffe.io.load_image(im_f)
+ for im_f in glob.glob(args.input_file + '/*.' + args.ext)]
+ else:
+ inputs = [caffe.io.load_image(args.input_file)]
+
+ print "Classifying %d inputs." % len(inputs)
+
+ # Classify.
+ start = time.time()
+ scores = classifier.predict(inputs, not args.center_only).flatten()
+ print "Done in %.2f s." % (time.time() - start)
+
+ if args.print_results:
+ with open(args.labels_file) as f:
+ labels_df = pd.DataFrame([
+ {
+ 'synset_id': l.strip().split(' ')[0],
+ 'name': ' '.join(l.strip().split(' ')[1:]).split(',')[0]
+ }
+ for l in f.readlines()
+ ])
+ labels = labels_df.sort('synset_id')['name'].values
+
+ indices = (-scores).argsort()[:5]
+ predictions = labels[indices]
+
+ meta = [
+ (p, '%.5f' % scores[i])
+ for i, p in zip(indices, predictions)
+ ]
+
+ print meta
+
+ # Save
+ np.save(args.output_file, scores)
+
+if __name__ == '__main__':
+ main(sys.argv)