-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Gravity-Spy/develop
Merge develop into master
- Loading branch information
Showing
21 changed files
with
9,876 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,29 @@ | ||
#!/bin/bash -e | ||
# | ||
# Set up a new python2.7 virtualenv for the GWpy software stack | ||
|
||
# get name | ||
target=$1 | ||
[[ -z ${target} ]] && target=${HOME}/opt/gwpysoft | ||
packagefile=$2 | ||
rm -rf ~/opt/GravitySpy-py27 | ||
virtualenv-2.7 ~/opt/GravitySpy-py27 | ||
. ~/opt/GravitySpy-py27/bin/activate | ||
python -m pip install --upgrade --quiet pip setuptools | ||
pip install . | ||
pip install cython | ||
|
||
# -- install dependencies for virtualenv itself | ||
# get python2.7 version | ||
if [[ -z ${PYTHON_VERSION} ]]; then | ||
PYTHON_VERSION=`python2.7 -c ' | ||
import sys; | ||
print(".".join(map(str, sys.version_info[:2])))'` | ||
fi | ||
if [[ -z ${PYTHON_USER_BASE} ]]; then | ||
PYTHON_USER_BASE=`python2.7 -c 'import site; print(site.USER_BASE)'` | ||
PYTHON_USER_BASE=${HOME}/python | ||
fi | ||
if [[ -z ${PYTHON_USER_SITE} ]]; then | ||
PYTHON_USER_SITE=`python2.7 -c 'import site; print(site.USER_SITE)'` | ||
PYTHON_USER_SITE=${HOME}/python/lib/python2.7/site-packages | ||
fi | ||
# create local directories | ||
mkdir -p ${PYTHON_USER_SITE} 1>/dev/null | ||
export PATH=$PATH:/usr/local/cuda/bin/ | ||
|
||
echo ${PYTHON_USER_BASE} | ||
echo ${PYTHON_USER_SITE} | ||
git clone https://github.com/Theano/libgpuarray.git | ||
cd libgpuarray | ||
rm -rf build Build | ||
mkdir Build | ||
cd Build | ||
cmake .. -DCMAKE_INSTALL_PREFIX=~/opt/GravitySpy-py27 -DCMAKE_BUILD_TYPE=Release | ||
make | ||
make install | ||
|
||
# install pip | ||
which pip &>/dev/null || easy_install -U --prefix=${PYTHON_USER_BASE} pip | ||
export PATH=${PATH}:${PYTHON_USER_BASE}/bin | ||
cd .. | ||
|
||
# install virtualenv | ||
pip install "virtualenv" --prefix=${PYTHON_USER_BASE} | ||
echo "Virtualenv is now installed" | ||
# Run the following export and add them in your ~/.bashrc file | ||
export CPATH=$CPATH:~/opt/GravitySpy-py27/include | ||
export LIBRARY_PATH=$LIBRARY_PATH:~/opt/GravitySpy-py27/lib | ||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/opt/GravitySpy-py27/lib | ||
|
||
# -- create virtualenv | ||
virtualenv $target --system-site-packages --clear | ||
. $target/bin/activate | ||
|
||
# Upgrading pip | ||
pip install pip --upgrade | ||
pip install -r $packagefile | ||
python setup.py build | ||
python setup.py install --prefix=~/opt/GravitySpy-py27/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,78 @@ | ||
#!/usr/bin/env python | ||
|
||
import ConfigParser | ||
import optparse | ||
import argparse | ||
import os | ||
|
||
from matplotlib import use | ||
use('agg') | ||
from matplotlib import (pyplot as plt, cm) | ||
|
||
import gravityspy.ML.make_pickle_for_linux as make_pickle | ||
import gravityspy.ML.train_classifier as train_classifier | ||
|
||
# Definite Command line arguments here | ||
|
||
def parse_commandline(): | ||
"""Parse the options given on the command-line. | ||
""" | ||
parser = optparse.OptionParser() | ||
parser.add_option("--path-to-golden", help="folder where labeled images live") | ||
parser.add_option("--path-to-pickle", help="folder where pickled files will live") | ||
parser.add_option("--path-to-trained-model", help="folder where the training model will live.") | ||
parser.add_option("--batch-size", type=int, default=30,help="defines the batch size, 30 is a reasonable size") | ||
parser.add_option("--nb-epoch", type=int, default=130,help="defines the number of iterations, 130 is reasonable. You can set it to 100 or below, if you have time concern for training.") | ||
parser.add_option("--train-flag", type=int, default=0,help="a flag that shows all the golden set should be used for training the ML classifier, if 1, use training, validation and test set from golden set (ML experiments)") | ||
parser.add_option("--number-of-classes", type=int, help="") | ||
parser.add_option("--verbose", action="store_true", default=False,help="Run in Verbose Mode") | ||
opts, args = parser.parse_args() | ||
|
||
|
||
return opts | ||
|
||
# example script | ||
|
||
#THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 trainmodel --path-to-golden /home/scoughlin/public_html/GravitySpy/TrainingSet2/H1L1/ --path-to-pickle ./pickleddata/ --path-to-trained-model ./model --number-of-classes 22 --batch-size 500 | ||
opts = parse_commandline() | ||
make_pickle.main(opts.path_to_golden,opts.path_to_pickle,0,opts.verbose) | ||
train_classifier.main(opts.batch_size,opts.nb_epoch,opts.train_flag,opts.path_to_pickle,opts.path_to_trained_model,opts.number_of_classes,opts.verbose) | ||
parser = argparse.ArgumentParser(description= | ||
"An examples commandline of how to obtain a model is given below: " | ||
"THEANO_FLAGS=mode=FAST_RUN,device=cuda,floatX=float32 trainmodel " | ||
"--path-to-trainingset='somedir' --number-of-classes='somenum'") | ||
parser.add_argument("--path-to-trainingset", | ||
help="folder where labeled images live", required=True) | ||
parser.add_argument("--number-of-classes", type=int, | ||
help="How many classes do you have", required=True) | ||
parser.add_argument("--path-to-pickle", | ||
help="folder where the entire pickled training set " | ||
"will live. This pickle file should be read in " | ||
"by pandas", default='pickeleddata') | ||
parser.add_argument("--path-to-trained-model", | ||
help="folder where the final trained model will go.", | ||
default='model') | ||
parser.add_argument("--batch-size", type=int, default=30, | ||
help="defines the batch size, 30 is a reasonable size") | ||
parser.add_argument("--nb-epoch", type=int, default=20, | ||
help="defines the number of iterations, " | ||
"130 is reasonable. You can set it to 100 or below, " | ||
"if you have time concern for training.") | ||
parser.add_argument("--fraction-validation", type=float, default=0.125, | ||
help="Perentage of trianing set to save for validation") | ||
parser.add_argument("--fraction-testing", type=float, default=0, | ||
help="Percentage of training set to save for testing") | ||
parser.add_argument("--randomseed", type=int, default=1986, | ||
help="Set random seed") | ||
parser.add_argument("--verbose", action="store_true", default=False, | ||
help="Run in Verbose Mode") | ||
args = parser.parse_args() | ||
|
||
return args | ||
|
||
# Parse commandline | ||
args = parse_commandline() | ||
|
||
# Pixelate and pickle the traiing set images | ||
train_classifier.pickle_trainingset( | ||
path_to_trainingset=args.path_to_trainingset, | ||
save_address=args.path_to_pickle, | ||
verbose=args.verbose | ||
) | ||
|
||
# Check if teting percentage is 0, set to None | ||
if not args.fraction_testing: | ||
fraction_testing = None | ||
else: | ||
fraction_testing = args.fraction_testing | ||
|
||
# Train model | ||
train_classifier.make_model( | ||
data=os.path.join(args.path_to_pickle, 'trainingset.pkl'), | ||
model_folder=args.path_to_trained_model, | ||
batch_size=args.batch_size, | ||
nb_epoch=args.nb_epoch, | ||
nb_classes=args.number_of_classes, | ||
fraction_validation=args.fraction_validation, | ||
fraction_testing=fraction_testing, | ||
best_model_based_validset=0, | ||
image_size=[140, 170], | ||
random_seed=args.randomseed, | ||
verbose=True | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.