Beispiel #1
0
    'update_lr', 1e-3,
    'step size alpha for inner gradient update.')  # 0.1 for omniglot
flags.DEFINE_integer('num_updates', 1,
                     'number of inner gradient updates during training.')
flags.DEFINE_integer(
    'sine_seed', '1',
    'seed for the random operations inside sine generator; sinuosidal regression expt'
)

## Model options
flags.DEFINE_string('norm', 'batch_norm', 'batch_norm, layer_norm, or None')
flags.DEFINE_integer(
    'num_filters', 64,
    'number of filters for conv nets -- 32 for miniimagenet, 64 for omiglot.')
flags.DEFINE_bool(
    'conv', True,
    'whether or not to use a convolutional network, only applicable in some cases'
)
flags.DEFINE_bool(
    'max_pool', False,
    'Whether or not to use max pooling rather than strided convolutions')
flags.DEFINE_bool(
    'stop_grad', False,
    'if True, do not use second derivatives in meta-optimization (for speed)')

## Logging, saving, and testing options
flags.DEFINE_bool('log', True,
                  'if false, do not log summaries, for debugging code.')
flags.DEFINE_string('logdir', '/tmp/data',
                    'directory for summaries and checkpoints.')
flags.DEFINE_bool('resume', True,
                  'resume training if there is a model available')
    'V': 99.06841,
    'Y': 163.06333,
    'M(ox)': 147.035405,
    'groupCH3': 14.01565,
    'groupOH': 17.00274,
    'groupH': 1.007825,
    'groupH2O': 18.01057,
    'groupCH3CO': 42.01057,
    'groupO': 15.994915,
    'groupNH3': 17.02655
}

FLAGS = flags.FLAGS
flags.DEFINE_string('input_data', '', 'Input data filepath.')
flags.DEFINE_string('output_data_dir', '', 'Input data filepath.')
flags.DEFINE_bool('clean_peptides', False,
                  'True if peptide modifications are in [x] format.')
flags.DEFINE_string('sequence_col', _MOD_SEQUENCE,
                    'Modified sequence column name in the input file.')
flags.DEFINE_string('charge_col', _CHARGE,
                    'Charge column name in the input file.')
flags.DEFINE_string('fragmentation_col', _FRAGMENTATION,
                    'Fragmentation column name in the input file.')
flags.DEFINE_string('analyzer_col', _MASS_ANALYZER,
                    'Mass analyzer column name in the input file.')


def generate_json_inputs(data, encoding):
    """Generates inputs to-be stored into a JSON file.

  Args:
    data: A pandas dataframe with modified sequence and metadata features.
Beispiel #3
0
def define():
    """Define common flags."""
    # yapf: disable
    # common_flags.define() may be called multiple times in unit tests.
    global _common_flags_defined
    if _common_flags_defined:
        return
    _common_flags_defined = True

    flags.DEFINE_integer('batch_size', 32,
                         'Batch size.')

    flags.DEFINE_integer('crop_width', None,
                         'Width of the central crop for images.')

    flags.DEFINE_integer('crop_height', None,
                         'Height of the central crop for images.')

    flags.DEFINE_string('train_log_dir', '/tmp/attention_ocr/train',
                        'Directory where to write event logs.')

    flags.DEFINE_string('dataset_name', 'fsns',
                        'Name of the dataset. Supported: fsns')

    flags.DEFINE_string('split_name', 'train',
                        'Dataset split name to run evaluation for: test,train.')

    flags.DEFINE_string('dataset_dir', None,
                        'Dataset root folder.')

    flags.DEFINE_string('checkpoint', '',
                        'Path for checkpoint to restore weights from.')

    flags.DEFINE_string('master',
                        '',
                        'BNS name of the TensorFlow master to use.')

    # Model hyper parameters
    flags.DEFINE_float('learning_rate', 0.004,
                       'learning rate')

    flags.DEFINE_string('optimizer', 'momentum',
                        'the optimizer to use')

    flags.DEFINE_float('momentum', 0.9,
                       'momentum value for the momentum optimizer if used')

    flags.DEFINE_bool('use_augment_input', True,
                      'If True will use image augmentation')

    # Method hyper parameters
    # conv_tower_fn
    flags.DEFINE_string('final_endpoint', 'Mixed_5d',
                        'Endpoint to cut inception tower')

    # sequence_logit_fn
    flags.DEFINE_bool('use_attention', True,
                      'If True will use the attention mechanism')

    flags.DEFINE_bool('use_autoregression', True,
                      'If True will use autoregression (a feedback link)')

    flags.DEFINE_integer('num_lstm_units', 256,
                         'number of LSTM units for sequence LSTM')

    flags.DEFINE_float('weight_decay', 0.00004,
                       'weight decay for char prediction FC layers')

    flags.DEFINE_float('lstm_state_clip_value', 10.0,
                       'cell state is clipped by this value prior to the cell'
                       ' output activation')

    # 'sequence_loss_fn'
    flags.DEFINE_float('label_smoothing', 0.1,
                       'weight for label smoothing')

    flags.DEFINE_bool('ignore_nulls', True,
                      'ignore null characters for computing the loss')

    flags.DEFINE_bool('average_across_timesteps', False,
                      'divide the returned cost by the total label weight')
Beispiel #4
0
common_flags.define()

flags.DEFINE_string('export_dir', None, 'Directory to export model files to.')
flags.DEFINE_integer(
    'image_width', None,
    'Image width used during training (or crop width if used)'
    ' If not set, the dataset default is used instead.')
flags.DEFINE_integer(
    'image_height', None,
    'Image height used during training(or crop height if used)'
    ' If not set, the dataset default is used instead.')
flags.DEFINE_string('work_dir', '/tmp',
                    'A directory to store temporary files.')
flags.DEFINE_integer('version_number', 1, 'Version number of the model')
flags.DEFINE_bool(
    'export_for_serving', True,
    'Whether the exported model accepts serialized tf.Example '
    'protos as input')


def get_checkpoint_path():
    """Returns a path to a checkpoint based on specified commandline flags.

  In order to specify a full path to a checkpoint use --checkpoint flag.
  Alternatively, if --train_log_dir was specified it will return a path to the
  most recent checkpoint.

  Raises:
    ValueError: in case it can't find a checkpoint.

  Returns:
    A string.
Beispiel #5
0
from tensorflow.keras.applications.resnet50 import ResNet50
from tensorflow.keras.layers import Input
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
from tensorflow.compat.v1 import flags
from tensorflow.keras.optimizers import RMSprop
from dataset import synth_input_fn
from dataset import input_fn, NUM_IMAGES
from dataset import get_images_infor_from_file, ImagenetSequence

keras = tf.keras

flags.DEFINE_string('model', './train_dir/resnet50_model_195.h5',
                    'TensorFlow \'GraphDef\' file to load.')
flags.DEFINE_bool('eval_tfrecords', True, 'If True then use tf_records data .')
flags.DEFINE_string('data_dir', '/data3/datasets/Kaggle/fruits-360/tf_records',
                    'The directory where put the eval images')
flags.DEFINE_bool('eval_images', False, 'If True then use tf_records data .')
flags.DEFINE_string('eval_image_path',
                    '/data3/datasets/Kaggle/fruits-360/val_for_tf2',
                    'The directory where put the eval images')
flags.DEFINE_string('eval_image_list',
                    '/data3/datasets/Kaggle/fruits-360/val_labels.txt',
                    'file has validation images list')
flags.DEFINE_string('save_path', "train_dir", 'The directory where save model')
flags.DEFINE_string('filename', "resnet50_model_{epoch}.h5",
                    'The name of sved model')
flags.DEFINE_integer('label_offset', 1, 'label offset')
flags.DEFINE_string('gpus', '0', 'The gpus used for running evaluation.')
flags.DEFINE_bool('eval_only', False,
                     'seconds.')

flags.DEFINE_integer('save_interval_secs', 600,
                     'Frequency in seconds of saving the model.')

flags.DEFINE_integer('max_number_of_steps', int(1e10),
                     'The maximum number of gradient steps.')

flags.DEFINE_string('checkpoint_inception', '',
                    'Checkpoint to recover inception weights from.')

flags.DEFINE_float('clip_gradient_norm', 2.0,
                   'If greater than 0 then the gradients would be clipped by '
                   'it.')

flags.DEFINE_bool('sync_replicas', False,
                  'If True will synchronize replicas during training.')

flags.DEFINE_integer('replicas_to_aggregate', 1,
                     'The number of gradients updates before updating params.')

flags.DEFINE_integer('total_num_replicas', 1,
                     'Total number of worker replicas.')

flags.DEFINE_integer('startup_delay_steps', 15,
                     'Number of training steps between replicas startup.')

flags.DEFINE_boolean('reset_train_dir', False,
                     'If true will delete all files in the train_log_dir')

flags.DEFINE_boolean('show_graph_stats', False,
                     'Output model size stats to stderr.')
_LENGTH = 'Length'

_POSITION_COL = 'FragmentNumber'
_ION_COL = 'FragmentType'
_ABUNDANCE_COL = 'RelativeIntensity'
_LOSS_TYPE = 'FragmentLossType'
_FRAG_CHARGE = 'FragmentCharge'

FLAGS = flags.FLAGS
flags.DEFINE_string('metadata_file', None, 'Path to a TSV file with metadata.')
flags.DEFINE_string('input_data_pattern', None, 'Input data filename pattern.')
flags.DEFINE_enum('label_dim', '2', ['2', '6'],
                  'Number of features in the output/label time step')
flags.DEFINE_string('output_data_dir', None,
                    'Directory with prediction outputs.')
flags.DEFINE_bool('neutral_losses', False,
                  'True if H2O and NH3 losses are modeled.')
flags.DEFINE_bool(
    'batch_prediction', True,
    'True if batch prediction instead of online was used to generate outputs.')
flags.DEFINE_string(
    'add_input_data_pattern', None,
    ('Input data filename pattern for additional features to-be included to '
     'the final outptu. These inputs should be formatted in the same way as'
     'the model outputs - ie, JSON format with "key" and "output" values,'
     'where the key is an integer and output is a list of feature values.'))
flags.DEFINE_list('add_feature_names', None,
                  'A comma-separated list of additional feature names.')


def reformat_outputs(row, label_dim, neutral_losses):
    """Reformats output from the spectral model into a TSV shape.