Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
c173234f
Commit
c173234f
authored
Feb 13, 2018
by
lzc5123016
Browse files
Merge remote-tracking branch 'upstream/master'
Sync with master.
parents
87ed703c
20a4313d
Changes
37
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
161 additions
and
87 deletions
+161
-87
research/gan/README.md
research/gan/README.md
+1
-1
research/gan/cifar/launch_jobs.sh
research/gan/cifar/launch_jobs.sh
+2
-2
research/gan/image_compression/launch_jobs.sh
research/gan/image_compression/launch_jobs.sh
+1
-1
research/gan/mnist/launch_jobs.sh
research/gan/mnist/launch_jobs.sh
+3
-3
research/lfads/README.md
research/lfads/README.md
+13
-2
research/lfads/lfads.py
research/lfads/lfads.py
+40
-8
research/lfads/run_lfads.py
research/lfads/run_lfads.py
+38
-11
research/lfads/synth_data/generate_itb_data.py
research/lfads/synth_data/generate_itb_data.py
+6
-6
research/lfads/synth_data/generate_labeled_rnn_data.py
research/lfads/synth_data/generate_labeled_rnn_data.py
+7
-7
research/lfads/synth_data/run_generate_synth_data.sh
research/lfads/synth_data/run_generate_synth_data.sh
+7
-7
research/lfads/synth_data/synthetic_data_utils.py
research/lfads/synth_data/synthetic_data_utils.py
+3
-3
research/lfads/utils.py
research/lfads/utils.py
+13
-10
research/object_detection/g3doc/installation.md
research/object_detection/g3doc/installation.md
+10
-9
research/tcn/data_providers.py
research/tcn/data_providers.py
+1
-1
samples/core/get_started/iris_data.py
samples/core/get_started/iris_data.py
+7
-7
tutorials/image/cifar10_estimator/generate_cifar10_tfrecords.py
...als/image/cifar10_estimator/generate_cifar10_tfrecords.py
+4
-4
tutorials/rnn/ptb/ptb_word_lm.py
tutorials/rnn/ptb/ptb_word_lm.py
+5
-5
No files found.
research/gan/README.md
View file @
c173234f
...
@@ -23,7 +23,7 @@ Maintainers of TFGAN:
...
@@ -23,7 +23,7 @@ Maintainers of TFGAN:
1.
[
CIFAR10
](
#cifar10
)
1.
[
CIFAR10
](
#cifar10
)
1.
[
Image compression
(coming soon)
](
#compression
)
1.
[
Image compression
](
#compression
)
## MNIST
## MNIST
<a
id=
'mnist'
></a>
<a
id=
'mnist'
></a>
...
...
research/gan/cifar/launch_jobs.sh
View file @
c173234f
...
@@ -89,7 +89,7 @@ if [[ "$gan_type" == "unconditional" ]]; then
...
@@ -89,7 +89,7 @@ if [[ "$gan_type" == "unconditional" ]]; then
--dataset_dir
=
${
DATASET_DIR
}
\
--dataset_dir
=
${
DATASET_DIR
}
\
--eval_real_images
=
false
\
--eval_real_images
=
false
\
--conditional_eval
=
false
\
--conditional_eval
=
false
\
--max_number_of_evaluation
=
1
--max_number_of_evaluation
s
=
1
Banner
"Finished unconditional evaluation. See
${
UNCONDITIONAL_EVAL_DIR
}
for output images."
Banner
"Finished unconditional evaluation. See
${
UNCONDITIONAL_EVAL_DIR
}
for output images."
fi
fi
...
@@ -116,6 +116,6 @@ if [[ "$gan_type" == "conditional" ]]; then
...
@@ -116,6 +116,6 @@ if [[ "$gan_type" == "conditional" ]]; then
--dataset_dir
=
${
DATASET_DIR
}
\
--dataset_dir
=
${
DATASET_DIR
}
\
--eval_real_images
=
false
\
--eval_real_images
=
false
\
--conditional_eval
=
true
\
--conditional_eval
=
true
\
--max_number_of_evaluation
=
1
--max_number_of_evaluation
s
=
1
Banner
"Finished conditional evaluation. See
${
CONDITIONAL_EVAL_DIR
}
for output images."
Banner
"Finished conditional evaluation. See
${
CONDITIONAL_EVAL_DIR
}
for output images."
fi
fi
research/gan/image_compression/launch_jobs.sh
View file @
c173234f
...
@@ -80,5 +80,5 @@ python "${git_repo}/research/gan/image_compression/eval.py" \
...
@@ -80,5 +80,5 @@ python "${git_repo}/research/gan/image_compression/eval.py" \
--checkpoint_dir
=
${
MODEL_TRAIN_DIR
}
\
--checkpoint_dir
=
${
MODEL_TRAIN_DIR
}
\
--eval_dir
=
${
MODEL_EVAL_DIR
}
\
--eval_dir
=
${
MODEL_EVAL_DIR
}
\
--dataset_dir
=
${
DATASET_DIR
}
\
--dataset_dir
=
${
DATASET_DIR
}
\
--max_number_of_evaluation
=
1
--max_number_of_evaluation
s
=
1
Banner
"Finished evaluation. See
${
MODEL_EVAL_DIR
}
for output images."
Banner
"Finished evaluation. See
${
MODEL_EVAL_DIR
}
for output images."
research/gan/mnist/launch_jobs.sh
View file @
c173234f
...
@@ -102,7 +102,7 @@ if [[ "$gan_type" == "unconditional" ]]; then
...
@@ -102,7 +102,7 @@ if [[ "$gan_type" == "unconditional" ]]; then
--dataset_dir
=
${
DATASET_DIR
}
\
--dataset_dir
=
${
DATASET_DIR
}
\
--eval_real_images
=
false
\
--eval_real_images
=
false
\
--classifier_filename
=
${
FROZEN_GRAPH
}
\
--classifier_filename
=
${
FROZEN_GRAPH
}
\
--max_number_of_evaluation
=
1
--max_number_of_evaluation
s
=
1
Banner
"Finished unconditional evaluation. See
${
UNCONDITIONAL_EVAL_DIR
}
for output images."
Banner
"Finished unconditional evaluation. See
${
UNCONDITIONAL_EVAL_DIR
}
for output images."
fi
fi
...
@@ -127,7 +127,7 @@ if [[ "$gan_type" == "conditional" ]]; then
...
@@ -127,7 +127,7 @@ if [[ "$gan_type" == "conditional" ]]; then
--checkpoint_dir
=
${
CONDITIONAL_TRAIN_DIR
}
\
--checkpoint_dir
=
${
CONDITIONAL_TRAIN_DIR
}
\
--eval_dir
=
${
CONDITIONAL_EVAL_DIR
}
\
--eval_dir
=
${
CONDITIONAL_EVAL_DIR
}
\
--classifier_filename
=
${
FROZEN_GRAPH
}
\
--classifier_filename
=
${
FROZEN_GRAPH
}
\
--max_number_of_evaluation
=
1
--max_number_of_evaluation
s
=
1
Banner
"Finished conditional evaluation. See
${
CONDITIONAL_EVAL_DIR
}
for output images."
Banner
"Finished conditional evaluation. See
${
CONDITIONAL_EVAL_DIR
}
for output images."
fi
fi
...
@@ -152,6 +152,6 @@ if [[ "$gan_type" == "infogan" ]]; then
...
@@ -152,6 +152,6 @@ if [[ "$gan_type" == "infogan" ]]; then
--checkpoint_dir
=
${
INFOGAN_TRAIN_DIR
}
\
--checkpoint_dir
=
${
INFOGAN_TRAIN_DIR
}
\
--eval_dir
=
${
INFOGAN_EVAL_DIR
}
\
--eval_dir
=
${
INFOGAN_EVAL_DIR
}
\
--classifier_filename
=
${
FROZEN_GRAPH
}
\
--classifier_filename
=
${
FROZEN_GRAPH
}
\
--max_number_of_evaluation
=
1
--max_number_of_evaluation
s
=
1
Banner
"Finished InfoGAN evaluation. See
${
INFOGAN_EVAL_DIR
}
for output images."
Banner
"Finished InfoGAN evaluation. See
${
INFOGAN_EVAL_DIR
}
for output images."
fi
fi
research/lfads/README.md
View file @
c173234f
...
@@ -7,7 +7,7 @@ This code implements the model from the paper "[LFADS - Latent Factor Analysis v
...
@@ -7,7 +7,7 @@ This code implements the model from the paper "[LFADS - Latent Factor Analysis v
The code is written in Python 2.7.6. You will also need:
The code is written in Python 2.7.6. You will also need:
*
**TensorFlow**
version 1.
2.1
(
[
install
](
https://www.tensorflow.org/install/
)
) -
*
**TensorFlow**
version 1.
5
(
[
install
](
https://www.tensorflow.org/install/
)
) -
*
**NumPy, SciPy, Matplotlib**
(
[
install SciPy stack
](
https://www.scipy.org/install.html
)
, contains all of them)
*
**NumPy, SciPy, Matplotlib**
(
[
install SciPy stack
](
https://www.scipy.org/install.html
)
, contains all of them)
*
**h5py**
(
[
install
](
https://pypi.python.org/pypi/h5py
)
)
*
**h5py**
(
[
install
](
https://pypi.python.org/pypi/h5py
)
)
...
@@ -98,7 +98,18 @@ $ python run_lfads.py --kind=train \
...
@@ -98,7 +98,18 @@ $ python run_lfads.py --kind=train \
--output_filename_stem
=
""
\
--output_filename_stem
=
""
\
--ic_prior_var_max
=
0.1
\
--ic_prior_var_max
=
0.1
\
--prior_ar_atau
=
10.0
\
--prior_ar_atau
=
10.0
\
--do_train_io_only
=
false
--do_train_io_only
=
false
\
--do_train_encoder_only
=
false
# Run LFADS on chaotic rnn data with no input pulses (g = 1.5) with Gaussian noise
$
python run_lfads.py
--kind
=
train
\
--data_dir
=
/tmp/rnn_synth_data_v1.0/
\
--data_filename_stem
=
gaussian_chaotic_rnn_no_inputs
\
--lfads_save_dir
=
/tmp/lfads_chaotic_rnn_inputs_g2p5
\
--co_dim
=
1
\
--factors_dim
=
20
\
--output_dist
=
gaussian
# Run LFADS on chaotic rnn data with input pulses (g = 2.5)
# Run LFADS on chaotic rnn data with input pulses (g = 2.5)
$
python run_lfads.py
--kind
=
train
\
$
python run_lfads.py
--kind
=
train
\
...
...
research/lfads/lfads.py
View file @
c173234f
...
@@ -365,7 +365,12 @@ class LFADS(object):
...
@@ -365,7 +365,12 @@ class LFADS(object):
if
datasets
and
'alignment_matrix_cxf'
in
datasets
[
name
].
keys
():
if
datasets
and
'alignment_matrix_cxf'
in
datasets
[
name
].
keys
():
dataset
=
datasets
[
name
]
dataset
=
datasets
[
name
]
print
(
"Using alignment matrix provided for dataset:"
,
name
)
if
hps
.
do_train_readin
:
print
(
"Initializing trainable readin matrix with alignment matrix"
\
" provided for dataset:"
,
name
)
else
:
print
(
"Setting non-trainable readin matrix to alignment matrix"
\
" provided for dataset:"
,
name
)
in_mat_cxf
=
dataset
[
'alignment_matrix_cxf'
].
astype
(
np
.
float32
)
in_mat_cxf
=
dataset
[
'alignment_matrix_cxf'
].
astype
(
np
.
float32
)
if
in_mat_cxf
.
shape
!=
(
data_dim
,
factors_dim
):
if
in_mat_cxf
.
shape
!=
(
data_dim
,
factors_dim
):
raise
ValueError
(
"""Alignment matrix must have dimensions %d x %d
raise
ValueError
(
"""Alignment matrix must have dimensions %d x %d
...
@@ -374,7 +379,12 @@ class LFADS(object):
...
@@ -374,7 +379,12 @@ class LFADS(object):
in_mat_cxf
.
shape
[
1
]))
in_mat_cxf
.
shape
[
1
]))
if
datasets
and
'alignment_bias_c'
in
datasets
[
name
].
keys
():
if
datasets
and
'alignment_bias_c'
in
datasets
[
name
].
keys
():
dataset
=
datasets
[
name
]
dataset
=
datasets
[
name
]
print
(
"Using alignment bias provided for dataset:"
,
name
)
if
hps
.
do_train_readin
:
print
(
"Initializing trainable readin bias with alignment bias "
\
"provided for dataset:"
,
name
)
else
:
print
(
"Setting non-trainable readin bias to alignment bias "
\
"provided for dataset:"
,
name
)
align_bias_c
=
dataset
[
'alignment_bias_c'
].
astype
(
np
.
float32
)
align_bias_c
=
dataset
[
'alignment_bias_c'
].
astype
(
np
.
float32
)
align_bias_1xc
=
np
.
expand_dims
(
align_bias_c
,
axis
=
0
)
align_bias_1xc
=
np
.
expand_dims
(
align_bias_c
,
axis
=
0
)
if
align_bias_1xc
.
shape
[
1
]
!=
data_dim
:
if
align_bias_1xc
.
shape
[
1
]
!=
data_dim
:
...
@@ -387,12 +397,22 @@ class LFADS(object):
...
@@ -387,12 +397,22 @@ class LFADS(object):
# So b = -alignment_bias * W_in to accommodate PCA style offset.
# So b = -alignment_bias * W_in to accommodate PCA style offset.
in_bias_1xf
=
-
np
.
dot
(
align_bias_1xc
,
in_mat_cxf
)
in_bias_1xf
=
-
np
.
dot
(
align_bias_1xc
,
in_mat_cxf
)
in_fac_lin
=
init_linear
(
data_dim
,
used_in_factors_dim
,
do_bias
=
True
,
if
hps
.
do_train_readin
:
# only add to IO transformations collection only if we want it to be
# learnable, because IO_transformations collection will be trained
# when do_train_io_only
collections_readin
=
[
'IO_transformations'
]
else
:
collections_readin
=
None
in_fac_lin
=
init_linear
(
data_dim
,
used_in_factors_dim
,
do_bias
=
True
,
mat_init_value
=
in_mat_cxf
,
mat_init_value
=
in_mat_cxf
,
bias_init_value
=
in_bias_1xf
,
bias_init_value
=
in_bias_1xf
,
identity_if_possible
=
in_identity_if_poss
,
identity_if_possible
=
in_identity_if_poss
,
normalized
=
False
,
name
=
"x_2_infac_"
+
name
,
normalized
=
False
,
name
=
"x_2_infac_"
+
name
,
collections
=
[
'IO_transformations'
])
collections
=
collections_readin
,
trainable
=
hps
.
do_train_readin
)
in_fac_W
,
in_fac_b
=
in_fac_lin
in_fac_W
,
in_fac_b
=
in_fac_lin
fns_in_fac_Ws
[
d
]
=
makelambda
(
in_fac_W
)
fns_in_fac_Ws
[
d
]
=
makelambda
(
in_fac_W
)
fns_in_fac_bs
[
d
]
=
makelambda
(
in_fac_b
)
fns_in_fac_bs
[
d
]
=
makelambda
(
in_fac_b
)
...
@@ -417,7 +437,7 @@ class LFADS(object):
...
@@ -417,7 +437,7 @@ class LFADS(object):
out_mat_fxc
=
None
out_mat_fxc
=
None
out_bias_1xc
=
None
out_bias_1xc
=
None
if
in_mat_cxf
is
not
None
:
if
in_mat_cxf
is
not
None
:
out_mat_fxc
=
np
.
linalg
.
pinv
(
in_mat_cxf
)
out_mat_fxc
=
in_mat_cxf
.
T
if
align_bias_1xc
is
not
None
:
if
align_bias_1xc
is
not
None
:
out_bias_1xc
=
align_bias_1xc
out_bias_1xc
=
align_bias_1xc
...
@@ -895,13 +915,25 @@ class LFADS(object):
...
@@ -895,13 +915,25 @@ class LFADS(object):
return
return
# OPTIMIZATION
# OPTIMIZATION
if
not
self
.
hps
.
do_train_io_only
:
# train the io matrices only
if
self
.
hps
.
do_train_io_only
:
self
.
train_vars
=
tvars
=
\
self
.
train_vars
=
tvars
=
\
tf
.
get_collection
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
,
tf
.
get_collection
(
'IO_transformations'
,
scope
=
tf
.
get_variable_scope
().
name
)
scope
=
tf
.
get_variable_scope
().
name
)
# train the encoder only
elif
self
.
hps
.
do_train_encoder_only
:
tvars1
=
\
tf
.
get_collection
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
,
scope
=
'LFADS/ic_enc_*'
)
tvars2
=
\
tf
.
get_collection
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
,
scope
=
'LFADS/z/ic_enc_*'
)
self
.
train_vars
=
tvars
=
tvars1
+
tvars2
# train all variables
else
:
else
:
self
.
train_vars
=
tvars
=
\
self
.
train_vars
=
tvars
=
\
tf
.
get_collection
(
'IO_transformations'
,
tf
.
get_collection
(
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
,
scope
=
tf
.
get_variable_scope
().
name
)
scope
=
tf
.
get_variable_scope
().
name
)
print
(
"done."
)
print
(
"done."
)
print
(
"Model Variables (to be optimized): "
)
print
(
"Model Variables (to be optimized): "
)
...
...
research/lfads/run_lfads.py
View file @
c173234f
...
@@ -23,6 +23,8 @@ import os
...
@@ -23,6 +23,8 @@ import os
import
tensorflow
as
tf
import
tensorflow
as
tf
import
re
import
re
import
utils
import
utils
import
sys
MAX_INT
=
sys
.
maxsize
# Lots of hyperparameters, but most are pretty insensitive. The
# Lots of hyperparameters, but most are pretty insensitive. The
# explanation of these hyperparameters is found below, in the flags
# explanation of these hyperparameters is found below, in the flags
...
@@ -35,7 +37,7 @@ OUTPUT_FILENAME_STEM = ""
...
@@ -35,7 +37,7 @@ OUTPUT_FILENAME_STEM = ""
DEVICE
=
"gpu:0"
# "cpu:0", or other gpus, e.g. "gpu:1"
DEVICE
=
"gpu:0"
# "cpu:0", or other gpus, e.g. "gpu:1"
MAX_CKPT_TO_KEEP
=
5
MAX_CKPT_TO_KEEP
=
5
MAX_CKPT_TO_KEEP_LVE
=
5
MAX_CKPT_TO_KEEP_LVE
=
5
PS_NEXAMPLES_TO_PROCESS
=
1e8
# if larger than number of examples, process all
PS_NEXAMPLES_TO_PROCESS
=
MAX_INT
# if larger than number of examples, process all
EXT_INPUT_DIM
=
0
EXT_INPUT_DIM
=
0
IC_DIM
=
64
IC_DIM
=
64
FACTORS_DIM
=
50
FACTORS_DIM
=
50
...
@@ -51,8 +53,10 @@ LEARNING_RATE_STOP = 0.00001
...
@@ -51,8 +53,10 @@ LEARNING_RATE_STOP = 0.00001
LEARNING_RATE_N_TO_COMPARE
=
6
LEARNING_RATE_N_TO_COMPARE
=
6
INJECT_EXT_INPUT_TO_GEN
=
False
INJECT_EXT_INPUT_TO_GEN
=
False
DO_TRAIN_IO_ONLY
=
False
DO_TRAIN_IO_ONLY
=
False
DO_TRAIN_ENCODER_ONLY
=
False
DO_RESET_LEARNING_RATE
=
False
DO_RESET_LEARNING_RATE
=
False
FEEDBACK_FACTORS_OR_RATES
=
"factors"
FEEDBACK_FACTORS_OR_RATES
=
"factors"
DO_TRAIN_READIN
=
True
# Calibrated just above the average value for the rnn synthetic data.
# Calibrated just above the average value for the rnn synthetic data.
MAX_GRAD_NORM
=
200.0
MAX_GRAD_NORM
=
200.0
...
@@ -60,7 +64,7 @@ CELL_CLIP_VALUE = 5.0
...
@@ -60,7 +64,7 @@ CELL_CLIP_VALUE = 5.0
KEEP_PROB
=
0.95
KEEP_PROB
=
0.95
TEMPORAL_SPIKE_JITTER_WIDTH
=
0
TEMPORAL_SPIKE_JITTER_WIDTH
=
0
OUTPUT_DISTRIBUTION
=
'poisson'
# 'poisson' or 'gaussian'
OUTPUT_DISTRIBUTION
=
'poisson'
# 'poisson' or 'gaussian'
NUM_STEPS_FOR_GEN_IC
=
np
.
inf
# set to num_steps if greater than num_steps
NUM_STEPS_FOR_GEN_IC
=
MAX_INT
# set to num_steps if greater than num_steps
DATA_DIR
=
"/tmp/rnn_synth_data_v1.0/"
DATA_DIR
=
"/tmp/rnn_synth_data_v1.0/"
DATA_FILENAME_STEM
=
"chaotic_rnn_inputs_g1p5"
DATA_FILENAME_STEM
=
"chaotic_rnn_inputs_g1p5"
...
@@ -209,9 +213,9 @@ flags.DEFINE_float("co_prior_var_scale", CO_PRIOR_VAR_SCALE,
...
@@ -209,9 +213,9 @@ flags.DEFINE_float("co_prior_var_scale", CO_PRIOR_VAR_SCALE,
"Variance of control input prior distribution."
)
"Variance of control input prior distribution."
)
flags
.
DEFINE_float
(
"prior_ar_atau"
,
PRIOR_AR_AUTOCORRELATION
,
flags
.
DEFINE_float
(
"prior_ar_atau"
,
PRIOR_AR_AUTOCORRELATION
,
"Initial autocorrelation of AR(1) priors."
)
"Initial autocorrelation of AR(1) priors."
)
flags
.
DEFINE_float
(
"prior_ar_nvar"
,
PRIOR_AR_PROCESS_VAR
,
flags
.
DEFINE_float
(
"prior_ar_nvar"
,
PRIOR_AR_PROCESS_VAR
,
"Initial noise variance for AR(1) priors."
)
"Initial noise variance for AR(1) priors."
)
flags
.
DEFINE_boolean
(
"do_train_prior_ar_atau"
,
DO_TRAIN_PRIOR_AR_ATAU
,
flags
.
DEFINE_boolean
(
"do_train_prior_ar_atau"
,
DO_TRAIN_PRIOR_AR_ATAU
,
"Is the value for atau an init, or the constant value?"
)
"Is the value for atau an init, or the constant value?"
)
...
@@ -254,13 +258,13 @@ flags.DEFINE_boolean("do_causal_controller",
...
@@ -254,13 +258,13 @@ flags.DEFINE_boolean("do_causal_controller",
# Strictly speaking, feeding either the factors or the rates to the controller
# Strictly speaking, feeding either the factors or the rates to the controller
# violates causality, since the g0 gets to see all the data. This may or may not
# violates causality, since the g0 gets to see all the data. This may or may not
# be only a theoretical concern.
# be only a theoretical concern.
flags
.
DEFINE_boolean
(
"do_feed_factors_to_controller"
,
flags
.
DEFINE_boolean
(
"do_feed_factors_to_controller"
,
DO_FEED_FACTORS_TO_CONTROLLER
,
DO_FEED_FACTORS_TO_CONTROLLER
,
"Should factors[t-1] be input to controller at time t?"
)
"Should factors[t-1] be input to controller at time t?"
)
flags
.
DEFINE_string
(
"feedback_factors_or_rates"
,
FEEDBACK_FACTORS_OR_RATES
,
flags
.
DEFINE_string
(
"feedback_factors_or_rates"
,
FEEDBACK_FACTORS_OR_RATES
,
"Feedback the factors or the rates to the controller?
\
"Feedback the factors or the rates to the controller?
\
Acceptable values: 'factors' or 'rates'."
)
Acceptable values: 'factors' or 'rates'."
)
flags
.
DEFINE_integer
(
"controller_input_lag"
,
CONTROLLER_INPUT_LAG
,
flags
.
DEFINE_integer
(
"controller_input_lag"
,
CONTROLLER_INPUT_LAG
,
"Time lag on the encoding to controller t-lag for
\
"Time lag on the encoding to controller t-lag for
\
forward, t+lag for reverse."
)
forward, t+lag for reverse."
)
...
@@ -312,10 +316,30 @@ flags.DEFINE_boolean("do_train_io_only", DO_TRAIN_IO_ONLY,
...
@@ -312,10 +316,30 @@ flags.DEFINE_boolean("do_train_io_only", DO_TRAIN_IO_ONLY,
"Train only the input (readin) and output (readout)
\
"Train only the input (readin) and output (readout)
\
affine functions."
)
affine functions."
)
# This flag is used for an experiment where one wants to know if the dynamics
# learned by the generator generalize across conditions. In that case, you might
# train up a model on one set of data, and then only further train the encoder on
# another set of data (the conditions to be tested) so that the model is forced
# to use the same dynamics to describe that data.
# If you don't care about that particular experiment, this flag should always be
# false.
flags
.
DEFINE_boolean
(
"do_train_encoder_only"
,
DO_TRAIN_ENCODER_ONLY
,
"Train only the encoder weights."
)
flags
.
DEFINE_boolean
(
"do_reset_learning_rate"
,
DO_RESET_LEARNING_RATE
,
flags
.
DEFINE_boolean
(
"do_reset_learning_rate"
,
DO_RESET_LEARNING_RATE
,
"Reset the learning rate to initial value."
)
"Reset the learning rate to initial value."
)
# for multi-session "stitching" models, the per-session readin matrices map from
# neurons to input factors which are fed into the shared encoder. These are
# initialized by alignment_matrix_cxf and alignment_bias_c in the input .h5
# files. They can be fixed or made trainable.
flags
.
DEFINE_boolean
(
"do_train_readin"
,
DO_TRAIN_READIN
,
"Whether to train the
\
readin matrices and bias vectors. False leaves them fixed
\
at their initial values specified by the alignment
\
matrices and vectors."
)
# OVERFITTING
# OVERFITTING
# Dropout is done on the input data, on controller inputs (from
# Dropout is done on the input data, on controller inputs (from
# encoder), on outputs from generator to factors.
# encoder), on outputs from generator to factors.
...
@@ -429,7 +453,9 @@ def build_model(hps, kind="train", datasets=None):
...
@@ -429,7 +453,9 @@ def build_model(hps, kind="train", datasets=None):
"write_model_params"
]:
"write_model_params"
]:
print
(
"Possible error!!! You are running "
,
kind
,
" on a newly
\
print
(
"Possible error!!! You are running "
,
kind
,
" on a newly
\
initialized model!"
)
initialized model!"
)
print
(
"Are you sure you sure "
,
ckpt
.
model_checkpoint_path
,
" exists?"
)
# cant print ckpt.model_check_point path if no ckpt
print
(
"Are you sure you sure a checkpoint in "
,
hps
.
lfads_save_dir
,
" exists?"
)
tf
.
global_variables_initializer
().
run
()
tf
.
global_variables_initializer
().
run
()
...
@@ -451,7 +477,7 @@ def jsonify_dict(d):
...
@@ -451,7 +477,7 @@ def jsonify_dict(d):
Creates a shallow-copied dictionary first, then accomplishes string
Creates a shallow-copied dictionary first, then accomplishes string
conversion.
conversion.
Args:
Args:
d: hyperparameter dictionary
d: hyperparameter dictionary
Returns: hyperparameter dictionary with bool's as strings
Returns: hyperparameter dictionary with bool's as strings
...
@@ -535,7 +561,9 @@ def build_hyperparameter_dict(flags):
...
@@ -535,7 +561,9 @@ def build_hyperparameter_dict(flags):
d
[
'max_grad_norm'
]
=
flags
.
max_grad_norm
d
[
'max_grad_norm'
]
=
flags
.
max_grad_norm
d
[
'cell_clip_value'
]
=
flags
.
cell_clip_value
d
[
'cell_clip_value'
]
=
flags
.
cell_clip_value
d
[
'do_train_io_only'
]
=
flags
.
do_train_io_only
d
[
'do_train_io_only'
]
=
flags
.
do_train_io_only
d
[
'do_train_encoder_only'
]
=
flags
.
do_train_encoder_only
d
[
'do_reset_learning_rate'
]
=
flags
.
do_reset_learning_rate
d
[
'do_reset_learning_rate'
]
=
flags
.
do_reset_learning_rate
d
[
'do_train_readin'
]
=
flags
.
do_train_readin
# Overfitting
# Overfitting
d
[
'keep_prob'
]
=
flags
.
keep_prob
d
[
'keep_prob'
]
=
flags
.
keep_prob
...
@@ -659,7 +687,7 @@ def write_model_parameters(hps, output_fname=None, datasets=None):
...
@@ -659,7 +687,7 @@ def write_model_parameters(hps, output_fname=None, datasets=None):
fname
=
os
.
path
.
join
(
hps
.
lfads_save_dir
,
output_fname
)
fname
=
os
.
path
.
join
(
hps
.
lfads_save_dir
,
output_fname
)
print
(
"Writing model parameters to: "
,
fname
)
print
(
"Writing model parameters to: "
,
fname
)
# save the optimizer params as well
# save the optimizer params as well
model
=
build_model
(
hps
,
kind
=
"write_model_params"
,
datasets
=
datasets
)
model
=
build_model
(
hps
,
kind
=
"write_model_params"
,
datasets
=
datasets
)
model_params
=
model
.
eval_model_parameters
(
use_nested
=
False
,
model_params
=
model
.
eval_model_parameters
(
use_nested
=
False
,
include_strs
=
"LFADS"
)
include_strs
=
"LFADS"
)
utils
.
write_data
(
fname
,
model_params
,
compression
=
None
)
utils
.
write_data
(
fname
,
model_params
,
compression
=
None
)
...
@@ -775,4 +803,3 @@ def main(_):
...
@@ -775,4 +803,3 @@ def main(_):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
tf
.
app
.
run
()
tf
.
app
.
run
()
research/lfads/synth_data/generate_itb_data.py
View file @
c173234f
...
@@ -39,7 +39,7 @@ flags.DEFINE_integer("C", 800, "Number of conditions")
...
@@ -39,7 +39,7 @@ flags.DEFINE_integer("C", 800, "Number of conditions")
flags
.
DEFINE_integer
(
"N"
,
50
,
"Number of units for the RNN"
)
flags
.
DEFINE_integer
(
"N"
,
50
,
"Number of units for the RNN"
)
flags
.
DEFINE_float
(
"train_percentage"
,
4.0
/
5.0
,
flags
.
DEFINE_float
(
"train_percentage"
,
4.0
/
5.0
,
"Percentage of train vs validation trials"
)
"Percentage of train vs validation trials"
)
flags
.
DEFINE_integer
(
"n
spikif
ications"
,
5
,
flags
.
DEFINE_integer
(
"n
repl
ications"
,
5
,
"Number of spikifications of the same underlying rates."
)
"Number of spikifications of the same underlying rates."
)
flags
.
DEFINE_float
(
"tau"
,
0.025
,
"Time constant of RNN"
)
flags
.
DEFINE_float
(
"tau"
,
0.025
,
"Time constant of RNN"
)
flags
.
DEFINE_float
(
"dt"
,
0.010
,
"Time bin"
)
flags
.
DEFINE_float
(
"dt"
,
0.010
,
"Time bin"
)
...
@@ -90,8 +90,8 @@ u_rng = np.random.RandomState(seed=FLAGS.synth_data_seed+1)
...
@@ -90,8 +90,8 @@ u_rng = np.random.RandomState(seed=FLAGS.synth_data_seed+1)
T
=
FLAGS
.
T
T
=
FLAGS
.
T
C
=
FLAGS
.
C
C
=
FLAGS
.
C
N
=
FLAGS
.
N
# must be same N as in trained model (provided example is N = 50)
N
=
FLAGS
.
N
# must be same N as in trained model (provided example is N = 50)
n
spikif
ications
=
FLAGS
.
n
spikif
ications
n
repl
ications
=
FLAGS
.
n
repl
ications
E
=
n
spikif
ications
*
C
# total number of trials
E
=
n
repl
ications
*
C
# total number of trials
train_percentage
=
FLAGS
.
train_percentage
train_percentage
=
FLAGS
.
train_percentage
ntimesteps
=
int
(
T
/
FLAGS
.
dt
)
ntimesteps
=
int
(
T
/
FLAGS
.
dt
)
batch_size
=
1
# gives one example per ntrial
batch_size
=
1
# gives one example per ntrial
...
@@ -144,7 +144,7 @@ with tf.Session() as sess:
...
@@ -144,7 +144,7 @@ with tf.Session() as sess:
outputs_t_bxn
=
np
.
squeeze
(
np
.
asarray
(
outputs_t_bxn
))
outputs_t_bxn
=
np
.
squeeze
(
np
.
asarray
(
outputs_t_bxn
))
r_sxt
=
np
.
dot
(
P_nxn
,
states_nxt
)
r_sxt
=
np
.
dot
(
P_nxn
,
states_nxt
)
for
s
in
xrange
(
n
spikif
ications
):
for
s
in
xrange
(
n
repl
ications
):
data_e
.
append
(
r_sxt
)
data_e
.
append
(
r_sxt
)
u_e
.
append
(
u_1xt
)
u_e
.
append
(
u_1xt
)
outs_e
.
append
(
outputs_t_bxn
)
outs_e
.
append
(
outputs_t_bxn
)
...
@@ -154,7 +154,7 @@ with tf.Session() as sess:
...
@@ -154,7 +154,7 @@ with tf.Session() as sess:
spiking_data_e
=
spikify_data
(
truth_data_e
,
rng
,
dt
=
FLAGS
.
dt
,
spiking_data_e
=
spikify_data
(
truth_data_e
,
rng
,
dt
=
FLAGS
.
dt
,
max_firing_rate
=
FLAGS
.
max_firing_rate
)
max_firing_rate
=
FLAGS
.
max_firing_rate
)
train_inds
,
valid_inds
=
get_train_n_valid_inds
(
E
,
train_percentage
,
train_inds
,
valid_inds
=
get_train_n_valid_inds
(
E
,
train_percentage
,
n
spikif
ications
)
n
repl
ications
)
data_train_truth
,
data_valid_truth
=
split_list_by_inds
(
truth_data_e
,
data_train_truth
,
data_valid_truth
=
split_list_by_inds
(
truth_data_e
,
train_inds
,
train_inds
,
...
@@ -188,7 +188,7 @@ data = { 'train_truth': data_train_truth,
...
@@ -188,7 +188,7 @@ data = { 'train_truth': data_train_truth,
'train_data'
:
data_train_spiking
,
'train_data'
:
data_train_spiking
,
'valid_data'
:
data_valid_spiking
,
'valid_data'
:
data_valid_spiking
,
'train_percentage'
:
train_percentage
,
'train_percentage'
:
train_percentage
,
'n
spikif
ications'
:
n
spikif
ications
,
'n
repl
ications'
:
n
repl
ications
,
'dt'
:
FLAGS
.
dt
,
'dt'
:
FLAGS
.
dt
,
'u_std'
:
FLAGS
.
u_std
,
'u_std'
:
FLAGS
.
u_std
,
'max_firing_rate'
:
FLAGS
.
max_firing_rate
,
'max_firing_rate'
:
FLAGS
.
max_firing_rate
,
...
...
research/lfads/synth_data/generate_labeled_rnn_data.py
View file @
c173234f
...
@@ -40,7 +40,7 @@ flags.DEFINE_integer("C", 400, "Number of conditions")
...
@@ -40,7 +40,7 @@ flags.DEFINE_integer("C", 400, "Number of conditions")
flags
.
DEFINE_integer
(
"N"
,
50
,
"Number of units for the RNN"
)
flags
.
DEFINE_integer
(
"N"
,
50
,
"Number of units for the RNN"
)
flags
.
DEFINE_float
(
"train_percentage"
,
4.0
/
5.0
,
flags
.
DEFINE_float
(
"train_percentage"
,
4.0
/
5.0
,
"Percentage of train vs validation trials"
)
"Percentage of train vs validation trials"
)
flags
.
DEFINE_integer
(
"n
spikif
ications"
,
10
,
flags
.
DEFINE_integer
(
"n
repl
ications"
,
10
,
"Number of spikifications of the same underlying rates."
)
"Number of spikifications of the same underlying rates."
)
flags
.
DEFINE_float
(
"g"
,
1.5
,
"Complexity of dynamics"
)
flags
.
DEFINE_float
(
"g"
,
1.5
,
"Complexity of dynamics"
)
flags
.
DEFINE_float
(
"x0_std"
,
1.0
,
flags
.
DEFINE_float
(
"x0_std"
,
1.0
,
...
@@ -56,8 +56,8 @@ rnn_rngs = [np.random.RandomState(seed=FLAGS.synth_data_seed+1),
...
@@ -56,8 +56,8 @@ rnn_rngs = [np.random.RandomState(seed=FLAGS.synth_data_seed+1),
T
=
FLAGS
.
T
T
=
FLAGS
.
T
C
=
FLAGS
.
C
C
=
FLAGS
.
C
N
=
FLAGS
.
N
N
=
FLAGS
.
N
n
spikif
ications
=
FLAGS
.
n
spikif
ications
n
repl
ications
=
FLAGS
.
n
repl
ications
E
=
n
spikif
ications
*
C
E
=
n
repl
ications
*
C
train_percentage
=
FLAGS
.
train_percentage
train_percentage
=
FLAGS
.
train_percentage
ntimesteps
=
int
(
T
/
FLAGS
.
dt
)
ntimesteps
=
int
(
T
/
FLAGS
.
dt
)
...
@@ -77,8 +77,8 @@ condition_labels = []
...
@@ -77,8 +77,8 @@ condition_labels = []
condition_number
=
0
condition_number
=
0
for
c
in
range
(
C
):
for
c
in
range
(
C
):
x0
=
FLAGS
.
x0_std
*
rng
.
randn
(
N
,
1
)
x0
=
FLAGS
.
x0_std
*
rng
.
randn
(
N
,
1
)
x0s
.
append
(
np
.
tile
(
x0
,
n
spikif
ications
))
x0s
.
append
(
np
.
tile
(
x0
,
n
repl
ications
))
for
ns
in
range
(
n
spikif
ications
):
for
ns
in
range
(
n
repl
ications
):
condition_labels
.
append
(
condition_number
)
condition_labels
.
append
(
condition_number
)
condition_number
+=
1
condition_number
+=
1
x0s
=
np
.
concatenate
(
x0s
,
axis
=
1
)
x0s
=
np
.
concatenate
(
x0s
,
axis
=
1
)
...
@@ -107,7 +107,7 @@ for trial in xrange(E):
...
@@ -107,7 +107,7 @@ for trial in xrange(E):
# split into train and validation sets
# split into train and validation sets
train_inds
,
valid_inds
=
get_train_n_valid_inds
(
E
,
train_percentage
,
train_inds
,
valid_inds
=
get_train_n_valid_inds
(
E
,
train_percentage
,
n
spikif
ications
)
n
repl
ications
)
rates_train
,
rates_valid
=
split_list_by_inds
(
rates
,
train_inds
,
valid_inds
)
rates_train
,
rates_valid
=
split_list_by_inds
(
rates
,
train_inds
,
valid_inds
)
spikes_train
,
spikes_valid
=
split_list_by_inds
(
spikes
,
train_inds
,
valid_inds
)
spikes_train
,
spikes_valid
=
split_list_by_inds
(
spikes
,
train_inds
,
valid_inds
)
...
@@ -129,7 +129,7 @@ data = {'train_truth': rates_train,
...
@@ -129,7 +129,7 @@ data = {'train_truth': rates_train,
'train_ext_input'
:
np
.
array
(
ext_input_train
),
'train_ext_input'
:
np
.
array
(
ext_input_train
),
'valid_ext_input'
:
np
.
array
(
ext_input_valid
),
'valid_ext_input'
:
np
.
array
(
ext_input_valid
),
'train_percentage'
:
train_percentage
,
'train_percentage'
:
train_percentage
,
'n
spikif
ications'
:
n
spikif
ications
,
'n
repl
ications'
:
n
repl
ications
,
'dt'
:
FLAGS
.
dt
,
'dt'
:
FLAGS
.
dt
,
'P_sxn'
:
P_nxn
,
'P_sxn'
:
P_nxn
,
'condition_labels_train'
:
condition_labels_train
,
'condition_labels_train'
:
condition_labels_train
,
...
...
research/lfads/synth_data/run_generate_synth_data.sh
View file @
c173234f
...
@@ -19,22 +19,22 @@
...
@@ -19,22 +19,22 @@
SYNTH_PATH
=
/tmp/rnn_synth_data_v1.0/
SYNTH_PATH
=
/tmp/rnn_synth_data_v1.0/
echo
"Generating chaotic rnn data with no input pulses (g=1.5) with spiking noise"
echo
"Generating chaotic rnn data with no input pulses (g=1.5) with spiking noise"
python generate_chaotic_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
chaotic_rnn_no_inputs
--synth_data_seed
=
5
--T
=
1.0
--C
=
400
--N
=
50
--S
=
50
--train_percentage
=
0.8
--n
spikif
ications
=
10
--g
=
1.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--input_magnitude
=
0.0
--max_firing_rate
=
30.0
--noise_type
=
'poisson'
python generate_chaotic_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
chaotic_rnn_no_inputs
--synth_data_seed
=
5
--T
=
1.0
--C
=
400
--N
=
50
--S
=
50
--train_percentage
=
0.8
--n
repl
ications
=
10
--g
=
1.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--input_magnitude
=
0.0
--max_firing_rate
=
30.0
--noise_type
=
'poisson'
echo
"Generating chaotic rnn data with no input pulses (g=1.5) with Gaussian noise"
echo
"Generating chaotic rnn data with no input pulses (g=1.5) with Gaussian noise"
python generate_chaotic_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
chaotic_rnn_no_inputs
_gaussian
--synth_data_seed
=
5
--T
=
1.0
--C
=
400
--N
=
50
--S
=
50
--train_percentage
=
0.8
--n
spikif
ications
=
10
--g
=
1.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--input_magnitude
=
0.0
--max_firing_rate
=
30.0
--noise_type
=
'gaussian'
python generate_chaotic_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
gaussian_
chaotic_rnn_no_inputs
--synth_data_seed
=
5
--T
=
1.0
--C
=
400
--N
=
50
--S
=
50
--train_percentage
=
0.8
--n
repl
ications
=
10
--g
=
1.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--input_magnitude
=
0.0
--max_firing_rate
=
30.0
--noise_type
=
'gaussian'
echo
"Generating chaotic rnn data with input pulses (g=1.5)"
echo
"Generating chaotic rnn data with input pulses (g=1.5)"
python generate_chaotic_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
chaotic_rnn_inputs_g1p5
--synth_data_seed
=
5
--T
=
1.0
--C
=
400
--N
=
50
--S
=
50
--train_percentage
=
0.8
--n
spikif
ications
=
10
--g
=
1.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--input_magnitude
=
20.0
--max_firing_rate
=
30.0
--noise_type
=
'poisson'
python generate_chaotic_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
chaotic_rnn_inputs_g1p5
--synth_data_seed
=
5
--T
=
1.0
--C
=
400
--N
=
50
--S
=
50
--train_percentage
=
0.8
--n
repl
ications
=
10
--g
=
1.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--input_magnitude
=
20.0
--max_firing_rate
=
30.0
--noise_type
=
'poisson'
echo
"Generating chaotic rnn data with input pulses (g=2.5)"
echo
"Generating chaotic rnn data with input pulses (g=2.5)"
python generate_chaotic_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
chaotic_rnn_inputs_g2p5
--synth_data_seed
=
5
--T
=
1.0
--C
=
400
--N
=
50
--S
=
50
--train_percentage
=
0.8
--n
spikif
ications
=
10
--g
=
2.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--input_magnitude
=
20.0
--max_firing_rate
=
30.0
--noise_type
=
'poisson'
python generate_chaotic_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
chaotic_rnn_inputs_g2p5
--synth_data_seed
=
5
--T
=
1.0
--C
=
400
--N
=
50
--S
=
50
--train_percentage
=
0.8
--n
repl
ications
=
10
--g
=
2.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--input_magnitude
=
20.0
--max_firing_rate
=
30.0
--noise_type
=
'poisson'
echo
"Generate the multi-session RNN data (no multi-session synth example in paper)"
echo
"Generate the multi-session RNN data (no multi-session synth example in paper)"
python generate_chaotic_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
chaotic_rnn_multisession
--synth_data_seed
=
5
--T
=
1.0
--C
=
150
--N
=
100
--S
=
20
--npcs
=
10
--train_percentage
=
0.8
--n
spikif
ications
=
40
--g
=
1.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--input_magnitude
=
0.0
--max_firing_rate
=
30.0
--noise_type
=
'poisson'
python generate_chaotic_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
chaotic_rnn_multisession
--synth_data_seed
=
5
--T
=
1.0
--C
=
150
--N
=
100
--S
=
20
--npcs
=
10
--train_percentage
=
0.8
--n
repl
ications
=
40
--g
=
1.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--input_magnitude
=
0.0
--max_firing_rate
=
30.0
--noise_type
=
'poisson'
echo
"Generating Integration-to-bound RNN data"
echo
"Generating Integration-to-bound RNN data"
python generate_itb_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
itb_rnn
--u_std
=
0.25
--checkpoint_path
=
SAMPLE_CHECKPOINT
--synth_data_seed
=
5
--T
=
1.0
--C
=
800
--N
=
50
--train_percentage
=
0.8
--n
spikif
ications
=
5
--tau
=
0.025
--dt
=
0.01
--max_firing_rate
=
30.0
python generate_itb_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
itb_rnn
--u_std
=
0.25
--checkpoint_path
=
SAMPLE_CHECKPOINT
--synth_data_seed
=
5
--T
=
1.0
--C
=
800
--N
=
50
--train_percentage
=
0.8
--n
repl
ications
=
5
--tau
=
0.025
--dt
=
0.01
--max_firing_rate
=
30.0
echo
"Generating chaotic rnn data with external input labels (no external input labels example in paper)"
echo
"Generating chaotic rnn data with external input labels (no external input labels example in paper)"
python generate_labeled_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
chaotic_rnns_labeled
--synth_data_seed
=
5
--T
=
1.0
--C
=
400
--N
=
50
--train_percentage
=
0.8
--n
spikif
ications
=
10
--g
=
1.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--max_firing_rate
=
30.0
python generate_labeled_rnn_data.py
--save_dir
=
$SYNTH_PATH
--datafile_name
=
chaotic_rnns_labeled
--synth_data_seed
=
5
--T
=
1.0
--C
=
400
--N
=
50
--train_percentage
=
0.8
--n
repl
ications
=
10
--g
=
1.5
--x0_std
=
1.0
--tau
=
0.025
--dt
=
0.01
--max_firing_rate
=
30.0
research/lfads/synth_data/synthetic_data_utils.py
View file @
c173234f
...
@@ -176,13 +176,13 @@ def gaussify_data(data_e, rng, dt=1.0, max_firing_rate=100):
...
@@ -176,13 +176,13 @@ def gaussify_data(data_e, rng, dt=1.0, max_firing_rate=100):
def
get_train_n_valid_inds
(
num_trials
,
train_fraction
,
n
spikif
ications
):
def
get_train_n_valid_inds
(
num_trials
,
train_fraction
,
n
repl
ications
):
"""Split the numbers between 0 and num_trials-1 into two portions for
"""Split the numbers between 0 and num_trials-1 into two portions for
training and validation, based on the train fraction.
training and validation, based on the train fraction.
Args:
Args:
num_trials: the number of trials
num_trials: the number of trials
train_fraction: (e.g. .80)
train_fraction: (e.g. .80)
n
spikif
ications: the number of spiking trials per initial condition
n
repl
ications: the number of spiking trials per initial condition
Returns:
Returns:
a 2-tuple of two lists: the training indices and validation indices
a 2-tuple of two lists: the training indices and validation indices
"""
"""
...
@@ -192,7 +192,7 @@ def get_train_n_valid_inds(num_trials, train_fraction, nspikifications):
...
@@ -192,7 +192,7 @@ def get_train_n_valid_inds(num_trials, train_fraction, nspikifications):
# This line divides up the trials so that within one initial condition,
# This line divides up the trials so that within one initial condition,
# the randomness of spikifying the condition is shared among both
# the randomness of spikifying the condition is shared among both
# training and validation data splits.
# training and validation data splits.
if
(
i
%
n
spikif
ications
)
+
1
>
train_fraction
*
n
spikif
ications
:
if
(
i
%
n
repl
ications
)
+
1
>
train_fraction
*
n
repl
ications
:
valid_inds
.
append
(
i
)
valid_inds
.
append
(
i
)
else
:
else
:
train_inds
.
append
(
i
)
train_inds
.
append
(
i
)
...
...
research/lfads/utils.py
View file @
c173234f
...
@@ -84,14 +84,15 @@ def linear(x, out_size, do_bias=True, alpha=1.0, identity_if_possible=False,
...
@@ -84,14 +84,15 @@ def linear(x, out_size, do_bias=True, alpha=1.0, identity_if_possible=False,
def
init_linear
(
in_size
,
out_size
,
do_bias
=
True
,
mat_init_value
=
None
,
def
init_linear
(
in_size
,
out_size
,
do_bias
=
True
,
mat_init_value
=
None
,
bias_init_value
=
None
,
alpha
=
1.0
,
identity_if_possible
=
False
,
bias_init_value
=
None
,
alpha
=
1.0
,
identity_if_possible
=
False
,
normalized
=
False
,
name
=
None
,
collections
=
None
):
normalized
=
False
,
name
=
None
,
collections
=
None
,
trainable
=
True
):
"""Linear (affine) transformation, y = x W + b, for a variety of
"""Linear (affine) transformation, y = x W + b, for a variety of
configurations.
configurations.
Args:
Args:
in_size: The integer size of the non-batc input dimension. [(x),y]
in_size: The integer size of the non-batc input dimension. [(x),y]
out_size: The integer size of non-batch output dimension. [x,(y)]
out_size: The integer size of non-batch output dimension. [x,(y)]
do_bias (optional): Add a learnable bias vector to the operation.
do_bias (optional): Add a (learnable) bias vector to the operation,
if false, b will be None
mat_init_value (optional): numpy constant for matrix initialization, if None
mat_init_value (optional): numpy constant for matrix initialization, if None
, do random, with additional parameters.
, do random, with additional parameters.
alpha (optional): A multiplicative scaling for the weight initialization
alpha (optional): A multiplicative scaling for the weight initialization
...
@@ -131,21 +132,22 @@ def init_linear(in_size, out_size, do_bias=True, mat_init_value=None,
...
@@ -131,21 +132,22 @@ def init_linear(in_size, out_size, do_bias=True, mat_init_value=None,
if
collections
:
if
collections
:
w_collections
+=
collections
w_collections
+=
collections
if
mat_init_value
is
not
None
:
if
mat_init_value
is
not
None
:
w
=
tf
.
Variable
(
mat_init_value
,
name
=
wname
,
collections
=
w_collections
)
w
=
tf
.
Variable
(
mat_init_value
,
name
=
wname
,
collections
=
w_collections
,
trainable
=
trainable
)
else
:
else
:
w
=
tf
.
get_variable
(
wname
,
[
in_size
,
out_size
],
initializer
=
mat_init
,
w
=
tf
.
get_variable
(
wname
,
[
in_size
,
out_size
],
initializer
=
mat_init
,
collections
=
w_collections
)
collections
=
w_collections
,
trainable
=
trainable
)
w
=
tf
.
nn
.
l2_normalize
(
w
,
dim
=
0
)
# x W, so xW_j = \sum_i x_bi W_ij
w
=
tf
.
nn
.
l2_normalize
(
w
,
dim
=
0
)
# x W, so xW_j = \sum_i x_bi W_ij
else
:
else
:
w_collections
=
[
tf
.
GraphKeys
.
GLOBAL_VARIABLES
]
w_collections
=
[
tf
.
GraphKeys
.
GLOBAL_VARIABLES
]
if
collections
:
if
collections
:
w_collections
+=
collections
w_collections
+=
collections
if
mat_init_value
is
not
None
:
if
mat_init_value
is
not
None
:
w
=
tf
.
Variable
(
mat_init_value
,
name
=
wname
,
collections
=
w_collections
)
w
=
tf
.
Variable
(
mat_init_value
,
name
=
wname
,
collections
=
w_collections
,
trainable
=
trainable
)
else
:
else
:
w
=
tf
.
get_variable
(
wname
,
[
in_size
,
out_size
],
initializer
=
mat_init
,
w
=
tf
.
get_variable
(
wname
,
[
in_size
,
out_size
],
initializer
=
mat_init
,
collections
=
w_collections
)
collections
=
w_collections
,
trainable
=
trainable
)
b
=
None
b
=
None
if
do_bias
:
if
do_bias
:
b_collections
=
[
tf
.
GraphKeys
.
GLOBAL_VARIABLES
]
b_collections
=
[
tf
.
GraphKeys
.
GLOBAL_VARIABLES
]
...
@@ -155,11 +157,12 @@ def init_linear(in_size, out_size, do_bias=True, mat_init_value=None,
...
@@ -155,11 +157,12 @@ def init_linear(in_size, out_size, do_bias=True, mat_init_value=None,
if
bias_init_value
is
None
:
if
bias_init_value
is
None
:
b
=
tf
.
get_variable
(
bname
,
[
1
,
out_size
],
b
=
tf
.
get_variable
(
bname
,
[
1
,
out_size
],
initializer
=
tf
.
zeros_initializer
(),
initializer
=
tf
.
zeros_initializer
(),
collections
=
b_collections
)
collections
=
b_collections
,
trainable
=
trainable
)
else
:
else
:
b
=
tf
.
Variable
(
bias_init_value
,
name
=
bname
,
b
=
tf
.
Variable
(
bias_init_value
,
name
=
bname
,
collections
=
b_collections
)
collections
=
b_collections
,
trainable
=
trainable
)
return
(
w
,
b
)
return
(
w
,
b
)
...
...
research/object_detection/g3doc/installation.md
View file @
c173234f
...
@@ -4,14 +4,15 @@
...
@@ -4,14 +4,15 @@
Tensorflow Object Detection API depends on the following libraries:
Tensorflow Object Detection API depends on the following libraries:
*
Protobuf 2.6
*
Protobuf 2.6
*
Pillow 1.0
*
Python-tk
*
lxml
*
Pillow 1.0
*
tf Slim (which is included in the "tensorflow/models/research/" checkout)
*
lxml
*
Jupyter notebook
*
tf Slim (which is included in the "tensorflow/models/research/" checkout)
*
Matplotlib
*
Jupyter notebook
*
Tensorflow
*
Matplotlib
*
cocoapi
*
Tensorflow
*
cocoapi
For detailed steps to install Tensorflow, follow the
[
Tensorflow installation
For detailed steps to install Tensorflow, follow the
[
Tensorflow installation
instructions
](
https://www.tensorflow.org/install/
)
. A typical user can install
instructions
](
https://www.tensorflow.org/install/
)
. A typical user can install
...
@@ -27,7 +28,7 @@ pip install tensorflow-gpu
...
@@ -27,7 +28,7 @@ pip install tensorflow-gpu
The remaining libraries can be installed on Ubuntu 16.04 using via apt-get:
The remaining libraries can be installed on Ubuntu 16.04 using via apt-get:
```
bash
```
bash
sudo
apt-get
install
protobuf-compiler python-pil python-lxml
sudo
apt-get
install
protobuf-compiler python-pil python-lxml
python-tk
sudo
pip
install
jupyter
sudo
pip
install
jupyter
sudo
pip
install
matplotlib
sudo
pip
install
matplotlib
```
```
...
...
research/tcn/data_providers.py
View file @
c173234f
...
@@ -165,7 +165,7 @@ def parse_sequence_example(serialized_example, num_views):
...
@@ -165,7 +165,7 @@ def parse_sequence_example(serialized_example, num_views):
views
=
tf
.
stack
([
sequence_parse
[
v
]
for
v
in
view_names
])
views
=
tf
.
stack
([
sequence_parse
[
v
]
for
v
in
view_names
])
lens
=
[
sequence_parse
[
v
].
get_shape
().
as_list
()[
0
]
for
v
in
view_names
]
lens
=
[
sequence_parse
[
v
].
get_shape
().
as_list
()[
0
]
for
v
in
view_names
]
assert
len
(
set
(
lens
))
==
1
assert
len
(
set
(
lens
))
==
1
seq_len
=
tf
.
shape
(
sequence_parse
[
v
])[
0
]
seq_len
=
tf
.
shape
(
sequence_parse
[
v
iew_names
[
-
1
]
])[
0
]
return
context_parse
,
views
,
seq_len
return
context_parse
,
views
,
seq_len
...
...
samples/core/get_started/iris_data.py
View file @
c173234f
...
@@ -6,7 +6,7 @@ TEST_URL = "http://download.tensorflow.org/data/iris_test.csv"
...
@@ -6,7 +6,7 @@ TEST_URL = "http://download.tensorflow.org/data/iris_test.csv"
CSV_COLUMN_NAMES
=
[
'SepalLength'
,
'SepalWidth'
,
CSV_COLUMN_NAMES
=
[
'SepalLength'
,
'SepalWidth'
,
'PetalLength'
,
'PetalWidth'
,
'Species'
]
'PetalLength'
,
'PetalWidth'
,
'Species'
]
SPECIES
=
[
'Se
n
tosa'
,
'Versicolor'
,
'Virginica'
]
SPECIES
=
[
'Setosa'
,
'Versicolor'
,
'Virginica'
]
def
maybe_download
():
def
maybe_download
():
train_path
=
tf
.
keras
.
utils
.
get_file
(
TRAIN_URL
.
split
(
'/'
)[
-
1
],
TRAIN_URL
)
train_path
=
tf
.
keras
.
utils
.
get_file
(
TRAIN_URL
.
split
(
'/'
)[
-
1
],
TRAIN_URL
)
...
@@ -35,8 +35,8 @@ def train_input_fn(features, labels, batch_size):
...
@@ -35,8 +35,8 @@ def train_input_fn(features, labels, batch_size):
# Shuffle, repeat, and batch the examples.
# Shuffle, repeat, and batch the examples.
dataset
=
dataset
.
shuffle
(
1000
).
repeat
().
batch
(
batch_size
)
dataset
=
dataset
.
shuffle
(
1000
).
repeat
().
batch
(
batch_size
)
# Return the
read end of the pipeline
.
# Return the
dataset
.
return
dataset
.
make_one_shot_iterator
().
get_next
()
return
dataset
def
eval_input_fn
(
features
,
labels
,
batch_size
):
def
eval_input_fn
(
features
,
labels
,
batch_size
):
...
@@ -55,8 +55,8 @@ def eval_input_fn(features, labels, batch_size):
...
@@ -55,8 +55,8 @@ def eval_input_fn(features, labels, batch_size):
assert
batch_size
is
not
None
,
"batch_size must not be None"
assert
batch_size
is
not
None
,
"batch_size must not be None"
dataset
=
dataset
.
batch
(
batch_size
)
dataset
=
dataset
.
batch
(
batch_size
)
# Return the
read end of the pipeline
.
# Return the
dataset
.
return
dataset
.
make_one_shot_iterator
().
get_next
()
return
dataset
# The remainder of this file contains a simple example of a csv parser,
# The remainder of this file contains a simple example of a csv parser,
...
@@ -89,5 +89,5 @@ def csv_input_fn(csv_path, batch_size):
...
@@ -89,5 +89,5 @@ def csv_input_fn(csv_path, batch_size):
# Shuffle, repeat, and batch the examples.
# Shuffle, repeat, and batch the examples.
dataset
=
dataset
.
shuffle
(
1000
).
repeat
().
batch
(
batch_size
)
dataset
=
dataset
.
shuffle
(
1000
).
repeat
().
batch
(
batch_size
)
# Return the read end of the pipeline.
# Return the dataset.
return
dataset
.
make_one_shot_iterator
().
get_next
()
return
dataset
\ No newline at end of file
tutorials/image/cifar10_estimator/generate_cifar10_tfrecords.py
View file @
c173234f
...
@@ -24,10 +24,10 @@ from __future__ import division
...
@@ -24,10 +24,10 @@ from __future__ import division
from
__future__
import
print_function
from
__future__
import
print_function
import
argparse
import
argparse
import
cPickle
import
os
import
os
import
tarfile
import
tarfile
from
six.moves
import
cPickle
as
pickle
from
six.moves
import
xrange
# pylint: disable=redefined-builtin
from
six.moves
import
xrange
# pylint: disable=redefined-builtin
import
tensorflow
as
tf
import
tensorflow
as
tf
...
@@ -49,7 +49,7 @@ def _int64_feature(value):
...
@@ -49,7 +49,7 @@ def _int64_feature(value):
def
_bytes_feature
(
value
):
def
_bytes_feature
(
value
):
return
tf
.
train
.
Feature
(
bytes_list
=
tf
.
train
.
BytesList
(
value
=
[
str
(
value
)
]))
return
tf
.
train
.
Feature
(
bytes_list
=
tf
.
train
.
BytesList
(
value
=
[
value
]))
def
_get_file_names
():
def
_get_file_names
():
...
@@ -62,8 +62,8 @@ def _get_file_names():
...
@@ -62,8 +62,8 @@ def _get_file_names():
def
read_pickle_from_file
(
filename
):
def
read_pickle_from_file
(
filename
):
with
tf
.
gfile
.
Open
(
filename
,
'r'
)
as
f
:
with
tf
.
gfile
.
Open
(
filename
,
'r
b
'
)
as
f
:
data_dict
=
cP
ickle
.
load
(
f
)
data_dict
=
p
ickle
.
load
(
f
)
return
data_dict
return
data_dict
...
...
tutorials/rnn/ptb/ptb_word_lm.py
View file @
c173234f
...
@@ -225,15 +225,15 @@ class PTBModel(object):
...
@@ -225,15 +225,15 @@ class PTBModel(object):
self
.
_initial_state
=
cell
.
zero_state
(
config
.
batch_size
,
data_type
())
self
.
_initial_state
=
cell
.
zero_state
(
config
.
batch_size
,
data_type
())
state
=
self
.
_initial_state
state
=
self
.
_initial_state
# Simplified version of t
ensorflow_models/tutorials/rnn/rnn.py's
rnn().
# Simplified version of t
f.nn.static_
rnn().
# This builds an unrolled LSTM for tutorial purposes only.
# This builds an unrolled LSTM for tutorial purposes only.
# In general, use t
he rnn() or
state_saving_rnn()
from rnn.py
.
# In general, use t
f.nn.static_rnn() or tf.nn.static_
state_saving_rnn().
#
#
# The alternative version of the code below is:
# The alternative version of the code below is:
#
#
# inputs = tf.unstack(inputs, num=num_steps, axis=1)
# inputs = tf.unstack(inputs, num=
self.
num_steps, axis=1)
# outputs, state = tf.
contrib.r
nn.static_rnn(cell, inputs,
# outputs, state = tf.nn.static_rnn(cell, inputs,
# initial_state=self._initial_state)
#
initial_state=self._initial_state)
outputs
=
[]
outputs
=
[]
with
tf
.
variable_scope
(
"RNN"
):
with
tf
.
variable_scope
(
"RNN"
):
for
time_step
in
range
(
self
.
num_steps
):
for
time_step
in
range
(
self
.
num_steps
):
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment