Exemple #1
0
    flags.DEFINE_string(
        "untar_model_dir", "/tmp/yt8m-model",
        "If --input_model_tgz is given, then this directory will "
        "be created and the contents of the .tgz file will be "
        "untarred here.")

    # Output
    flags.DEFINE_string("output_file", "",
                        "The file to save the predictions to.")
    flags.DEFINE_string(
        "output_model_tgz", "",
        "If given, should be a filename with a .tgz extension, "
        "the model graph and checkpoint will be bundled in this "
        "gzip tar. This file can be uploaded to Kaggle for the "
        "top 10 participants.")
    flags.DEFINE_integer("top_k", 20,
                         "How many predictions to output per video.")

    # Other flags.
    flags.DEFINE_integer("batch_size", 8192,
                         "How many examples to process per batch.")
    flags.DEFINE_integer("num_readers", 1,
                         "How many threads to use for reading input files.")


def format_lines(video_ids, predictions, top_k):
    batch_size = len(video_ids)
    for video_index in range(batch_size):
        top_indices = numpy.argpartition(predictions[video_index],
                                         -top_k)[-top_k:]
        line = [(class_index, predictions[video_index][class_index])
                for class_index in top_indices]
      "If set, then --train_data_pattern must be frame-level features (but with"
      " segment_labels). Otherwise, --train_data_pattern must be aggregated "
      "video-level features. The model must also be set appropriately (i.e. to "
      "read 3D batches VS 4D batches.")
  flags.DEFINE_string(
      "model", "LogisticModel",
      "Which architecture to use for the model. Models are defined "
      "in models.py.")
  flags.DEFINE_bool(
      "start_new_model", False,
      "If set, this will not resume from a checkpoint and will instead create a"
      " new model instance.")

  # Training flags.
  flags.DEFINE_integer(
      "num_gpu", 1, "The maximum number of GPU devices to use for training. "
      "Flag only applies if GPUs are installed")
  flags.DEFINE_integer("batch_size", 1024,
                       "How many examples to process per batch for training.")
  flags.DEFINE_string("label_loss", "CrossEntropyLoss",
                      "Which loss function to use for training the model.")
  flags.DEFINE_float(
      "regularization_penalty", 1.0,
      "How much weight to give to the regularization loss (the label loss has "
      "a weight of 1).")
  flags.DEFINE_float("base_learning_rate", 0.01,
                     "Which learning rate to start with.")
  flags.DEFINE_float(
      "learning_rate_decay", 0.95,
      "Learning rate decay factor to be applied every "
      "learning_rate_decay_examples.")
Exemple #3
0
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Provides readers configured for different datasets."""

import tensorflow as tf
import utils
from tensorflow import flags
FLAGS = flags.FLAGS
flags.DEFINE_integer("max_frames", 300,
                     "frames_size")
flags.DEFINE_bool("diff", False,
                  "differential input?")


def resize_axis(tensor, axis, new_size, fill_value=0):
  """Truncates or pads a tensor to new_size on on a given axis.

  Truncate or extend tensor such that tensor.shape[axis] == new_size. If the
  size increases, the padding will be performed at the end, using fill_value.

  Args:
    tensor: The tensor to be resized.
    axis: An integer representing the dimension to be sliced.
    new_size: An integer or 0d tensor representing the new value for
      tensor.shape[axis].
Exemple #4
0
FLAGS = flags.FLAGS

if __name__ == '__main__':
    flags.DEFINE_string("train_dir", "/tmp/cvd_model/",
                        "The directory to load the model files from.")
    flags.DEFINE_string("output_file", "",
                        "The file to save the predictions to.")
    flags.DEFINE_string(
        "input_data_pattern", "",
        "File glob defining the evaluation dataset in tensorflow.SequenceExample "
        "format. The SequenceExamples are expected to have an 'rgb' byte array "
        "sequence feature as well as a 'labels' int64 context feature.")

    # Other flags.
    flags.DEFINE_integer("num_readers", 1,
                         "How many threads to use for reading input files.")


def format_lines(image_ids, predictions):
    batch_size = len(image_ids)
    predictions = 1.0 * (predictions > .5)
    for video_index in range(batch_size):
        yield image_ids[video_index].decode('utf-8') + "," + (
            "%d" % predictions[video_index]) + "\n"


def get_input_data_tensors(reader, data_pattern, batch_size, num_readers=1):
    """Creates the section of the graph which reads the input data.

  Args:
    reader: A class which parses the input data.
                      "The file to save the predictions to.")
  flags.DEFINE_string(
      "input_data_pattern", "",
      "File glob defining the evaluation dataset in tensorflow.SequenceExample "
      "format. The SequenceExamples are expected to have an 'rgb' byte array "
      "sequence feature as well as a 'labels' kwansoo int64 context feature.")

  # Model flags.
  flags.DEFINE_bool(
      "frame_features", False,
      "If set, then --eval_data_pattern must be frame-level features. "
      "Otherwise, --eval_data_pattern must be aggregated video-level "
      "features. The model must also be set appropriately (i.e. to read 3D "
      "batches VS 4D batches.")
  flags.DEFINE_integer(
      "batch_size", 8192,
      "How many examples to process per batch.")
  flags.DEFINE_string("feature_names", "mean_rgb", "Name of the feature "
                      "to use for training.")
  flags.DEFINE_string("feature_sizes", "1024", "Length of the feature vectors.")


  # Other flags.
  flags.DEFINE_integer("num_readers", 4,
                       "How many threads to use for reading input files.")
  flags.DEFINE_integer("top_k", 500,
                       "How many predictions to output per video.")
  flags.DEFINE_integer("check_point",-1,
                       "Model checkpoint to load, -1 for latest.")

def format_lines(video_ids, predictions, top_k):
Exemple #6
0
        "model", "PolicyGradient",
        "Which architecture to use for the model. Models are defined "
        "in models.py.")

    flags.DEFINE_bool(
        "start_new_model", False,
        "If set, this will not resume from a checkpoint and will instead create a"
        " new model instance.")

    flags.DEFINE_bool(
        "rendering", False,
        "If True, this will render the environment but drastically slow down training"
    )

    flags.DEFINE_integer(
        "export_model_steps", 10,
        "The period, in number of steps, with which the model "
        "is exported for batch prediction.")

    flags.DEFINE_integer("total_episodes", 1000, "Number of episodes")

    flags.DEFINE_integer(
        "batch_size", 100, "Size of batch for models that do parameter "
        "updates in batches")


def find_class_by_name(name, modules):
    """Searches the provided modules for the named class and returns it."""
    modules = [getattr(module, name, None) for module in modules]
    return next(a for a in modules if a)

Exemple #7
0
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file has been modified by Brown Visual Computing Lab / Authors of the accompanying paper Matryodshka

"""Loads video sequence data using the tf Dataset API.

For easiest setup, use create_from_flags, then you won't have to specify any
additional options.
"""
import os.path
import tensorflow as tf
from tensorflow import flags
import datasets

flags.DEFINE_integer('epochs', -1,
                     'Epochs of training data, or -1 to continue indefinitely.')
flags.DEFINE_integer('height', 320, 'Image height in pixels.')
flags.DEFINE_integer('width', 640, 'Image width in pixels.')
flags.DEFINE_integer('hres_height', 2048, 'Image height in pixels.')
flags.DEFINE_integer('hres_width', 4096, 'Image width in pixels.')
flags.DEFINE_integer('min_stride', 3, 'Minimum stride for sequence.')
flags.DEFINE_integer('max_stride', 10, 'Maximum stride for sequence.')
flags.DEFINE_float('augment_min_scale', 1.0,
                   'Minimum scale for data augmentation.')
flags.DEFINE_float('augment_max_scale', 1.15,
                   'Maximum scale for data augmentation.')
flags.DEFINE_integer('batch_size', 1, 'The size of a sample batch.')
FLAGS = flags.FLAGS

# The lambdas in this file are only long because of clear argument names.
# pylint: disable=g-long-lambda
Exemple #8
0
from networks.utils import *
import numpy as np

flags.DEFINE_string("images", "./data/images-train/",
                    "path to training images directory")
flags.DEFINE_string("grasp", "./data/grasp-train/",
                    "path to training grasp data directory")
flags.DEFINE_string("images_test", "./data/images-test/",
                    "path to testing images directory")
flags.DEFINE_string("grasp_test", "./data/grasp_test/",
                    "path to testing grasp data directory")
flags.DEFINE_boolean("train", False, "train the whole net")
flags.DEFINE_string("load", "-1", "load weights from checkpoint")
flags.DEFINE_string("backup", "./backup/", "path to backup folder")
flags.DEFINE_float("lr", 0.001, "learning rate")
flags.DEFINE_integer("seed", 1234, "Random Seed for training")
flags.DEFINE_integer("keep", 10,
                     "Number of most recent training results to save")
flags.DEFINE_integer("batch", 50, "batch size")
flags.DEFINE_integer("epoch", 5000, "number of epoch")
flags.DEFINE_integer("save", 50, "save checkpoint every ? training examples")
flags.DEFINE_string("name", "",
                    "Give a name for better manage your trained profiles")
flags.DEFINE_string("gpu_mode", "cpu", "'cpu','gpu:1','gpu:2'")
FLAGS = flags.FLAGS

try:
    FLAGS.load = int(FLAGS.load)
except:
    pass
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains model definitions."""
import math

import models
import tensorflow as tf
import utils

from tensorflow import flags
import tensorflow.contrib.slim as slim

FLAGS = flags.FLAGS
flags.DEFINE_integer(
    "moe_num_mixtures", 2,
    "The number of mixtures (excluding the dummy 'expert') used for MoeModel.")


class LogisticModel(models.BaseModel):
    """Logistic model with L2 regularization."""
    def create_model(self, model_input, vocab_size, **unused_params):
        """Creates a logistic model.

    Args:
      model_input: 'batch' x 'num_features' matrix of input features.
      vocab_size: The number of classes in the dataset.

    Returns:
      A dictionary with a tensor containing the probability predictions of the
      model in the 'predictions' key. The dimensions of the tensor are
import numpy as np
import tensorflow as tf

from tensorflow import flags

from dcgan import DCGAN
from library.utils import create_path
from library.utils import generate_log_model_dirs

FLAGS = flags.FLAGS
flags.DEFINE_float('d_learning_rate', 0.0002,
                   'Learning rate for discriminator')
flags.DEFINE_float('g_learning_rate', 0.0002, 'Learning rate for generator')
flags.DEFINE_integer('batch_size', 128,
                     'Number of date poitns in each training batch')
flags.DEFINE_float('keep_prob', 0.5, 'For generator dropout layer')
flags.DEFINE_integer('num_epochs', 25, 'Number of epochs for training')
flags.DEFINE_boolean('shuffle', True,
                     'Whether to shuffle the training set for each epoch')
flags.DEFINE_integer(
    'eval_frequency', 20, 'Number of steps between validation set '
    'evaluations or model file updates')
flags.DEFINE_string('root_logdir', './tf_logs/',
                    'Root directory for storing tensorboard logs')
flags.DEFINE_string('root_model_dir', './tf_models/',
                    'Root directory for storing tensorflow models')
flags.DEFINE_integer('random_state', 666, 'Random state or seed')
flags.DEFINE_float('beta1', 0.5, 'beta1 for AdamOptimizer')
flags.DEFINE_string('data_nm', 'mnist', 'Select from mnist and celeba')
flags.DEFINE_integer('noise_len', 100, 'Length of noise vector')
flags.DEFINE_integer('sample_freq', 100,
Exemple #11
0
    # Dataset flags.
    flags.DEFINE_string(
        "train_dir", "/tmp/mnist_model/",
        "The directory to load the model files from. "
        "The tensorboard metrics files are also saved to this "
        "directory.")
    flags.DEFINE_string(
        "eval_data_pattern", "",
        "File glob defining the evaluation dataset in tensorflow.SequenceExample "
        "format. The SequenceExamples are expected to have an 'rgb' byte array "
        "sequence feature as well as a 'labels' int64 context feature.")

    flags.DEFINE_string("model", "LogisticModel",
                        "Which Model to use: see mnist_models.py")

    flags.DEFINE_integer("batch_size", 512,
                         "How many examples to process per batch.")

    flags.DEFINE_string("label_loss", "CrossEntropyLoss",
                        "Loss computed on validation data")

    # Other flags.
    flags.DEFINE_integer("num_readers", 8,
                         "How many threads to use for reading input files.")

    flags.DEFINE_boolean("run_once", False, "Whether to run eval only once.")


def find_class_by_name(name, modules):
    """Searches the provided modules for the named class and returns it."""
    modules = [getattr(module, name, None) for module in modules]
    return next(a for a in modules if a)