本文整理匯總了Python中keras.layers.Conv2DTranspose方法的典型用法代碼示例。如果您正苦於以下問題:Python layers.Conv2DTranspose方法的具體用法?Python layers.Conv2DTranspose怎麽用?Python layers.Conv2DTranspose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類keras.layers
的用法示例。
在下文中一共展示了layers.Conv2DTranspose方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: build_mbllen
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def build_mbllen(input_shape):
def EM(input, kernal_size, channel):
conv_1 = Conv2D(channel, (3, 3), activation='relu', padding='same', data_format='channels_last')(input)
conv_2 = Conv2D(channel, (kernal_size, kernal_size), activation='relu', padding='valid', data_format='channels_last')(conv_1)
conv_3 = Conv2D(channel*2, (kernal_size, kernal_size), activation='relu', padding='valid', data_format='channels_last')(conv_2)
conv_4 = Conv2D(channel*4, (kernal_size, kernal_size), activation='relu', padding='valid', data_format='channels_last')(conv_3)
conv_5 = Conv2DTranspose(channel*2, (kernal_size, kernal_size), activation='relu', padding='valid', data_format='channels_last')(conv_4)
conv_6 = Conv2DTranspose(channel, (kernal_size, kernal_size), activation='relu', padding='valid', data_format='channels_last')(conv_5)
res = Conv2DTranspose(3, (kernal_size, kernal_size), activation='relu', padding='valid', data_format='channels_last')(conv_6)
return res
inputs = Input(shape=input_shape)
FEM = Conv2D(32, (3, 3), activation='relu', padding='same', data_format='channels_last')(inputs)
EM_com = EM(FEM, 5, 8)
for j in range(3):
for i in range(0, 3):
FEM = Conv2D(32, (3, 3), activation='relu', padding='same', data_format='channels_last')(FEM)
EM1 = EM(FEM, 5, 8)
EM_com = Concatenate(axis=3)([EM_com, EM1])
outputs = Conv2D(3, (1, 1), activation='relu', padding='same', data_format='channels_last')(EM_com)
return Model(inputs, outputs)
示例2: Transpose2D_block
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def Transpose2D_block(filters, stage, kernel_size=(3,3), upsample_rate=(2,2),
transpose_kernel_size=(4,4), use_batchnorm=False, skip=None):
def layer(input_tensor):
conv_name, bn_name, relu_name, up_name = handle_block_names(stage)
x = Conv2DTranspose(filters, transpose_kernel_size, strides=upsample_rate,
padding='same', name=up_name, use_bias=not(use_batchnorm))(input_tensor)
if use_batchnorm:
x = BatchNormalization(name=bn_name+'1')(x)
x = Activation('relu', name=relu_name+'1')(x)
if skip is not None:
x = Concatenate()([x, skip])
x = ConvRelu(filters, kernel_size, use_batchnorm=use_batchnorm,
conv_name=conv_name + '2', bn_name=bn_name + '2', relu_name=relu_name + '2')(x)
return x
return layer
示例3: Conv2DTranspose
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def Conv2DTranspose(filters,
upsample_rate,
kernel_size=(4,4),
up_name='up',
**kwargs):
#if not tuple(upsample_rate) == (2,2):
# raise NotImplementedError(
# f'Conv2DTranspose support only upsample_rate=(2, 2), got {upsample_rate}')
def layer(input_tensor):
x = Transpose(filters,
kernel_size=kernel_size,
strides=upsample_rate,
padding='same',
name=up_name)(input_tensor)
return x
return layer
示例4: Conv2DTranspose
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def Conv2DTranspose(filters,
upsample_rate,
kernel_size=(4,4),
up_name='up',
**kwargs):
if not tuple(upsample_rate) == (2,2):
raise NotImplementedError(
f'Conv2DTranspose support only upsample_rate=(2, 2), got {upsample_rate}')
def layer(input_tensor):
x = Transpose(filters,
kernel_size=kernel_size,
strides=upsample_rate,
padding='same',
name=up_name)(input_tensor)
return x
return layer
示例5: fsrcnn
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def fsrcnn(x, d=56, s=12, m=4, scale=3):
"""Build an FSRCNN model.
See https://arxiv.org/abs/1608.00367
"""
model = Sequential()
model.add(InputLayer(input_shape=x.shape[-3:]))
c = x.shape[-1]
f = [5, 1] + [3] * m + [1]
n = [d, s] + [s] * m + [d]
for ni, fi in zip(n, f):
model.add(Conv2D(ni, fi, padding='same',
kernel_initializer='he_normal', activation='relu'))
model.add(Conv2DTranspose(c, 9, strides=scale, padding='same',
kernel_initializer='he_normal'))
return model
示例6: nsfsrcnn
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def nsfsrcnn(x, d=56, s=12, m=4, scale=3, pos=1):
"""Build an FSRCNN model, but change deconv position.
See https://arxiv.org/abs/1608.00367
"""
model = Sequential()
model.add(InputLayer(input_shape=x.shape[-3:]))
c = x.shape[-1]
f1 = [5, 1] + [3] * pos
n1 = [d, s] + [s] * pos
f2 = [3] * (m - pos - 1) + [1]
n2 = [s] * (m - pos - 1) + [d]
f3 = 9
n3 = c
for ni, fi in zip(n1, f1):
model.add(Conv2D(ni, fi, padding='same',
kernel_initializer='he_normal', activation='relu'))
model.add(Conv2DTranspose(s, 3, strides=scale, padding='same',
kernel_initializer='he_normal'))
for ni, fi in zip(n2, f2):
model.add(Conv2D(ni, fi, padding='same',
kernel_initializer='he_normal', activation='relu'))
model.add(Conv2D(n3, f3, padding='same',
kernel_initializer='he_normal'))
return model
示例7: classification_branch_wrapper
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def classification_branch_wrapper(self, input, softmax_trainable=False):
x = self.res_block(input, filter=128, stages=9, block=4)
# all layers before OPI
x = Conv2D(filters=5, kernel_size=(1, 1), padding='same', name='conv2d_after_fourth_resblock',
kernel_regularizer=keras.regularizers.l2(self.l2r))(x)
x = BatchNormalization(name='bn_after_fourth_resblock')(x)
x = Activation('relu',name='relu_after_fourth_resblock')(x)
x = Conv2DTranspose(filters=5, kernel_size=(3, 3),
strides=(2, 2), padding='same',
kernel_regularizer=keras.regularizers.l2(self.l2r),
name='secondlast_deconv_before_cls')(x)
x = BatchNormalization(name='secondlast_bn_before_cls')(x)
x = Activation('relu', name='last_relu_before_cls')(x)
x = Conv2DTranspose(filters=5, kernel_size=(3, 3),
strides=(2, 2), padding='same',
kernel_regularizer=keras.regularizers.l2(self.l2r),
name='last_deconv_before_cls')(x)
x_output = BatchNormalization(name='last_bn_before_cls')(x)
if softmax_trainable == True:
x_output = Activation('softmax', name='Classification_output')(x_output)
return x_output
示例8: modelGenerator
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def modelGenerator(self, name):
inputImg = Input(shape=self.latent_dim)
# Layer 1: 1 res block
x = self.resblk(inputImg, 256)
# Layer 2: 2 res block
x = self.resblk(x, 256)
# Layer 3: 3 res block
x = self.resblk(x, 256)
# Layer 4:
x = Conv2DTranspose(128, kernel_size=3, strides=2, padding='same')(x)
x = LeakyReLU(alpha=0.01)(x)
# Layer 5:
x = Conv2DTranspose(64, kernel_size=3, strides=2, padding='same')(x)
x = LeakyReLU(alpha=0.01)(x)
# Layer 6
x = Conv2DTranspose(self.channels, kernel_size=1, strides=1, padding='valid')(x)
z = Activation("tanh")(x)
return Model(inputs=inputImg, outputs=z, name=name)
示例9: model_3
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def model_3():
input_layer = Input(shape=(224,224,3))
from keras.layers import Conv2DTranspose as DeConv
resnet = ResNet50(include_top=False, weights="imagenet")
resnet.trainable = False
res_features = resnet(input_layer)
conv = DeConv(1024, padding="valid", activation="relu", kernel_size=3)(res_features)
conv = UpSampling2D((2,2))(conv)
conv = DeConv(512, padding="valid", activation="relu", kernel_size=5)(conv)
conv = UpSampling2D((2,2))(conv)
conv = DeConv(128, padding="valid", activation="relu", kernel_size=5)(conv)
conv = UpSampling2D((2,2))(conv)
conv = DeConv(32, padding="valid", activation="relu", kernel_size=5)(conv)
conv = UpSampling2D((2,2))(conv)
conv = DeConv(8, padding="valid", activation="relu", kernel_size=5)(conv)
conv = UpSampling2D((2,2))(conv)
conv = DeConv(4, padding="valid", activation="relu", kernel_size=5)(conv)
conv = DeConv(1, padding="valid", activation="sigmoid", kernel_size=5)(conv)
model = Model(inputs=input_layer, outputs=conv)
return model
示例10: get_unet_model
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def get_unet_model(input_channel_num=3, out_ch=3, start_ch=64, depth=4, inc_rate=2., activation='relu',
dropout=0.5, batchnorm=False, maxpool=True, upconv=True, residual=False):
def _conv_block(m, dim, acti, bn, res, do=0):
n = Conv2D(dim, 3, activation=acti, padding='same')(m)
n = BatchNormalization()(n) if bn else n
n = Dropout(do)(n) if do else n
n = Conv2D(dim, 3, activation=acti, padding='same')(n)
n = BatchNormalization()(n) if bn else n
return Concatenate()([m, n]) if res else n
def _level_block(m, dim, depth, inc, acti, do, bn, mp, up, res):
if depth > 0:
n = _conv_block(m, dim, acti, bn, res)
m = MaxPooling2D()(n) if mp else Conv2D(dim, 3, strides=2, padding='same')(n)
m = _level_block(m, int(inc * dim), depth - 1, inc, acti, do, bn, mp, up, res)
if up:
m = UpSampling2D()(m)
m = Conv2D(dim, 2, activation=acti, padding='same')(m)
else:
m = Conv2DTranspose(dim, 3, strides=2, activation=acti, padding='same')(m)
n = Concatenate()([n, m])
m = _conv_block(n, dim, acti, bn, res)
else:
m = _conv_block(m, dim, acti, bn, res, do)
return m
i = Input(shape=(None, None, input_channel_num))
o = _level_block(i, start_ch, depth, inc_rate, activation, dropout, batchnorm, maxpool, upconv, residual)
o = Conv2D(out_ch, 1)(o)
model = Model(inputs=i, outputs=o)
return model
示例11: build_REDNet
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def build_REDNet(nb_layers, input_size, nb_filters=32, k_size=3, dropout=0, strides=1, every=1):
# -> CONV/FC -> BatchNorm -> ReLu(or other activation) -> Dropout -> CONV/FC -> # https://arxiv.org/pdf/1502.03167.pdf
input_img = Input(shape=(input_size, input_size, 1))
x = input_img
if K.image_data_format() == 'channels_last':
bn_axis = 3
else:
bn_axis = 1
encoderLayers = [None] * nb_layers
for i in range(nb_layers):
x = Conv2D(nb_filters, kernel_size=k_size, strides=strides, padding='same')(x)
x = BatchNormalization(axis=bn_axis)(x)
x = Activation('relu')(x)
if dropout > 0:
x = Dropout(dropout)(x)
encoderLayers[i] = x
encoded = x
for i in range(nb_layers):
ind = nb_layers - i - 1
x = layers.add([x, encoderLayers[ind]])
x = Conv2DTranspose(nb_filters, kernel_size=k_size, strides=strides, padding='same')(x)
x = BatchNormalization(axis=bn_axis)(x)
x = Activation('relu')(x)
if dropout > 0:
x = Dropout(dropout)(x)
decoded = Conv2D(1, kernel_size=k_size, strides=1, padding='same', activation='sigmoid')(x)
autoencoder = Model(input_img, decoded)
return autoencoder, encoded, decoded
示例12: deconv
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def deconv(input, channels, kernel_size, scale):
return Conv2DTranspose(channels, kernel_size=kernel_size, strides=scale, padding='same')(input)
示例13: uk
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def uk(self, x, k):
# (up sampling followed by 1x1 convolution <=> fractional-strided 1/2)
if self.use_resize_convolution:
x = UpSampling2D(size=(2, 2))(x) # Nearest neighbor upsampling
x = ReflectionPadding2D((1, 1))(x)
x = Conv2D(filters=k, kernel_size=3, strides=1, padding='valid')(x)
else:
x = Conv2DTranspose(filters=k, kernel_size=3, strides=2, padding='same')(x) # this matches fractinoally stided with stride 1/2
x = self.normalization(axis=3, center=True, epsilon=1e-5)(x, training=True)
x = Activation('relu')(x)
return x
#===============================================================================
# Models
示例14: upsampling_block
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def upsampling_block(self, input_tensor, skip_tensor, filters, padding='valid',
batchnorm=False, dropout=0.0):
x = Conv2DTranspose(filters, kernel_size=(2,2), strides=(2,2))(input_tensor)
# compute amount of cropping needed for skip_tensor
_, x_height, x_width, _ = K.int_shape(x)
_, s_height, s_width, _ = K.int_shape(skip_tensor)
h_crop = s_height - x_height
w_crop = s_width - x_width
assert h_crop >= 0
assert w_crop >= 0
if h_crop == 0 and w_crop == 0:
y = skip_tensor
else:
cropping = ((h_crop//2, h_crop - h_crop//2), (w_crop//2, w_crop - w_crop//2))
y = Cropping2D(cropping=cropping)(skip_tensor)
x = Concatenate()([x, y])
# no dilation in upsampling convolutions
x = Conv2D(filters, kernel_size=(3,3), padding=padding)(x)
x = BatchNormalization()(x) if batchnorm else x
x = Activation('relu')(x)
x = Dropout(dropout)(x) if dropout > 0 else x
x = Conv2D(filters, kernel_size=(3,3), padding=padding)(x)
x = BatchNormalization()(x) if batchnorm else x
x = Activation('relu')(x)
x = Dropout(dropout)(x) if dropout > 0 else x
return x
示例15: TransitionUp
# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import Conv2DTranspose [as 別名]
def TransitionUp(self,filters,input_shape,output_shape):
model = self.model
model.add(Conv2DTranspose(filters, kernel_size=(3, 3), strides=(2, 2),
padding='same',
output_shape=output_shape,
input_shape=input_shape,
kernel_initializer="he_uniform",
data_format='channels_last'))