本文整理匯總了Python中tf_util.conv2d方法的典型用法代碼示例。如果您正苦於以下問題:Python tf_util.conv2d方法的具體用法?Python tf_util.conv2d怎麽用?Python tf_util.conv2d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tf_util
的用法示例。
在下文中一共展示了tf_util.conv2d方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: residual_block
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def residual_block(X, out_dim, is_training, bn_decay, scope):
n_dim = X.get_shape()[2].value
X_expanded = tf.expand_dims(X, -2)
net = tf_util.conv2d(X_expanded, out_dim, [1,1], padding='VALID',
stride=[1,1], bn=True, is_training=is_training,
bn_decay=bn_decay, activation_fn=tf.nn.relu, scope=scope+'_conv1')
net = tf_util.conv2d(net, out_dim, [1,1], padding='VALID',
stride=[1,1], bn=True, is_training=is_training,
bn_decay=bn_decay, activation_fn=None, scope=scope+'_conv2')
if n_dim != out_dim:
X_expanded = tf_util.conv2d(X_expanded, out_dim, [1,1], padding='VALID',
stride=[1,1], activation_fn=None, scope=scope+'_conv3')
net = tf.nn.relu(net + X_expanded)
net = tf.squeeze(net)
return net
示例2: _get_dgcnn
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def _get_dgcnn(pcs, layer_sizes, scope_name, is_training, bn_decay):
assert len(layer_sizes) > 0
num_point = pcs.shape[1]
k = 20
with tf.variable_scope(scope_name):
adj_matrix = tf_util_dgcnn.pairwise_distance(pcs)
nn_idx = tf_util_dgcnn.knn(adj_matrix, k=k)
edge_feature = tf_util_dgcnn.get_edge_feature(pcs, nn_idx=nn_idx, k=k)
net = tf_util_dgcnn.conv2d(edge_feature, layer_sizes[0], [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training, scope='conv1', bn_decay=bn_decay)
for idx, layer_size in enumerate(layer_sizes[1:-1]):
net = tf_util_dgcnn.conv2d(net, layer_size, [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training, scope=f'conv{idx+2}', bn_decay=bn_decay)
net = tf.reduce_max(net, axis=-2, keepdims=True)
net = tf_util_dgcnn.conv2d(net, layer_sizes[-1], [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training, scope=f'conv{len(layer_sizes)}', bn_decay=bn_decay)
net = tf_util_dgcnn.max_pool2d(net, [num_point, 1], padding='VALID', scope='maxpool')
return net
示例3: single_encoding_net
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def single_encoding_net(pc, mlp_list, mlp_list2, scope, is_training, bn_decay):
''' The encoding network for instance
Input:
pc: [B, N, 3]
Return:
net: [B, nfea]
'''
with tf.variable_scope(scope) as myscope:
net = tf.expand_dims(pc, 2)
for i,num_out_channel in enumerate(mlp_list):
net = tf_util.conv2d(net, num_out_channel, [1,1],
padding='VALID', stride=[1,1],
bn=True, is_training=is_training,
scope='conv%d'%i, bn_decay=bn_decay)
net = tf.reduce_max(net, axis=[1])
net = tf.squeeze(net, 1)
for i,num_out_channel in enumerate(mlp_list2):
net = tf_util.fully_connected(net, num_out_channel, bn=True, is_training=is_training,
scope='fc%d'%i, bn_decay=bn_decay)
return net
示例4: build
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def build(self,
inputs,
num_outputs,
scope=None,
activation_fn=tf.nn.relu,
is_training=None):
''' Build Multi-layer preceptrons '''
outputs = tf_util.conv2d(inputs,
num_outputs,
self.kernel_size,
padding=self.padding,
stride=self.stride,
bn=self.bn,
is_training=is_training,
weight_decay=self.weight_decay,
activation_fn = activation_fn,
scope=scope,
bn_decay=self.bn_decay,
is_dist=self.is_dist)
return outputs
示例5: weight_net
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def weight_net(xyz, hidden_units, scope, is_training, bn_decay=None, weight_decay=None,
activation_fn=tf.nn.relu, is_dist=False):
with tf.variable_scope(scope) as sc:
net = xyz
for i, num_hidden_units in enumerate(hidden_units):
if i != len(hidden_units) - 1:
net = tf_util.conv2d(net, num_hidden_units, [1, 1],
padding='VALID', stride=[1, 1],
bn=True, is_training=is_training, activation_fn=activation_fn,
scope='wconv{}'.format(i), bn_decay=bn_decay,
weight_decay=weight_decay, is_dist=is_dist)
else:
net = tf_util.conv2d(net, num_hidden_units, [1, 1],
padding='VALID', stride=[1, 1],
bn=False, is_training=is_training, activation_fn=None,
scope='wconv{}'.format(i), bn_decay=bn_decay,
weight_decay=weight_decay, is_dist=is_dist)
# net = tf_util.dropout(net, keep_prob=0.5, is_training=is_training, scope='wconv_dp{}'.format(i))
return net
示例6: nonlinear_transform
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def nonlinear_transform(data_in, mlp, scope, is_training, bn_decay=None, weight_decay=None,
activation_fn=tf.nn.relu, is_dist=False):
with tf.variable_scope(scope) as sc:
net = data_in
l = len(mlp)
if l > 1:
for i, out_ch in enumerate(mlp[0:(l - 1)]):
net = tf_util.conv2d(net, out_ch, [1, 1],
padding='VALID', stride=[1, 1],
bn=True, is_training=is_training, activation_fn=tf.nn.relu,
scope='nonlinear{}'.format(i), bn_decay=bn_decay,
weight_decay=weight_decay, is_dist=is_dist)
# net = tf_util.dropout(net, keep_prob=0.5, is_training=is_training, scope='dp_nonlinear{}'.format(i))
net = tf_util.conv2d(net, mlp[-1], [1, 1],
padding='VALID', stride=[1, 1],
bn=False, is_training=is_training,
scope='nonlinear%d' % (l - 1), bn_decay=bn_decay,
activation_fn=tf.nn.sigmoid, weight_decay=weight_decay, is_dist=is_dist)
return net
示例7: get_model
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def get_model(source_point_cloud, template_point_cloud, is_training, bn_decay=None):
point_cloud = tf.concat([source_point_cloud, template_point_cloud],0)
batch_size = point_cloud.get_shape()[0].value
num_point = point_cloud.get_shape()[1].value
end_points = {}
input_image = tf.expand_dims(point_cloud, -1)
net = tf_util.conv2d(input_image, 64, [1,3],
padding='VALID', stride=[1,1],
bn=False, is_training=is_training,
scope='conv1', bn_decay=bn_decay)
net = tf_util.conv2d(net, 64, [1,1],
padding='VALID', stride=[1,1],
bn=False, is_training=is_training,
scope='conv2', bn_decay=bn_decay)
net = tf_util.conv2d(net, 64, [1,1],
padding='VALID', stride=[1,1],
bn=False, is_training=is_training,
scope='conv3', bn_decay=bn_decay)
net = tf_util.conv2d(net, 128, [1,1],
padding='VALID', stride=[1,1],
bn=False, is_training=is_training,
scope='conv4', bn_decay=bn_decay)
net = tf_util.conv2d(net, 1024, [1,1],
padding='VALID', stride=[1,1],
bn=False, is_training=is_training,
scope='conv5', bn_decay=bn_decay)
# Symmetric function: max pooling
net = tf_util.max_pool2d(net, [num_point,1],
padding='VALID', scope='maxpool')
net = tf.reshape(net, [batch_size, -1])
source_global_feature = tf.slice(net, [0,0], [int(batch_size/2),1024])
template_global_feature = tf.slice(net, [int(batch_size/2),0], [int(batch_size/2),1024])
return source_global_feature, template_global_feature
示例8: get_model
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def get_model(self, source_point_cloud, template_point_cloud, feature_size, is_training, bn_decay=None):
point_cloud = tf.concat([source_point_cloud, template_point_cloud], 0)
batch_size = point_cloud.get_shape()[0].value
num_point = point_cloud.get_shape()[1].value
end_points = {}
input_image = tf.expand_dims(point_cloud, -1)
net = tf_util.conv2d(input_image, 64, [1,3],
padding='VALID', stride=[1,1],
bn=False, is_training=is_training,
scope='conv1', bn_decay=bn_decay)
net = tf_util.conv2d(net, 64, [1,1],
padding='VALID', stride=[1,1],
bn=False, is_training=is_training,
scope='conv2', bn_decay=bn_decay)
net = tf_util.conv2d(net, 64, [1,1],
padding='VALID', stride=[1,1],
bn=False, is_training=is_training,
scope='conv3', bn_decay=bn_decay)
net = tf_util.conv2d(net, 128, [1,1],
padding='VALID', stride=[1,1],
bn=False, is_training=is_training,
scope='conv4', bn_decay=bn_decay)
net = tf_util.conv2d(net, feature_size, [1,1],
padding='VALID', stride=[1,1],
bn=False, is_training=is_training,
scope='conv5', bn_decay=bn_decay)
# Symmetric function: max pooling
net = tf_util.max_pool2d(net, [num_point,1],
padding='VALID', scope='maxpool')
net = tf.reshape(net, [batch_size, -1])
# Extract the features from the network.
source_global_feature = tf.slice(net, [0,0], [int(batch_size/2),feature_size])
template_global_feature = tf.slice(net, [int(batch_size/2),0], [int(batch_size/2),feature_size])
return source_global_feature, template_global_feature
示例9: pointnet_sa_module_msg
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def pointnet_sa_module_msg(xyz, points, npoint, radius_list, nsample_list, mlp_list, is_training, bn_decay, scope, bn=True, use_xyz=True, use_nchw=False):
''' PointNet Set Abstraction (SA) module with Multi-Scale Grouping (MSG)
Input:
xyz: (batch_size, ndataset, 3) TF tensor
points: (batch_size, ndataset, channel) TF tensor
npoint: int32 -- #points sampled in farthest point sampling
radius: list of float32 -- search radius in local region
nsample: list of int32 -- how many points in each local region
mlp: list of list of int32 -- output size for MLP on each point
use_xyz: bool, if True concat XYZ with local point features, otherwise just use point features
use_nchw: bool, if True, use NCHW data format for conv2d, which is usually faster than NHWC format
Return:
new_xyz: (batch_size, npoint, 3) TF tensor
new_points: (batch_size, npoint, \sum_k{mlp[k][-1]}) TF tensor
'''
data_format = 'NCHW' if use_nchw else 'NHWC'
with tf.variable_scope(scope) as sc:
new_xyz = gather_point(xyz, farthest_point_sample(npoint, xyz))
new_points_list = []
for i in range(len(radius_list)):
radius = radius_list[i]
nsample = nsample_list[i]
idx, pts_cnt = query_ball_point(radius, nsample, xyz, new_xyz)
grouped_xyz = group_point(xyz, idx)
grouped_xyz -= tf.tile(tf.expand_dims(new_xyz, 2), [1,1,nsample,1])
if points is not None:
grouped_points = group_point(points, idx)
if use_xyz:
grouped_points = tf.concat([grouped_points, grouped_xyz], axis=-1)
else:
grouped_points = grouped_xyz
if use_nchw: grouped_points = tf.transpose(grouped_points, [0,3,1,2])
for j,num_out_channel in enumerate(mlp_list[i]):
grouped_points = tf_util.conv2d(grouped_points, num_out_channel, [1,1],
padding='VALID', stride=[1,1], bn=bn, is_training=is_training,
scope='conv%d_%d'%(i,j), bn_decay=bn_decay)
if use_nchw: grouped_points = tf.transpose(grouped_points, [0,2,3,1])
new_points = tf.reduce_max(grouped_points, axis=[2])
new_points_list.append(new_points)
new_points_concat = tf.concat(new_points_list, axis=-1)
return new_xyz, new_points_concat
示例10: pointnet_fp_module
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def pointnet_fp_module(xyz1, xyz2, points1, points2, mlp, is_training, bn_decay, scope, bn=True):
''' PointNet Feature Propogation (FP) Module
Input:
xyz1: (batch_size, ndataset1, 3) TF tensor
xyz2: (batch_size, ndataset2, 3) TF tensor, sparser than xyz1
points1: (batch_size, ndataset1, nchannel1) TF tensor
points2: (batch_size, ndataset2, nchannel2) TF tensor
mlp: list of int32 -- output size for MLP on each point
Return:
new_points: (batch_size, ndataset1, mlp[-1]) TF tensor
'''
with tf.variable_scope(scope) as sc:
dist, idx = three_nn(xyz1, xyz2)
dist = tf.maximum(dist, 1e-10)
norm = tf.reduce_sum((1.0/dist),axis=2,keep_dims=True)
norm = tf.tile(norm,[1,1,3])
weight = (1.0/dist) / norm
interpolated_points = three_interpolate(points2, idx, weight)
if points1 is not None:
new_points1 = tf.concat(axis=2, values=[interpolated_points, points1]) # B,ndataset1,nchannel1+nchannel2
else:
new_points1 = interpolated_points
new_points1 = tf.expand_dims(new_points1, 2)
for i, num_out_channel in enumerate(mlp):
new_points1 = tf_util.conv2d(new_points1, num_out_channel, [1,1],
padding='VALID', stride=[1,1],
bn=bn, is_training=is_training,
scope='conv_%d'%(i), bn_decay=bn_decay)
new_points1 = tf.squeeze(new_points1, [2]) # B,ndataset1,mlp[-1]
return new_points1
示例11: feature_transform_net
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def feature_transform_net(inputs, is_training, bn_decay=None, K=64):
""" Feature Transform Net, input is BxNx1xK
Return:
Transformation matrix of size KxK """
batch_size = inputs.get_shape()[0].value
num_point = inputs.get_shape()[1].value
net = tf_util.conv2d(inputs, 64, [1,1],
padding='VALID', stride=[1,1],
bn=True, is_training=is_training,
scope='tconv1', bn_decay=bn_decay)
net = tf_util.conv2d(net, 128, [1,1],
padding='VALID', stride=[1,1],
bn=True, is_training=is_training,
scope='tconv2', bn_decay=bn_decay)
net = tf_util.conv2d(net, 1024, [1,1],
padding='VALID', stride=[1,1],
bn=True, is_training=is_training,
scope='tconv3', bn_decay=bn_decay)
net = tf_util.max_pool2d(net, [num_point,1],
padding='VALID', scope='tmaxpool')
net = tf.reshape(net, [batch_size, -1])
net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training,
scope='tfc1', bn_decay=bn_decay)
net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training,
scope='tfc2', bn_decay=bn_decay)
with tf.variable_scope('transform_feat') as sc:
weights = tf.get_variable('weights', [256, K*K],
initializer=tf.constant_initializer(0.0),
dtype=tf.float32)
biases = tf.get_variable('biases', [K*K],
initializer=tf.constant_initializer(0.0),
dtype=tf.float32)
biases += tf.constant(np.eye(K).flatten(), dtype=tf.float32)
transform = tf.matmul(net, weights)
transform = tf.nn.bias_add(transform, biases)
transform = tf.reshape(transform, [batch_size, K, K])
return transform
示例12: pointnet_fp_module
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def pointnet_fp_module(xyz1, xyz2, points1, points2, mlp, is_training, bn_decay, scope, bn=True):
''' PointNet Feature Propogation (FP) Module
Input:
xyz1: (batch_size, ndataset1, 3) TF tensor
xyz2: (batch_size, ndataset2, 3) TF tensor, sparser than xyz1
points1: (batch_size, ndataset1, nchannel1) TF tensor
points2: (batch_size, ndataset2, nchannel2) TF tensor
mlp: list of int32 -- output size for MLP on each point
Return:
new_points: (batch_size, ndataset1, mlp[-1]) TF tensor
'''
with tf.variable_scope(scope) as sc:
dist, idx = three_nn(xyz1, xyz2)
dist = tf.maximum(dist, 1e-10)
norm = tf.reduce_sum((1.0/dist),axis=2, keepdims=True)
norm = tf.tile(norm,[1,1,3])
weight = (1.0/dist) / norm
interpolated_points = three_interpolate(points2, idx, weight)
if points1 is not None:
new_points1 = tf.concat(axis=2, values=[interpolated_points, points1]) # B,ndataset1,nchannel1+nchannel2
else:
new_points1 = interpolated_points
new_points1 = tf.expand_dims(new_points1, 2)
for i, num_out_channel in enumerate(mlp):
new_points1 = tf_util.conv2d(new_points1, num_out_channel, [1,1],
padding='VALID', stride=[1,1],
bn=bn, is_training=is_training,
scope='conv_%d'%(i), bn_decay=bn_decay)
new_points1 = tf.squeeze(new_points1, [2]) # B,ndataset1,mlp[-1]
return new_points1
示例13: _get_pointnet
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def _get_pointnet(pcs_extended, layer_sizes, scope_name, is_training, bn_decay):
assert len(layer_sizes) > 0
num_point = pcs_extended.shape[1]
num_channel = pcs_extended.shape[2]
with tf.variable_scope(scope_name):
# Point functions (MLP implemented as conv2d)
net = tf_util.conv2d(pcs_extended, layer_sizes[0], [1, num_channel], padding='VALID', stride=[1, 1], bn=True, is_training=is_training, scope='conv1', bn_decay=bn_decay)
for idx, layer_size in enumerate(layer_sizes[1:]):
net = tf_util.conv2d(net, layer_size, [1, 1], padding='VALID', stride=[1, 1], bn=True, is_training=is_training, scope=f'conv{idx+2}', bn_decay=bn_decay)
net = tf_util.max_pool2d(net, [num_point, 1], padding='VALID', scope='maxpool')
return net
示例14: pointnet_fp_module
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def pointnet_fp_module(xyz1, xyz2, points1, points2, mlp, is_training, bn_decay, scope, bn=True):
''' PointNet Feature Propogation (FP) Module
Input:
xyz1: (batch_size, ndataset1, 3) TF tensor
xyz2: (batch_size, ndataset2, 3) TF tensor, sparser than xyz1
points1: (batch_size, ndataset1, nchannel1) TF tensor
points2: (batch_size, ndataset2, nchannel2) TF tensor
mlp: list of int32 -- output size for MLP on each point
Return:
new_points: (batch_size, ndataset1, mlp[-1]) TF tensor
'''
with tf.variable_scope(scope) as sc:
dist, idx = three_nn(xyz1, xyz2)
dist = tf.maximum(dist, 1e-10)
norm = tf.reduce_sum((1.0/dist),axis=2,keepdims=True)
norm = tf.tile(norm,[1,1,3])
weight = (1.0/dist) / norm
interpolated_points = three_interpolate(points2, idx, weight)
if points1 is not None:
new_points1 = tf.concat(axis=2, values=[interpolated_points, points1]) # B,ndataset1,nchannel1+nchannel2
else:
new_points1 = interpolated_points
new_points1 = tf.expand_dims(new_points1, 2)
for i, num_out_channel in enumerate(mlp):
new_points1 = tf_util.conv2d(new_points1, num_out_channel, [1,1],
padding='VALID', stride=[1,1],
bn=bn, is_training=is_training,
scope='conv_%d'%(i), bn_decay=bn_decay)
new_points1 = tf.squeeze(new_points1, [2]) # B,ndataset1,mlp[-1]
return new_points1
示例15: get_center_regression_net
# 需要導入模塊: import tf_util [as 別名]
# 或者: from tf_util import conv2d [as 別名]
def get_center_regression_net(object_point_cloud, one_hot_vec,
is_training, bn_decay, end_points):
''' Regression network for center delta. a.k.a. T-Net.
Input:
object_point_cloud: TF tensor in shape (B,M,C)
point clouds in 3D mask coordinate
one_hot_vec: TF tensor in shape (B,3)
length-3 vectors indicating predicted object type
Output:
predicted_center: TF tensor in shape (B,3)
'''
num_point = object_point_cloud.get_shape()[1].value
net = tf.expand_dims(object_point_cloud, 2)
net = tf_util.conv2d(net, 128, [1,1],
padding='VALID', stride=[1,1],
bn=True, is_training=is_training,
scope='conv-reg1-stage1', bn_decay=bn_decay)
net = tf_util.conv2d(net, 128, [1,1],
padding='VALID', stride=[1,1],
bn=True, is_training=is_training,
scope='conv-reg2-stage1', bn_decay=bn_decay)
net = tf_util.conv2d(net, 256, [1,1],
padding='VALID', stride=[1,1],
bn=True, is_training=is_training,
scope='conv-reg3-stage1', bn_decay=bn_decay)
net = tf_util.max_pool2d(net, [num_point,1],
padding='VALID', scope='maxpool-stage1')
net = tf.squeeze(net, axis=[1,2])
net = tf.concat([net, one_hot_vec], axis=1)
net = tf_util.fully_connected(net, 256, scope='fc1-stage1', bn=True,
is_training=is_training, bn_decay=bn_decay)
net = tf_util.fully_connected(net, 128, scope='fc2-stage1', bn=True,
is_training=is_training, bn_decay=bn_decay)
predicted_center = tf_util.fully_connected(net, 3, activation_fn=None,
scope='fc3-stage1')
return predicted_center, end_points