本文整理汇总了Python中tensorflow.to_int32函数的典型用法代码示例。如果您正苦于以下问题:Python to_int32函数的具体用法?Python to_int32怎么用?Python to_int32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_int32函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _smallest_size_at_least
def _smallest_size_at_least(height, width, smallest_side):
"""Computes new shape with the smallest side equal to `smallest_side`.
Computes new shape with the smallest side equal to `smallest_side` while
preserving the original aspect ratio.
Args:
height: an int32 scalar tensor indicating the current height.
width: an int32 scalar tensor indicating the current width.
smallest_side: A python integer or scalar `Tensor` indicating the size of
the smallest side after resize.
Returns:
new_height: an int32 scalar tensor indicating the new height.
new_width: and int32 scalar tensor indicating the new width.
"""
smallest_side = tf.convert_to_tensor(smallest_side, dtype=tf.int32)
height = tf.to_float(height)
width = tf.to_float(width)
smallest_side = tf.to_float(smallest_side)
scale = tf.cond(tf.greater(height, width),
lambda: smallest_side / width,
lambda: smallest_side / height)
new_height = tf.to_int32(height * scale)
new_width = tf.to_int32(width * scale)
return new_height, new_width
开发者ID:Zumbalamambo,项目名称:deepcv,代码行数:28,代码来源:vgg_preprocessing.py
示例2: padded_sequence_accuracy
def padded_sequence_accuracy(predictions,
labels,
weights_fn=common_layers.weights_nonzero):
"""Percentage of times that predictions matches labels everywhere (non-0)."""
# If the last dimension is 1 then we're using L1/L2 loss.
if common_layers.shape_list(predictions)[-1] == 1:
return rounding_sequence_accuracy(
predictions, labels, weights_fn=weights_fn)
with tf.variable_scope(
"padded_sequence_accuracy", values=[predictions, labels]):
padded_predictions, padded_labels = common_layers.pad_with_zeros(
predictions, labels)
weights = weights_fn(padded_labels)
# Flatten, keeping batch dim (and num_classes dim for predictions)
# TPU argmax can only deal with a limited number of dimensions
predictions_shape = common_layers.shape_list(padded_predictions)
batch_size = predictions_shape[0]
num_classes = predictions_shape[-1]
flat_size = common_layers.list_product(
common_layers.shape_list(padded_labels)[1:])
padded_predictions = tf.reshape(
padded_predictions,
[batch_size, common_layers.list_product(predictions_shape[1:-1]),
num_classes])
padded_labels = tf.reshape(padded_labels, [batch_size, flat_size])
weights = tf.reshape(weights, [batch_size, flat_size])
outputs = tf.to_int32(tf.argmax(padded_predictions, axis=-1))
padded_labels = tf.to_int32(padded_labels)
not_correct = tf.to_float(tf.not_equal(outputs, padded_labels)) * weights
axis = list(range(1, len(outputs.get_shape())))
correct_seq = 1.0 - tf.minimum(1.0, tf.reduce_sum(not_correct, axis=axis))
return correct_seq, tf.constant(1.0)
开发者ID:qixiuai,项目名称:tensor2tensor,代码行数:34,代码来源:metrics.py
示例3: decoder
def decoder(self, logits_main, logits_sub, inputs_seq_len, beam_width=1):
"""Operation for decoding.
Args:
logits_main: A tensor of size `[T, B, input_size]`
logits_sub: A tensor of size `[T, B, input_size]`
inputs_seq_len: A tensor of size `[B]`
beam_width (int, optional): beam width for beam search.
1 disables beam search, which mean greedy decoding.
Return:
decode_op_main: operation for decoding of the main task
decode_op_sub: operation for decoding of the sub task
"""
assert isinstance(beam_width, int), "beam_width must be integer."
assert beam_width >= 1, "beam_width must be >= 1"
# inputs_seq_len = tf.cast(inputs_seq_len, tf.int32)
if beam_width == 1:
decoded_main, _ = tf.nn.ctc_greedy_decoder(
logits_main, inputs_seq_len)
decoded_sub, _ = tf.nn.ctc_greedy_decoder(
logits_sub, inputs_seq_len)
else:
decoded_main, _ = tf.nn.ctc_beam_search_decoder(
logits_main, inputs_seq_len,
beam_width=beam_width)
decoded_sub, _ = tf.nn.ctc_beam_search_decoder(
logits_sub, inputs_seq_len,
beam_width=beam_width)
decode_op_main = tf.to_int32(decoded_main[0])
decode_op_sub = tf.to_int32(decoded_sub[0])
return decode_op_main, decode_op_sub
开发者ID:seasky100,项目名称:tensorflow_end2end_speech_recognition,代码行数:35,代码来源:multitask_ctc.py
示例4: add_volume_iou_metrics
def add_volume_iou_metrics(inputs, outputs):
"""Computes the per-instance volume IOU.
Args:
inputs: Input dictionary of the voxel generation model.
outputs: Output dictionary returned by the voxel generation model.
Returns:
names_to_values: metrics->values (dict).
names_to_updates: metrics->ops (dict).
"""
names_to_values = dict()
names_to_updates = dict()
labels = tf.greater_equal(inputs['voxels'], 0.5)
predictions = tf.greater_equal(outputs['voxels_1'], 0.5)
labels = 2 - tf.to_int32(labels)
predictions = 3 - tf.to_int32(predictions) * 2
tmp_values, tmp_updates = tf.metrics.mean_iou(
labels=labels,
predictions=predictions,
num_classes=3)
names_to_values['volume_iou'] = tmp_values * 3.0
names_to_updates['volume_iou'] = tmp_updates
return names_to_values, names_to_updates
开发者ID:ameerellaboudy,项目名称:models,代码行数:25,代码来源:metrics.py
示例5: test_accuracy
def test_accuracy(logits, labels):
logits_idx = tf.to_int32(tf.argmax(logits, axis=1))
logits_idx = tf.reshape(logits_idx, shape=(cfg.batch_size,))
correct_preds = tf.equal(tf.to_int32(labels), logits_idx)
accuracy = tf.reduce_sum(tf.cast(correct_preds, tf.float32)) / cfg.batch_size
return accuracy
开发者ID:lzqkean,项目名称:deep_learning,代码行数:7,代码来源:capsnet_dynamic_routing.py
示例6: crop_or_pad
def crop_or_pad(waves, length, channels):
"""Crop or pad wave to have shape [N, length, channels].
Args:
waves: A 3D `Tensor` of NLC format.
length: A Python scalar. The output wave size.
channels: Number of output waves channels.
Returns:
A 3D `Tensor` of NLC format with shape [N, length, channels].
"""
waves = tf.convert_to_tensor(waves)
batch_size = waves.shape[0].value
waves_shape = tf.shape(waves)
# Force audio length.
pad = tf.maximum(0, length - waves_shape[1])
right_pad = tf.to_int32(tf.to_float(pad) / 2.0)
left_pad = pad - right_pad
waves = tf.pad(waves, [[0, 0], [left_pad, right_pad], [0, 0]])
waves = waves[:, :length, :]
# Force number of channels.
num_repeats = tf.to_int32(
tf.ceil(tf.to_float(channels) / tf.to_float(waves_shape[2])))
waves = tf.tile(waves, [1, 1, num_repeats])[:, :, :channels]
waves.set_shape([batch_size, length, channels])
return waves
开发者ID:cghawthorne,项目名称:magenta,代码行数:29,代码来源:spectral_ops.py
示例7: get_exemplar_images
def get_exemplar_images(images, exemplar_size, targets_pos=None):
"""Crop exemplar image from input images"""
with tf.name_scope('get_exemplar_image'):
batch_size, x_height, x_width = images.get_shape().as_list()[:3]
z_height, z_width = exemplar_size
if targets_pos is None:
target_pos_single = [[get_center(x_height), get_center(x_width)]]
targets_pos_ = tf.tile(target_pos_single, [batch_size, 1])
else:
targets_pos_ = targets_pos
# convert to top-left corner based coordinates
top = tf.to_int32(tf.round(targets_pos_[:, 0] - get_center(z_height)))
bottom = tf.to_int32(top + z_height)
left = tf.to_int32(tf.round(targets_pos_[:, 1] - get_center(z_width)))
right = tf.to_int32(left + z_width)
def _slice(x):
f, t, l, b, r = x
c = f[t:b, l:r]
return c
exemplar_img = tf.map_fn(_slice, (images, top, left, bottom, right), dtype=images.dtype)
exemplar_img.set_shape([batch_size, z_height, z_width, 3])
return exemplar_img
开发者ID:fossabot,项目名称:SiamFC-TensorFlow,代码行数:26,代码来源:infer_utils.py
示例8: smoothing_crossentropy_avgall
def smoothing_crossentropy_avgall(logits, targets, sequence_length):
""" Computes cross entropy loss of a batch of data with label smoothing.
The final loss is averaged by the length of each
sequence and then averaged by the batch size.
Args:
logits: The logits Tensor with shape [timesteps, batch_size, vocab_size].
targets: The gold labels Tensor with shape [timesteps, batch_size].
sequence_length: The length of `targets`, [batch_size, ]
Returns: Loss sum and weight sum.
"""
soft_targets, normalizing = label_smoothing(targets, logits.get_shape().as_list()[-1])
losses = tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=soft_targets) - normalizing
# [timesteps, batch_size]
loss_mask = tf.transpose(
tf.sequence_mask(
lengths=tf.to_int32(sequence_length),
maxlen=tf.to_int32(tf.shape(targets)[0]),
dtype=tf.float32), [1, 0])
losses = losses * loss_mask
# average loss
avg_length = tf.to_float(sequence_length)
loss_by_time = tf.reduce_sum(losses, axis=0) / avg_length
loss_sum = tf.reduce_sum(loss_by_time)
return loss_sum, tf.to_float(tf.shape(sequence_length)[0])
开发者ID:KIngpon,项目名称:NJUNMT-tf,代码行数:27,代码来源:loss_fns.py
示例9: crossentropy
def crossentropy(logits, targets, sequence_length):
""" Computes cross entropy loss of a batch of data. (Not averaged by batch_size)
The final loss is averaged by the number of samples in the batch.
Args:
logits: The logits Tensor with shape [timesteps, batch_size, vocab_size].
targets: The gold labels Tensor with shape [timesteps, batch_size].
sequence_length: The length of `targets`, [batch_size, ]
Returns: Loss sum and weight sum.
"""
# [timesteps, batch_size]
losses = tf.nn.sparse_softmax_cross_entropy_with_logits(
logits=logits, labels=targets)
# [timesteps, batch_size]
loss_mask = tf.transpose(
tf.sequence_mask(
lengths=tf.to_int32(sequence_length),
maxlen=tf.to_int32(tf.shape(targets)[0]),
dtype=tf.float32), [1, 0])
losses = losses * loss_mask
loss_sum = tf.reduce_sum(losses)
return loss_sum, tf.to_float(tf.shape(sequence_length)[0])
开发者ID:KIngpon,项目名称:NJUNMT-tf,代码行数:26,代码来源:loss_fns.py
示例10: indices_to_dense_vector
def indices_to_dense_vector(indices,
size,
indices_value=1.,
default_value=0,
dtype=tf.float32):
"""Creates dense vector with indices set to specific value and rest to zeros.
This function exists because it is unclear if it is safe to use
tf.sparse_to_dense(indices, [size], 1, validate_indices=False)
with indices which are not ordered.
This function accepts a dynamic size (e.g. tf.shape(tensor)[0])
Args:
indices: 1d Tensor with integer indices which are to be set to
indices_values.
size: scalar with size (integer) of output Tensor.
indices_value: values of elements specified by indices in the output vector
default_value: values of other elements in the output vector.
dtype: data type.
Returns:
dense 1D Tensor of shape [size] with indices set to indices_values and the
rest set to default_value.
"""
size = tf.to_int32(size)
zeros = tf.ones([size], dtype=dtype) * default_value
values = tf.ones_like(indices, dtype=dtype) * indices_value
return tf.dynamic_stitch([tf.range(size), tf.to_int32(indices)],
[zeros, values])
开发者ID:Zumbalamambo,项目名称:deepcv,代码行数:30,代码来源:ops.py
示例11: pad_to_multiple
def pad_to_multiple(tensor, multiple):
"""Returns the tensor zero padded to the specified multiple.
Appends 0s to the end of the first and second dimension (height and width) of
the tensor until both dimensions are a multiple of the input argument
'multiple'. E.g. given an input tensor of shape [1, 3, 5, 1] and an input
multiple of 4, PadToMultiple will append 0s so that the resulting tensor will
be of shape [1, 4, 8, 1].
Args:
tensor: rank 4 float32 tensor, where
tensor -> [batch_size, height, width, channels].
multiple: the multiple to pad to.
Returns:
padded_tensor: the tensor zero padded to the specified multiple.
"""
tensor_shape = tensor.get_shape()
batch_size = static_shape.get_batch_size(tensor_shape)
tensor_height = static_shape.get_height(tensor_shape)
tensor_width = static_shape.get_width(tensor_shape)
tensor_depth = static_shape.get_depth(tensor_shape)
if batch_size is None:
batch_size = tf.shape(tensor)[0]
if tensor_height is None:
tensor_height = tf.shape(tensor)[1]
padded_tensor_height = tf.to_int32(
tf.ceil(tf.to_float(tensor_height) / tf.to_float(multiple))) * multiple
else:
padded_tensor_height = int(
math.ceil(float(tensor_height) / multiple) * multiple)
if tensor_width is None:
tensor_width = tf.shape(tensor)[2]
padded_tensor_width = tf.to_int32(
tf.ceil(tf.to_float(tensor_width) / tf.to_float(multiple))) * multiple
else:
padded_tensor_width = int(
math.ceil(float(tensor_width) / multiple) * multiple)
if tensor_depth is None:
tensor_depth = tf.shape(tensor)[3]
# Use tf.concat instead of tf.pad to preserve static shape
if padded_tensor_height != tensor_height:
height_pad = tf.zeros([
batch_size, padded_tensor_height - tensor_height, tensor_width,
tensor_depth
])
tensor = tf.concat([tensor, height_pad], 1)
if padded_tensor_width != tensor_width:
width_pad = tf.zeros([
batch_size, padded_tensor_height, padded_tensor_width - tensor_width,
tensor_depth
])
tensor = tf.concat([tensor, width_pad], 2)
return tensor
开发者ID:ALISCIFP,项目名称:models,代码行数:60,代码来源:ops.py
示例12: padded_accuracy
def padded_accuracy(logits, labels):
"""Percentage of times that predictions matches labels on non-0s."""
with tf.variable_scope("padded_accuracy", values=[logits, labels]):
logits, labels = _pad_tensors_to_same_length(logits, labels)
weights = tf.to_float(tf.not_equal(labels, 0))
outputs = tf.to_int32(tf.argmax(logits, axis=-1))
padded_labels = tf.to_int32(labels)
return tf.to_float(tf.equal(outputs, padded_labels)), weights
开发者ID:812864539,项目名称:models,代码行数:8,代码来源:metrics.py
示例13: subsample
def subsample(self, indicator, batch_size, labels, scope=None):
"""Returns subsampled minibatch.
Args:
indicator: boolean tensor of shape [N] whose True entries can be sampled.
batch_size: desired batch size. If None, keeps all positive samples and
randomly selects negative samples so that the positive sample fraction
matches self._positive_fraction. It cannot be None is is_static is True.
labels: boolean tensor of shape [N] denoting positive(=True) and negative
(=False) examples.
scope: name scope.
Returns:
sampled_idx_indicator: boolean tensor of shape [N], True for entries which
are sampled.
Raises:
ValueError: if labels and indicator are not 1D boolean tensors.
"""
if len(indicator.get_shape().as_list()) != 1:
raise ValueError('indicator must be 1 dimensional, got a tensor of '
'shape %s' % indicator.get_shape())
if len(labels.get_shape().as_list()) != 1:
raise ValueError('labels must be 1 dimensional, got a tensor of '
'shape %s' % labels.get_shape())
if labels.dtype != tf.bool:
raise ValueError('labels should be of type bool. Received: %s' %
labels.dtype)
if indicator.dtype != tf.bool:
raise ValueError('indicator should be of type bool. Received: %s' %
indicator.dtype)
with tf.name_scope(scope, 'BalancedPositiveNegativeSampler'):
if self._is_static:
return self._static_subsample(indicator, batch_size, labels)
else:
# Only sample from indicated samples
negative_idx = tf.logical_not(labels)
positive_idx = tf.logical_and(labels, indicator)
negative_idx = tf.logical_and(negative_idx, indicator)
# Sample positive and negative samples separately
if batch_size is None:
max_num_pos = tf.reduce_sum(tf.to_int32(positive_idx))
else:
max_num_pos = int(self._positive_fraction * batch_size)
sampled_pos_idx = self.subsample_indicator(positive_idx, max_num_pos)
num_sampled_pos = tf.reduce_sum(tf.cast(sampled_pos_idx, tf.int32))
if batch_size is None:
negative_positive_ratio = (
1 - self._positive_fraction) / self._positive_fraction
max_num_neg = tf.to_int32(
negative_positive_ratio * tf.to_float(num_sampled_pos))
else:
max_num_neg = batch_size - num_sampled_pos
sampled_neg_idx = self.subsample_indicator(negative_idx, max_num_neg)
return tf.logical_or(sampled_pos_idx, sampled_neg_idx)
开发者ID:ALISCIFP,项目名称:models,代码行数:58,代码来源:balanced_positive_negative_sampler.py
示例14: _build_once
def _build_once(self, dataset, feature_transformer):
with tf.device(self._local_device):
tr_batch = dataset()
te_batch = dataset()
num_classes = tr_batch.label_onehot.shape.as_list()[1]
all_batch = utils.structure_map_multi(lambda x: tf.concat(x, 0),
[tr_batch, te_batch])
features = feature_transformer(all_batch)
trX, teX = utils.structure_map_split(lambda x: tf.split(x, 2, axis=0),
features)
trY = tf.to_int64(tr_batch.label)
trY_onehot = tf.to_int32(tr_batch.label_onehot)
teY = tf.to_int64(te_batch.label)
teY_shape = teY.shape.as_list()
def blackbox((trX, trY, teX, teY)):
trY = tf.to_int32(tf.rint(trY))
teY = tf.to_int32(tf.rint(teY))
tf_fn = build_fit(
self._local_device,
self._get_model,
num_classes=num_classes,
probs=self.probs)
if self.probs:
trP, teP, teP_probs = tf_fn(trX, trY, teX)
else:
trP, teP = tf_fn(trX, trY, teX)
teY.set_shape(teY_shape)
if self.probs:
onehot = tf.one_hot(teY, num_classes)
crossent = -tf.reduce_sum(onehot * teP_probs, [1])
return tf.reduce_mean(crossent)
else:
# use error rate as the loss if no surrogate is avalible.
return 1 - tf.reduce_mean(
tf.to_float(tf.equal(teY, tf.to_int32(teP))))
test_loss = blackbox((trX, tf.to_float(trY), teX, tf.to_float(teY)))
stats = {}
tf_fn = build_fit(
self._local_device,
self._get_model,
num_classes=num_classes,
probs=self.probs)
if self.probs:
trP, teP, teP_probs = tf_fn(trX, trY, teX)
else:
trP, teP = tf_fn(trX, trY, teX)
stats["%s/accuracy_train" % self.name] = tf.reduce_mean(
tf.to_float(tf.equal(tf.to_int32(trY), tf.to_int32(trP))))
stats["%s/accuracy_test" % self.name] = tf.reduce_mean(
tf.to_float(tf.equal(tf.to_int32(teY), tf.to_int32(teP))))
stats["%s/test_loss" % self.name] = test_loss
return test_loss, stats
开发者ID:ALISCIFP,项目名称:models,代码行数:57,代码来源:sklearn.py
示例15: rounding_accuracy
def rounding_accuracy(predictions,
labels,
weights_fn=common_layers.weights_nonzero):
"""Rounding accuracy for L1/L2 losses: round down the predictions to ints."""
outputs = tf.squeeze(tf.to_int32(predictions))
labels = tf.squeeze(labels)
weights = weights_fn(labels)
labels = tf.to_int32(labels)
return tf.to_float(tf.equal(outputs, labels)), weights
开发者ID:qixiuai,项目名称:tensor2tensor,代码行数:9,代码来源:metrics.py
示例16: predict_setup
def predict_setup(self):
# Create queue coordinator.
self.coord = tf.train.Coordinator()
# Load reader
with tf.name_scope("create_inputs"):
reader = ImageReader(
self.conf.data_dir,
self.conf.test_data_list,
None, # the images have different sizes
False, # no data-aug
False, # no data-aug
self.conf.ignore_label,
IMG_MEAN,
self.coord)
image, label = reader.image, reader.label # [h, w, 3 or 1]
# Add one batch dimension [1, h, w, 3 or 1]
image_batch, label_batch = tf.expand_dims(image, dim=0), tf.expand_dims(label, dim=0)
h_orig, w_orig = tf.to_float(tf.shape(image_batch)[1]), tf.to_float(tf.shape(image_batch)[2])
image_batch_075 = tf.image.resize_images(image_batch, tf.stack([tf.to_int32(tf.multiply(h_orig, 0.75)), tf.to_int32(tf.multiply(w_orig, 0.75))]))
image_batch_05 = tf.image.resize_images(image_batch, tf.stack([tf.to_int32(tf.multiply(h_orig, 0.5)), tf.to_int32(tf.multiply(w_orig, 0.5))]))
# Create network
if self.conf.encoder_name not in ['res101', 'res50']:
print('encoder_name ERROR!')
print("Please input: res101, res50")
sys.exit(-1)
else:
with tf.variable_scope('', reuse=False):
net = ResNet_segmentation(image_batch, self.conf.num_classes, False, self.conf.encoder_name)
with tf.variable_scope('', reuse=True):
net075 = ResNet_segmentation(image_batch_075, self.conf.num_classes, False, self.conf.encoder_name)
with tf.variable_scope('', reuse=True):
net05 = ResNet_segmentation(image_batch_05, self.conf.num_classes, False, self.conf.encoder_name)
# predictions
# Network raw output
raw_output100 = net.outputs
raw_output075 = net075.outputs
raw_output05 = net05.outputs
raw_output = tf.reduce_max(tf.stack([raw_output100,
tf.image.resize_images(raw_output075, tf.shape(raw_output100)[1:3,]),
tf.image.resize_images(raw_output05, tf.shape(raw_output100)[1:3,])]), axis=0)
raw_output = tf.image.resize_bilinear(raw_output, tf.shape(image_batch)[1:3,])
raw_output = tf.argmax(raw_output, axis=3)
self.pred = tf.cast(tf.expand_dims(raw_output, dim=3), tf.uint8)
# Create directory
if not os.path.exists(self.conf.out_dir):
os.makedirs(self.conf.out_dir)
os.makedirs(self.conf.out_dir + '/prediction')
if self.conf.visual:
os.makedirs(self.conf.out_dir + '/visual_prediction')
# Loader for loading the checkpoint
self.loader = tf.train.Saver(var_list=tf.global_variables())
开发者ID:ascenoputing,项目名称:SemanticSegmentation_DL,代码行数:57,代码来源:model_msc.py
示例17: arg_max_2d
def arg_max_2d(x_in):
orig_shape = tf.shape(x_in)
reshape_t = tf.concat([orig_shape[0:1], [-1], orig_shape[3:4]], 0)
zz = tf.reshape(x_in, reshape_t)
pp = tf.to_int32(tf.argmax(zz, 1))
sz1 = tf.slice(orig_shape, [2], [1])
cc1 = tf.div(pp, tf.to_int32(sz1))
cc2 = tf.mod(pp, tf.to_int32(sz1))
return tf.stack([cc1, cc2])
开发者ID:mkabra,项目名称:poseTF,代码行数:10,代码来源:PoseTools.py
示例18: preprocess_example
def preprocess_example(self, example, mode, hparams):
example = super(AudioTimitProblem, self).preprocess_example(
example, mode, hparams)
# Reshape audio to proper shape
sample_count = tf.to_int32(example.pop("audio/sample_count"))
sample_width = tf.to_int32(example.pop("audio/sample_width"))
channel_count = 1
example["inputs"] = tf.reshape(example["inputs"],
[sample_count, sample_width, channel_count])
return example
开发者ID:chqiwang,项目名称:tensor2tensor,代码行数:10,代码来源:problem_hparams.py
示例19: _anchor_component_tf
def _anchor_component_tf(self):
print('Use TF anchors')
with tf.variable_scope('ANCHOR_' + self._tag) as scope:
# just to get the shape right
height = tf.to_int32(tf.ceil(self._im_info[0, 0] / np.float32(self._feat_stride[0])))
width = tf.to_int32(tf.ceil(self._im_info[0, 1] / np.float32(self._feat_stride[0])))
self._anchors, self._anchor_length = generate_anchors_pre_tf(
height, width, self._feat_stride[0], self._anchor_scales,
self._anchor_ratios)
开发者ID:jacke121,项目名称:tf_rfcn,代码行数:10,代码来源:network.py
示例20: create_learning_rate_decay_fn
def create_learning_rate_decay_fn(decay_type,
decay_steps,
decay_rate,
start_decay_at=0,
stop_decay_at=1e9,
min_learning_rate=None,
staircase=False):
"""Creates a function that decays the learning rate.
Args:
decay_steps: How often to apply decay.
decay_rate: A Python number. The decay rate.
start_decay_at: Don't decay before this step
stop_decay_at: Don't decay after this step
min_learning_rate: Don't decay below this number
decay_type: A decay function name defined in `tf.train`
staircase: Whether to apply decay in a discrete staircase,
as opposed to continuous, fashion.
Returns:
A function that takes (learning_rate, global_step) as inputs
and returns the learning rate for the given step.
Returns `None` if decay_type is empty or None.
"""
if decay_type is None or decay_type == "":
return None
start_decay_at = tf.to_int32(start_decay_at)
stop_decay_at = tf.to_int32(stop_decay_at)
def decay_fn(learning_rate, global_step):
"""The computed learning rate decay function.
"""
global_step = tf.to_int32(global_step)
decay_type_fn = getattr(tf.train, decay_type)
decayed_learning_rate = decay_type_fn(
learning_rate=learning_rate,
global_step=tf.minimum(global_step, stop_decay_at) - start_decay_at,
decay_steps=decay_steps,
decay_rate=decay_rate,
staircase=staircase,
name="decayed_learning_rate")
final_lr = tf.train.piecewise_constant(
x=global_step,
boundaries=[start_decay_at],
values=[learning_rate, decayed_learning_rate])
if min_learning_rate:
final_lr = tf.maximum(final_lr, min_learning_rate)
return final_lr
return decay_fn
开发者ID:AbhinavJain13,项目名称:seq2seq,代码行数:55,代码来源:utils.py
注:本文中的tensorflow.to_int32函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论