代码拉取完成,页面将自动刷新
同步操作将从 chenmingling/MRI_Deep_learning 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import tensorflow as tf
import tensorflow.contrib.slim as slim
"""
Creates a convolutional residual block
as defined in the paper. More on
this inside model.py
x: input to pass through the residual block
channels: number of channels to compute
stride: convolution stride
"""
def resBlock(x,channels=64,kernel_size=[3,3],scale=1):
tmp = slim.conv2d(x,channels,kernel_size,activation_fn=None)
tmp = tf.nn.relu(tmp)
tmp = slim.conv2d(tmp,channels,kernel_size,activation_fn=None)
tmp *= scale
return x + tmp
"""
Method to upscale an image using
conv2d transpose. Based on upscaling
method defined in the paper
x: input to be upscaled
scale: scale increase of upsample
features: number of features to compute
activation: activation function
"""
def upsample(x,channels=2,scale=2,features=64,activation=tf.nn.relu):
assert scale in [1,2,3,4]
x = slim.conv2d(x,features,[3,3],activation_fn=activation)
if scale == 1:
x = slim.conv2d(x, 1, [3, 3], activation_fn=activation)
if scale == 2:
ps_features = channels*(scale**2)
x = slim.conv2d(x,ps_features,[3,3],activation_fn=activation)
##add by mingliang
# x = PS_complex(x, 2, color=False)
# x = PS_complex_multi_channel(x, 2, color=False)
x = PS(x, 2, color=False)
# x = PS(x,2,color=True)
elif scale == 3:
ps_features =3*(scale**2)
x = slim.conv2d(x,ps_features,[3,3],activation_fn=activation)
#x = slim.conv2d_transpose(x,ps_features,9,stride=1,activation_fn=activation)
x = PS(x,3,color=True)
elif scale == 4:
ps_features = 3*(2**2)
for i in range(2):
x = slim.conv2d(x,ps_features,[3,3],activation_fn=activation)
#x = slim.conv2d_transpose(x,ps_features,6,stride=1,activation_fn=activation)
x = PS(x,2,color=True)
return x
"""
Borrowed from https://github.com/tetrachrome/subpixel
Used for subpixel phase shifting after deconv operations
"""
def _phase_shift(I, r):
bsize, a, b, c = I.get_shape().as_list()
bsize = tf.shape(I)[0] # Handling Dimension(None) type for undefined batch dim
X = tf.reshape(I, (bsize, a, b, r, r))
X = tf.transpose(X, (0, 1, 2, 4, 3)) # bsize, a, b, 1, 1
X = tf.split(X, a, 1) # a, [bsize, b, r, r]
X = tf.concat([tf.squeeze(x, axis=1) for x in X],2) # bsize, b, a*r, r
X = tf.split(X, b, 1) # b, [bsize, a*r, r]
X = tf.concat([tf.squeeze(x, axis=1) for x in X],2) # bsize, a*r, b*r
return tf.reshape(X, (bsize, a*r, b*r, 1))
"""
Borrowed from https://github.com/tetrachrome/subpixel
Used for subpixel phase shifting after deconv operations
"""
def PS(X, r, color=False):
if color:
Xc = tf.split(X, 3, 3)
X = tf.concat([_phase_shift(x, r) for x in Xc],3)
else:
X = _phase_shift(X, r)
return X
def PS_complex(X, r, color=False):
Xc = tf.split(X, 2, 3)
X = tf.concat([_phase_shift(x, r) for x in Xc],3)
return X
def PS_complex_multi_channel(X, r, color=False):
Xc = tf.split(X, 12, 3)
X = tf.concat([_phase_shift(x, r) for x in Xc],3)
return X
"""
Tensorflow log base 10.
Found here: https://github.com/tensorflow/tensorflow/issues/1666
"""
def log10(x):
numerator = tf.log(x)
denominator = tf.log(tf.constant(10, dtype=numerator.dtype))
return numerator / denominator
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。