Tensorflow model for estimating angles from images based on tf.estimator.Estimator
s.
Each model is identified by a model_name
. Parameters are defined in params/model_name.json
. Each model follows a typical convolution > dense layer chain, with optional dropout and batch normalization. The output for each example is either a probability distribution representing confidences of a given angle, or an angle in the range (-pi, pi]
.
estimator.py
: provides theModelBuilder
class for building various parts of the graph, along withget_estimator
andget_model_dir
for use withtf.estimator.Estimator
data.py
: provides data io functions.server.py
: example of how to use for custom predictions. Note this doesn't use tensorflow'sTfServing
, so should be treated as an example only.train.py
: training script.losses.py
: provides losses used.
- Change the
load_data
function indata.py
to something meaningful. Current implementation is random input for debugging purposes. - Define a model by creating a new
.json
file inparams
(or usebase
) - Train:
python train.py my_model_name -b 64 -s 10000000
trains with batch size of 64 and maximum number of steps 10000000.
(conv (-> batch_norm)? -> tf.nn.relu
(-> dropout)?)* -> flatten -> (dense (-> batch_norm)? -> tf.nn.relu
(-> dropout)?)* (-> atan)?
See params/base.json
for an example parameterization of the models.
conv_kernels
: list of ints, e.g. [3, 3, 3]. Kernel size for each convolutional layerconv_filters
: list of ints, e.g. [32, 64, 64]. Number of filters for each convolutional layerpadding
: one of ['VALID', 'SAME']. Used intf.layers.conv2d
andtf.layers.max_pool2d
.dense_nodes
: list of ints, e.g. [1024, 128]. Number dense nodes after convolutional layers and before the final fully connected layer.target
: one of ['angle', 'distribution']. Indicates whether the output of the nextwork should be an angle (in which case the network infers an (x, y) value and calculates the angle viatf.atan2
) or a distribution (seen_bins
).n_bins
: int, only applicable iftarget == 'distribution'
. Number of bins to divide the range(-pi, pi]
into.dropout_rate
: float in [0, 1). Dropout rate used after each convolution/dense layer. Ignored if 0.use_batch_norm
: bool indicating whether or not to use batch_norm. If true, it is applied before the activation (relu
) and dropout.
- Use
cosine
loss - Move dropout to before
batch_norm
- Different activation function (from
tf.nn.relu
) - More convolutions between each
max_pool2d
- Average pooling, or strided convolutional layers.