本文整理汇总了Python中tensorflow.floor_div方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.floor_div方法的具体用法?Python tensorflow.floor_div怎么用?Python tensorflow.floor_div使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.floor_div方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_sequence_lengths
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floor_div [as 别名]
def get_sequence_lengths( widths ):
"""Tensor calculating output sequence length from original image widths"""
kernel_sizes = [params[1] for params in layer_params]
with tf.variable_scope("sequence_length"):
conv1_trim = tf.constant( 2 * (kernel_sizes[0] // 2),
dtype=tf.int32,
name='conv1_trim' )
one = tf.constant( 1, dtype=tf.int32, name='one' )
two = tf.constant( 2, dtype=tf.int32, name='two' )
after_conv1 = tf.subtract( widths, conv1_trim, name='after_conv1' )
after_pool2 = tf.floor_div( after_conv1, two, name='after_pool2' )
after_pool4 = tf.subtract( after_pool2, one, name='after_pool4' )
after_pool6 = tf.subtract( after_pool4, one, name='after_pool6' )
after_pool8 = tf.identity( after_pool6, name='after_pool8' )
return after_pool8
示例2: _upsample_rois
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floor_div [as 别名]
def _upsample_rois(scores, bboxes, keep_top_k):
# upsample with replacement
# filter out paddings
bboxes = tf.boolean_mask(bboxes, scores > 0.)
scores = tf.boolean_mask(scores, scores > 0.)
scores, bboxes = tf.cond(tf.less(tf.shape(scores)[0], 1), lambda: (tf.constant([1.]), tf.constant([[0.2, 0.2, 0.8, 0.8]])), lambda: (scores, bboxes))
#scores = tf.Print(scores,[scores])
def upsampel_impl():
num_bboxes = tf.shape(scores)[0]
left_count = keep_top_k - num_bboxes
select_indices = tf.random_shuffle(tf.range(num_bboxes))[:tf.floormod(left_count, num_bboxes)]
#### zero
select_indices = tf.concat([tf.tile(tf.range(num_bboxes), [tf.floor_div(left_count, num_bboxes) + 1]), select_indices], axis = 0)
return [tf.gather(scores, select_indices), tf.gather(bboxes, select_indices)]
return tf.cond(tf.shape(scores)[0] < keep_top_k, lambda : upsampel_impl(), lambda : [scores, bboxes])
示例3: get_control_flag
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floor_div [as 别名]
def get_control_flag(control, field):
return tf.equal(tf.mod(tf.floor_div(control, field), 2), 1)
示例4: get_control_flag
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floor_div [as 别名]
def get_control_flag(control, field):
logger.info(msg="get_control_flag called")
return tf.equal(tf.mod(tf.floor_div(control, field), 2), 1)
示例5: five_crops
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floor_div [as 别名]
def five_crops(image, crop_size):
""" Returns the central and four corner crops of `crop_size` from `image`. """
image_size = tf.shape(image)[:2]
crop_margin = tf.subtract(image_size, crop_size)
assert_size = tf.assert_non_negative(
crop_margin, message='Crop size must be smaller or equal to the image size.')
with tf.control_dependencies([assert_size]):
top_left = tf.floor_div(crop_margin, 2)
bottom_right = tf.add(top_left, crop_size)
center = image[top_left[0]:bottom_right[0], top_left[1]:bottom_right[1]]
top_left = image[:-crop_margin[0], :-crop_margin[1]]
top_right = image[:-crop_margin[0], crop_margin[1]:]
bottom_left = image[crop_margin[0]:, :-crop_margin[1]]
bottom_right = image[crop_margin[0]:, crop_margin[1]:]
return center, top_left, top_right, bottom_left, bottom_right
示例6: cross_2args
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floor_div [as 别名]
def cross_2args(X,Y):
if X.doms == [] and Y.doms == []:
result = tf.concat([X,Y],axis=-1)
result.doms = []
return result,[X,Y]
X_Y = set(X.doms) - set(Y.doms)
Y_X = set(Y.doms) - set(X.doms)
eX = X
eX_doms = [x for x in X.doms]
for y in Y_X:
eX = tf.expand_dims(eX,0)
eX_doms = [y] + eX_doms
eY = Y
eY_doms = [y for y in Y.doms]
for x in X_Y:
eY = tf.expand_dims(eY,-2)
eY_doms.append(x)
perm_eY = []
for y in eY_doms:
perm_eY.append(eX_doms.index(y))
eY = tf.transpose(eY,perm=perm_eY + [len(perm_eY)])
mult_eX = [1]*(len(eX_doms)+1)
mult_eY = [1]*(len(eY_doms)+1)
for i in range(len(mult_eX)-1):
mult_eX[i] = tf.maximum(1,tf.floor_div(tf.shape(eY)[i],tf.shape(eX)[i]))
mult_eY[i] = tf.maximum(1,tf.floor_div(tf.shape(eX)[i],tf.shape(eY)[i]))
result1 = tf.tile(eX,mult_eX)
result2 = tf.tile(eY,mult_eY)
result = tf.concat([result1,result2],axis=-1)
result1.doms = eX_doms
result2.doms = eX_doms
result.doms = eX_doms
return result,[result1,result2]
示例7: _padding
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floor_div [as 别名]
def _padding(tensor, out_size):
t_width = tensor.get_shape()[1]
delta = tf.subtract(out_size, t_width)
pad_left = tf.floor_div(delta, 2)
pad_right = delta - pad_left
return tf.pad(
tensor,
[
[0, 0],
[pad_left, pad_right],
[pad_left, pad_right],
[0, 0]
],
'CONSTANT'
)
示例8: Dense_net
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floor_div [as 别名]
def Dense_net(input_x,widths,mode):
training = (mode == learn.ModeKeys.TRAIN)
# input_x:[ 32 ,width , 3 ]
x = conv_layer(input_x,filter=filter,kernel=[3,3],stride=1,layer_name='conv0')
# x = Max_Pooling(x,pool_size=[3,3],stride=2)
# x: [32,width,64]
x = dense_block(input_x = x,nb_layers=4,layer_name='dense_1',training=training)
# x: [32,width,64+4*32=192]
x = transition_layer(x,128,scope='trans_1',training=training)#transition_layer(x,filters,scope,training)
# x: [16,width-1,128]
x = dense_block(input_x = x,nb_layers=6,layer_name='dense_2',training=training)
# x: [16,width,128+6*32=320]
x = transition_layer(x,256,scope='trans_2',training=training)
# x: [8,width-1,256]
x = Max_Pooling(x,[2,2],2)
# x:[4,width/2,256]
x = dense_block(input_x =x ,nb_layers=8,layer_name='dense_3',training=training)
# x: [4,width,256+8*32=512]
x = transition_layer(x,512,scope='trans_3',training=training)
# x: [4,width-1,512]
x = Batch_Normalization(x,training=training,scope='linear_batch')
x = Relu(x)
# x = Global_Average_Pooling(x) # cifar-10中用于分类
x = Max_Pooling(x,[2,2],[2,1])
# x: [1,width/2,512]
features = tf.squeeze(x,axis=1,name='features')
# calculate resulting sequence length
one = tf.constant(1, dtype=tf.int32, name='one')
two = tf.constant(2, dtype=tf.int32, name='two')
after_conv0=widths
after_dense_1=after_conv0
after_trans_1=tf.subtract(after_dense_1,one)
after_dense_2=after_trans_1
after_trans_2=tf.subtract(after_dense_2,one)
after_first_maxpool=tf.floor_div(after_trans_2, two )#向下取整
after_dense_3=after_first_maxpool
after_trans_3=tf.subtract(after_dense_3,one)
after_second_maxpool=tf.subtract(after_trans_3,one)
sequence_length = tf.reshape(after_second_maxpool,[-1], name='seq_len')
return features,sequence_length
示例9: convnet_layers
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floor_div [as 别名]
def convnet_layers(inputs, widths, mode):# image, width, mode
"""Build convolutional network layers attached to the given input tensor"""
training = (mode == learn.ModeKeys.TRAIN)
# inputs should have shape [ ?, 32, ?, 1 ]
with tf.variable_scope("convnet"): # h,w
inputs=gaussian_noise_layer(inputs,1)
inputs=tf.image.random_brightness(inputs,32./255)
inputs=tf.image.random_contrast(inputs,lower=0.5,upper=1.5)
# inputs=tf.image.random_hue(inputs,max_delta=0.2)
conv1 = conv_layer(inputs, layer_params[0], training ) # 30,30
conv2 = conv_layer( conv1, layer_params[1], training ) # 30,30
pool2 = pool_layer( conv2, 2, 'valid', 'pool2') # 15,15
conv3 = conv_layer( pool2, layer_params[2], training ) # 15,15
conv4 = conv_layer( conv3, layer_params[3], training ) # 15,15
pool4 = pool_layer( conv4, 1, 'valid', 'pool4' ) # 7,14
conv5 = conv_layer( pool4, layer_params[4], training ) # 7,14
conv6 = conv_layer( conv5, layer_params[5], training ) # 7,14
pool6 = pool_layer( conv6, 1, 'valid', 'pool6') # 3,13
conv7 = conv_layer( pool6, layer_params[6], training ) # 3,13
conv8 = conv_layer( conv7, layer_params[7], training ) # 3,13
pool8 = tf.layers.max_pooling2d( conv8, [3,1], [3,1],
padding='valid', name='pool8') # 1,13
features = tf.squeeze(pool8, axis=1, name='features') # squeeze row dim
kernel_sizes = [ params[1] for params in layer_params]
# Calculate resulting sequence length from original image widths
conv1_trim = tf.constant( 2 * (kernel_sizes[0] // 2),
dtype=tf.int32,
name='conv1_trim')
one = tf.constant(1, dtype=tf.int32, name='one')
two = tf.constant(2, dtype=tf.int32, name='two')
after_conv1 = tf.subtract( widths, conv1_trim)
after_pool2 = tf.floor_div( after_conv1, two )
after_pool4 = tf.subtract(after_pool2, one)
after_pool6 = tf.subtract(after_pool4, one)
after_pool8 = after_pool6
sequence_length = tf.reshape(after_pool8,[-1], name='seq_len') # Vectorize
return features,sequence_length