import logging
import os
import pickle
import time
import itertools
import tensorflow as tf
from tensorflow.contrib.losses.python.metric_learning import triplet_semihard_loss
import numpy as np
from .util import AttrDict
from .util import tf_config
from . import util
from . import spherical
from . import tfnp_compatibility as tfnp
from . import params
from .layers import * # !!!
from . import datasets # !!!
logger = logging.getLogger('logger')
def dup(x):
""" Return two references for input; useful when creating NNs and storing references to layers """
return [x, x]
def init_block(args, dset=None):
net = {}
if dset is None:
net['input'], curr = dup(tf.placeholder(args.dtype,
shape=(None, *get_indim(args)[1:])))
net['label'] = tf.placeholder('int64', shape=[None])
else:
# dset is tuple (iterator, init_ops); iterator returns input and label
net['input'], net['label'] = dset[0].get_next()
curr = net['input']
net['training'] = tf.placeholder('bool', shape=(), name='is_training')
return net, curr
def init_sphcnn(args):
method = args.transform_method
real = args.real_inputs
if method == 'naive':
fun = lambda *args, **kwargs: spherical.sph_harm_all(*args, **kwargs, real=real)
with tf.name_scope('harmonics_or_legendre'):
res = args.input_res
harmonics = [fun(res // (2**i), as_tfvar=True) for i in range(sum(args.pool_layers) + 1)]
return harmonics
def two_branch(args, convfun=sphconv, **kwargs):
""" Model, that splits input in two branches, and concatenate intermediate feature maps. """
method = args.transform_method
l_or_h = init_sphcnn(args)
net, curr = init_block(args, **kwargs)
assert tfnp.shape(curr)[-1] == 2
curr = [curr[..., 0][..., np.newaxis],
curr[..., 1][..., np.newaxis]]
# indices for legendre or harmonics
high = 0
low = 1
for i, (nf, pool, concat) in enumerate(zip(args.nfilters, args.pool_layers, args.concat_branches)):
for b in [0, 1]:
name = 'conv{}_b{}'.format(i, b)
if concat and b == 0:
# top branch also receives features from bottom branch
curr[b] = tf.concat(curr, axis=-1)
if not pool:
with tf.variable_scope(name):
net[name], curr[b] = dup(block(args, convfun, net['training'], curr[b], nf,
n_filter_params=args.n_filter_params,
harmonics_or_legendre=l_or_h[high],
method=method))
else:
with tf.variable_scope(name):
# force spectral pool in first layer if spectral input
spectral_pool = True if (args.spectral_input and i == 0) else args.spectral_pool
net[name], curr[b] = dup(block(args, convfun, net['training'], curr[b], nf,
n_filter_params=args.n_filter_params,
harmonics_or_legendre=l_or_h[high],
method=method,
spectral_pool=pool if spectral_pool else 0,
harmonics_or_legendre_low=l_or_h[low]))
if not spectral_pool:
# weighted avg pooling
if args.pool == 'wap':
curr[b] = area_weights(tf.layers.average_pooling2d(area_weights(curr[b]),
2*pool, 2*pool,
'same'),
invert=True)
elif args.pool == 'avg':
curr[b] = tf.layers.average_pooling2d(curr[b],
2*pool, 2*pool,
'same')
elif args.pool == 'max':
curr[b] = tf.layers.max_pooling2d(curr[b],
2*pool, 2*pool,
'same')
else:
raise ValueError('args.pool')
if pool:
high += 1
low += 1
# combine for final layer
curr = tf.concat(curr, axis=-1)
return sphcnn_afterconv(curr, net, args, l_or_h[high])
def sphcnn_afterconv(curr, net, args, l_or_h):
""" Part of model after convolutional layers;
should be common for different architectures. """
# normalize by area before computing the mean
with tf.name_scope('wsa'):
if args.weighted_sph_avg:
n = tfnp.shape(curr)[1]
phi, theta = util.sph_sample(n)
phi += np.diff(phi)[0]/2
curr *= np.sin(phi)[np.newaxis, np.newaxis, :, np.newaxis]
net['final_conv'] = curr
if 'complex' in args.model:
curr = tf.abs(curr)
nlin = 'relu'
else:
nlin = args.nonlin
# curr is last conv layer
with tf.name_scope('final_pool'):
net['gap'] = tf.reduce_mean(curr, axis=(1, 2))
if args.final_pool in ['max', 'all']:
net['max'] = tf.reduce_max(curr, axis=(1, 2))
if args.final_pool in ['magnitudes', 'all']:
net['final_coeffs'] = spherical.sph_harm_transform_batch(curr,
method=args.transform_method,
harmonics=l_or_h,
m0_only=False)
# use per frequency magnitudes
net['magnitudes'] = tf.contrib.layers.flatten(tf.reduce_sum(tf.square(net['final_coeffs']),
axis=(1, 3)))
net['magnitudes'] = tf.real(net['magnitudes'])
if args.final_pool != 'all':
curr = net[args.final_pool]
else:
curr = tf.concat([net['gap'], net['max'], net['magnitudes']], axis=-1)
if args.dropout:
curr = tf.nn.dropout(curr,
keep_prob=tf.cond(net['training'],
lambda: 0.5,
lambda: 1.0))
if not args.no_final_fc:
with tf.variable_scope('fc1') as scope:
net['fc1'], curr = dup(block(AttrDict({**args.__dict__,
'batch_norm': False,
'nonlin': nlin}),
tf.layers.dense, net['training'], curr, 64))
if args.dropout:
curr = tf.nn.dropout(curr,
keep_prob=tf.cond(net['training'],
lambda: 0.5,
lambda: 1.0))
for v in scope.trainable_variables():
tf.summary.histogram(v.name, v)
net['descriptor'] = curr
if args.triplet_loss:
norm_desc = tf.nn.l2_normalize(curr, dim=-1)
# this only works w/ fixed batch size
triplet_loss = triplet_semihard_loss(tf.cast(tf.reshape(net['label'],
(args.train_bsize,)),
'int32'),
norm_desc)
# NaNs may appear if bsize is small:
triplet_
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
xing hu , yi an, cheng shao, pan qin, Journal of Physics: Conference Series.研究畸变卷积,由拟合马路牙子,得出曲率,最后由曲率进一步得出卷积核偏置。 设计FE分支,由sobel图作为他的标签,提高对边界的分割精度。实验证明精度有提高。
资源推荐
资源详情
资源评论
收起资源包目录
A new deep distortion convolutional neural network for semantic (232个子文件)
_classes_weights.npy 168B
models.py 23KB
attention_module.py 20KB
drn.py 14KB
train.py 14KB
batchnorm.py 13KB
s2_mm.py 12KB
xception.py 11KB
so3_mm.py 10KB
curve.py 9KB
networks.py 9KB
params.py 7KB
test.py 7KB
custom_transforms.py 7KB
resnet.py 6KB
pascal.py 6KB
coco.py 6KB
mobilenet.py 5KB
cityscapes.py 5KB
deeplab.py 5KB
layers.py 5KB
resnet.py 5KB
comm.py 4KB
sbd.py 4KB
aspp.py 4KB
util.py 4KB
utils.py 3KB
combine_dbs.py 3KB
replicate.py 3KB
gen_kernel.py 3KB
lr_scheduler.py 3KB
saver.py 2KB
__init__.py 2KB
loss.py 2KB
metrics.py 2KB
decoder.py 2KB
decoder1.py 2KB
undistortion.py 2KB
datasets.py 2KB
basic_layers.py 2KB
summaries.py 1KB
spherical.py 1017B
calculate_weights.py 956B
dis_convolutional.py 919B
unittest.py 834B
mypath.py 771B
__init__.py 514B
sobel.py 463B
__init__.py 447B
sample_on_line.py 367B
sample_on_line1.py 283B
adaptive_conv.py 205B
new1.py 81B
__init__.py 0B
__init__.py 0B
batchnorm.cpython-35.pyc 13KB
batchnorm.cpython-38.pyc 13KB
batchnorm.cpython-36.pyc 13KB
batchnorm.cpython-37.pyc 13KB
batchnorm.cpython-39.pyc 13KB
drn.cpython-35.pyc 12KB
spherical.cpython-37.pyc 12KB
spherical.cpython-36.pyc 12KB
drn.cpython-36.pyc 11KB
drn.cpython-37.pyc 11KB
drn.cpython-38.pyc 10KB
drn.cpython-39.pyc 10KB
xception.cpython-35.pyc 8KB
networks.cpython-35.pyc 8KB
custom_transforms.cpython-35.pyc 7KB
networks.cpython-36.pyc 7KB
networks.cpython-37.pyc 7KB
networks.cpython-38.pyc 7KB
networks.cpython-39.pyc 7KB
xception.cpython-38.pyc 7KB
xception.cpython-39.pyc 7KB
xception.cpython-36.pyc 7KB
xception.cpython-37.pyc 7KB
custom_transforms.cpython-38.pyc 6KB
custom_transforms.cpython-39.pyc 6KB
deeplab.cpython-35.pyc 6KB
custom_transforms.cpython-37.pyc 6KB
cityscapes.cpython-36.pyc 6KB
pascal.cpython-35.pyc 6KB
coco.cpython-36.pyc 6KB
resnet.cpython-35.pyc 6KB
resnet.cpython-37.pyc 5KB
deeplab.cpython-39.pyc 5KB
resnet.cpython-36.pyc 5KB
resnet.cpython-38.pyc 5KB
resnet.cpython-39.pyc 5KB
comm.cpython-35.pyc 5KB
comm.cpython-39.pyc 5KB
comm.cpython-38.pyc 5KB
pascal.cpython-38.pyc 5KB
pascal.cpython-39.pyc 5KB
custom_transforms.cpython-36.pyc 5KB
comm.cpython-37.pyc 5KB
comm.cpython-36.pyc 5KB
resnet.cpython-35.pyc 5KB
共 232 条
- 1
- 2
- 3
资源评论
accdgh
- 粉丝: 1
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功