本文整理汇总了Python中keras.layers.convolutional.UpSampling2D方法的典型用法代码示例。如果您正苦于以下问题:Python convolutional.UpSampling2D方法的具体用法?Python convolutional.UpSampling2D怎么用?Python convolutional.UpSampling2D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.layers.convolutional
的用法示例。
在下文中一共展示了convolutional.UpSampling2D方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_generator
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def build_generator(self):
model = Sequential()
model.add(Dense(128 * 7 * 7, activation="relu", input_dim=self.latent_dim))
model.add(Reshape((7, 7, 128)))
model.add(BatchNormalization(momentum=0.8))
model.add(UpSampling2D())
model.add(Conv2D(128, kernel_size=3, padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(momentum=0.8))
model.add(UpSampling2D())
model.add(Conv2D(64, kernel_size=3, padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(momentum=0.8))
model.add(Conv2D(1, kernel_size=3, padding="same"))
model.add(Activation("tanh"))
model.summary()
noise = Input(shape=(self.latent_dim,))
img = model(noise)
return Model(noise, img)
示例2: build_generator
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def build_generator(self):
model = Sequential()
model.add(Dense(128 * 7 * 7, activation="relu", input_dim=self.latent_dim))
model.add(Reshape((7, 7, 128)))
model.add(UpSampling2D())
model.add(Conv2D(128, kernel_size=4, padding="same"))
model.add(BatchNormalization(momentum=0.8))
model.add(Activation("relu"))
model.add(UpSampling2D())
model.add(Conv2D(64, kernel_size=4, padding="same"))
model.add(BatchNormalization(momentum=0.8))
model.add(Activation("relu"))
model.add(Conv2D(self.channels, kernel_size=4, padding="same"))
model.add(Activation("tanh"))
model.summary()
noise = Input(shape=(self.latent_dim,))
img = model(noise)
return Model(noise, img)
示例3: dc_model
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def dc_model(self):
model = Sequential()
model.add(Dense(256*8*8,activation=LeakyReLU(0.2), input_dim=self.LATENT_SPACE_SIZE))
model.add(BatchNormalization())
model.add(Reshape((8, 8, 256)))
model.add(UpSampling2D())
model.add(Convolution2D(128, 5, 5, border_mode='same',activation=LeakyReLU(0.2)))
model.add(BatchNormalization())
model.add(UpSampling2D())
model.add(Convolution2D(64, 5, 5, border_mode='same',activation=LeakyReLU(0.2)))
model.add(BatchNormalization())
model.add(UpSampling2D())
model.add(Convolution2D(self.C, 5, 5, border_mode='same', activation='tanh'))
return model
示例4: __transition_up_block
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def __transition_up_block(ip, nb_filters, type='deconv', weight_decay=1E-4):
''' SubpixelConvolutional Upscaling (factor = 2)
Args:
ip: keras tensor
nb_filters: number of layers
type: can be 'upsampling', 'subpixel', 'deconv'. Determines type of upsampling performed
weight_decay: weight decay factor
Returns: keras tensor, after applying upsampling operation.
'''
if type == 'upsampling':
x = UpSampling2D()(ip)
elif type == 'subpixel':
x = Conv2D(nb_filters, (3, 3), activation='relu', padding='same', kernel_regularizer=l2(weight_decay),
use_bias=False, kernel_initializer='he_normal')(ip)
x = SubPixelUpscaling(scale_factor=2)(x)
x = Conv2D(nb_filters, (3, 3), activation='relu', padding='same', kernel_regularizer=l2(weight_decay),
use_bias=False, kernel_initializer='he_normal')(x)
else:
x = Conv2DTranspose(nb_filters, (3, 3), activation='relu', padding='same', strides=(2, 2),
kernel_initializer='he_normal', kernel_regularizer=l2(weight_decay))(ip)
return x
示例5: generator_model
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def generator_model():
model = Sequential()
model.add(Dense(input_dim=100, output_dim=1024))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Dense(7 * 7 * 128))
model.add(BatchNormalization())
model.add(Activation('relu'))
# tfモードの場合はチャネルは後!
model.add(Reshape((7, 7, 128), input_shape=(7 * 7 * 128,)))
model.add(UpSampling2D((2, 2))) # 画像のサイズが2倍になる 14x14
model.add(Convolution2D(64, 5, 5, border_mode='same'))
model.add(Activation('tanh'))
model.add(UpSampling2D(size=(2, 2))) # 28x28
model.add(Convolution2D(1, 5, 5, border_mode='same')) # 28x28x1が出力
model.add(Activation('tanh'))
return model
示例6: create_res_texture_net
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def create_res_texture_net(input_rows, input_cols, num_res_filters=128,
res_out_activation='linear', activation='relu', num_res_blocks=5):
net = Graph()
net.add_input('x', input_shape=(3, input_rows, input_cols))
add_conv_block(net, 'in0', 'x', num_res_filters // 4, 9, activation=activation)
add_conv_block(net, 'in1', 'in0', num_res_filters // 2, 3, subsample=(2, 2), activation=activation)
add_conv_block(net, 'in2', 'in1', num_res_filters, 3, subsample=(2, 2), activation=activation)
last_block_name = 'in2'
for res_i in range(num_res_blocks):
block_name = 'res_{}'.format(res_i)
add_conv_block(net, block_name + '_in0', last_block_name, num_res_filters, 3, activation=activation)
add_conv_block(net, block_name + '_in1', block_name + '_in0', num_res_filters, 3, activation='linear')
net.add_node(Activation(res_out_activation), block_name, merge_mode='sum', inputs=[block_name + '_in1', last_block_name])
last_block_name = block_name
# theano doesn't seem to support fractionally-strided convolutions at the moment
net.add_node(UpSampling2D(), 'out_up0', last_block_name)
add_conv_block(net, 'out_0', 'out_up0', num_res_filters // 2, 3, activation=activation)
net.add_node(UpSampling2D(), 'out_up1', 'out_0')
add_conv_block(net, 'out_1', 'out_up1', num_res_filters // 4, 3, activation=activation)
add_conv_block(net, 'out_2', 'out_1', 3, 9, activation='linear')
net.add_node(Activation('linear'), 'texture_rgb', 'out_2', create_output=True)
return net
示例7: create_sequential_texture_net
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def create_sequential_texture_net(input_rows, input_cols, num_res_filters=128,
res_out_activation='linear', activation='relu', num_inner_blocks=5):
net = Sequential()
add_seq_conv_block(net, num_res_filters // 4, 9, input_shape=(3, input_rows, input_cols), activation=activation)
add_seq_conv_block(net, num_res_filters // 2, 3, subsample=(2, 2), activation=activation)
add_seq_conv_block(net, num_res_filters, 3, subsample=(2, 2), activation=activation)
for i in range(num_inner_blocks):
add_seq_conv_block(net, num_res_filters, 3, activation=activation)
add_seq_conv_block(net, num_res_filters, 3, activation=activation)
# theano doesn't seem to support fractionally-strided convolutions at the moment
net.add(UpSampling2D())
add_seq_conv_block(net, num_res_filters // 2, 3, activation=activation)
net.add(UpSampling2D())
add_seq_conv_block(net, num_res_filters // 4, 3, activation=activation)
add_seq_conv_block(net, 3, 9, activation='linear')
return net
示例8: build_generator
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def build_generator():
gen_model = Sequential()
gen_model.add(Dense(input_dim=100, output_dim=2048))
gen_model.add(ReLU())
gen_model.add(Dense(256 * 8 * 8))
gen_model.add(BatchNormalization())
gen_model.add(ReLU())
gen_model.add(Reshape((8, 8, 256), input_shape=(256 * 8 * 8,)))
gen_model.add(UpSampling2D(size=(2, 2)))
gen_model.add(Conv2D(128, (5, 5), padding='same'))
gen_model.add(ReLU())
gen_model.add(UpSampling2D(size=(2, 2)))
gen_model.add(Conv2D(64, (5, 5), padding='same'))
gen_model.add(ReLU())
gen_model.add(UpSampling2D(size=(2, 2)))
gen_model.add(Conv2D(3, (5, 5), padding='same'))
gen_model.add(Activation('tanh'))
return gen_model
示例9: model_generator
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def model_generator():
model = Sequential()
nch = 256
reg = lambda: l1l2(l1=1e-7, l2=1e-7)
h = 5
model.add(Dense(nch * 4 * 4, input_dim=100, W_regularizer=reg()))
model.add(BatchNormalization(mode=0))
model.add(Reshape(dim_ordering_shape((nch, 4, 4))))
model.add(Convolution2D(int(nch / 2), h, h, border_mode='same', W_regularizer=reg()))
model.add(BatchNormalization(mode=0, axis=1))
model.add(LeakyReLU(0.2))
model.add(UpSampling2D(size=(2, 2)))
model.add(Convolution2D(int(nch / 2), h, h, border_mode='same', W_regularizer=reg()))
model.add(BatchNormalization(mode=0, axis=1))
model.add(LeakyReLU(0.2))
model.add(UpSampling2D(size=(2, 2)))
model.add(Convolution2D(int(nch / 4), h, h, border_mode='same', W_regularizer=reg()))
model.add(BatchNormalization(mode=0, axis=1))
model.add(LeakyReLU(0.2))
model.add(UpSampling2D(size=(2, 2)))
model.add(Convolution2D(3, h, h, border_mode='same', W_regularizer=reg()))
model.add(Activation('sigmoid'))
return model
示例10: model_generator
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def model_generator(latent_dim, units=512, dropout=0.5, reg=lambda: l1l2(l1=1e-7, l2=1e-7)):
model = Sequential(name="decoder")
h = 5
model.add(Dense(units * 4 * 4, input_dim=latent_dim, W_regularizer=reg()))
model.add(Reshape(dim_ordering_shape((units, 4, 4))))
# model.add(SpatialDropout2D(dropout))
model.add(LeakyReLU(0.2))
model.add(Convolution2D(units / 2, h, h, border_mode='same', W_regularizer=reg()))
# model.add(SpatialDropout2D(dropout))
model.add(LeakyReLU(0.2))
model.add(UpSampling2D(size=(2, 2)))
model.add(Convolution2D(units / 2, h, h, border_mode='same', W_regularizer=reg()))
# model.add(SpatialDropout2D(dropout))
model.add(LeakyReLU(0.2))
model.add(UpSampling2D(size=(2, 2)))
model.add(Convolution2D(units / 4, h, h, border_mode='same', W_regularizer=reg()))
# model.add(SpatialDropout2D(dropout))
model.add(LeakyReLU(0.2))
model.add(UpSampling2D(size=(2, 2)))
model.add(Convolution2D(3, h, h, border_mode='same', W_regularizer=reg()))
model.add(Activation('sigmoid'))
return model
示例11: model_generator
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def model_generator():
nch = 256
g_input = Input(shape=[100])
H = Dense(nch * 14 * 14)(g_input)
H = BatchNormalization(mode=2)(H)
H = Activation('relu')(H)
H = dim_ordering_reshape(nch, 14)(H)
H = UpSampling2D(size=(2, 2))(H)
H = Convolution2D(int(nch / 2), 3, 3, border_mode='same')(H)
H = BatchNormalization(mode=2, axis=1)(H)
H = Activation('relu')(H)
H = Convolution2D(int(nch / 4), 3, 3, border_mode='same')(H)
H = BatchNormalization(mode=2, axis=1)(H)
H = Activation('relu')(H)
H = Convolution2D(1, 1, 1, border_mode='same')(H)
g_V = Activation('sigmoid')(H)
return Model(g_input, g_V)
示例12: build_generator
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def build_generator(noise_shape=(100,)):
input = Input(noise_shape)
x = Dense(128 * 7 * 7, activation="relu")(input)
x = Reshape((7, 7, 128))(x)
x = BatchNormalization(momentum=0.8)(x)
x = UpSampling2D()(x)
x = Conv2D(128, kernel_size=3, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(momentum=0.8)(x)
x = UpSampling2D()(x)
x = Conv2D(64, kernel_size=3, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(momentum=0.8)(x)
x = Conv2D(1, kernel_size=3, padding="same")(x)
out = Activation("tanh")(x)
model = Model(input, out)
print("-- Generator -- ")
model.summary()
return model
示例13: build_generator
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def build_generator(noise_shape=(100,)):
input = Input(noise_shape)
x = Dense(128 * 8 * 8, activation="relu")(input)
x = Reshape((8, 8, 128))(x)
x = BatchNormalization(momentum=0.8)(x)
x = UpSampling2D()(x)
x = Conv2D(128, kernel_size=3, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(momentum=0.8)(x)
x = UpSampling2D()(x)
x = Conv2D(64, kernel_size=3, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(momentum=0.8)(x)
x = Conv2D(3, kernel_size=3, padding="same")(x)
out = Activation("tanh")(x)
model = Model(input, out)
print("-- Generator -- ")
model.summary()
return model
示例14: build_generator
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def build_generator(self):
noise_shape = (self.z_dim,)
model = Sequential()
model.add(Dense(128 * 32 * 32, activation="relu", input_shape=noise_shape))
model.add(Reshape((32, 32, 128)))
model.add(BatchNormalization(momentum=0.8))
model.add(UpSampling2D())
model.add(Conv2D(128, kernel_size=3, padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(momentum=0.8))
model.add(UpSampling2D())
model.add(Conv2D(64, kernel_size=3, padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(momentum=0.8))
model.add(Conv2D(3, kernel_size=3, padding="same"))
model.add(Activation("tanh"))
model.summary()
noise = Input(shape=noise_shape)
img = model(noise)
return Model(noise, img)
示例15: build_generator
# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import UpSampling2D [as 别名]
def build_generator(self):
model = Sequential()
model.add(Dense(128 * 7 * 7, activation="relu", input_dim=self.latent_dim))
model.add(Reshape((7, 7, 128)))
model.add(UpSampling2D())
model.add(Conv2D(128, kernel_size=3, padding="same"))
model.add(BatchNormalization(momentum=0.8))
model.add(Activation("relu"))
model.add(UpSampling2D())
model.add(Conv2D(64, kernel_size=3, padding="same"))
model.add(BatchNormalization(momentum=0.8))
model.add(Activation("relu"))
model.add(Conv2D(self.channels, kernel_size=3, padding="same"))
model.add(Activation("tanh"))
model.summary()
noise = Input(shape=(self.latent_dim,))
img = model(noise)
return Model(noise, img)