本文整理汇总了Python中tensorflow.python.keras._impl.keras.models.Model.get_layer方法的典型用法代码示例。如果您正苦于以下问题:Python Model.get_layer方法的具体用法?Python Model.get_layer怎么用?Python Model.get_layer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.keras._impl.keras.models.Model
的用法示例。
在下文中一共展示了Model.get_layer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VGG19
# 需要导入模块: from tensorflow.python.keras._impl.keras.models import Model [as 别名]
# 或者: from tensorflow.python.keras._impl.keras.models.Model import get_layer [as 别名]
#.........这里部分代码省略.........
128, (3, 3), activation='relu', padding='same', name='block2_conv2')(
x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='block2_pool')(x)
# Block 3
x = Conv2D(
256, (3, 3), activation='relu', padding='same', name='block3_conv1')(
x)
x = Conv2D(
256, (3, 3), activation='relu', padding='same', name='block3_conv2')(
x)
x = Conv2D(
256, (3, 3), activation='relu', padding='same', name='block3_conv3')(
x)
x = Conv2D(
256, (3, 3), activation='relu', padding='same', name='block3_conv4')(
x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='block3_pool')(x)
# Block 4
x = Conv2D(
512, (3, 3), activation='relu', padding='same', name='block4_conv1')(
x)
x = Conv2D(
512, (3, 3), activation='relu', padding='same', name='block4_conv2')(
x)
x = Conv2D(
512, (3, 3), activation='relu', padding='same', name='block4_conv3')(
x)
x = Conv2D(
512, (3, 3), activation='relu', padding='same', name='block4_conv4')(
x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='block4_pool')(x)
# Block 5
x = Conv2D(
512, (3, 3), activation='relu', padding='same', name='block5_conv1')(
x)
x = Conv2D(
512, (3, 3), activation='relu', padding='same', name='block5_conv2')(
x)
x = Conv2D(
512, (3, 3), activation='relu', padding='same', name='block5_conv3')(
x)
x = Conv2D(
512, (3, 3), activation='relu', padding='same', name='block5_conv4')(
x)
x = MaxPooling2D((2, 2), strides=(2, 2), name='block5_pool')(x)
if include_top:
# Classification block
x = Flatten(name='flatten')(x)
x = Dense(4096, activation='relu', name='fc1')(x)
x = Dense(4096, activation='relu', name='fc2')(x)
x = Dense(classes, activation='softmax', name='predictions')(x)
else:
if pooling == 'avg':
x = GlobalAveragePooling2D()(x)
elif pooling == 'max':
x = GlobalMaxPooling2D()(x)
# Ensure that the model takes into account
# any potential predecessors of `input_tensor`.
if input_tensor is not None:
inputs = get_source_inputs(input_tensor)
else:
inputs = img_input
# Create model.
model = Model(inputs, x, name='vgg19')
# load weights
if weights == 'imagenet':
if include_top:
weights_path = get_file(
'vgg19_weights_tf_dim_ordering_tf_kernels.h5',
WEIGHTS_PATH,
cache_subdir='models',
file_hash='cbe5617147190e668d6c5d5026f83318')
else:
weights_path = get_file(
'vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5',
WEIGHTS_PATH_NO_TOP,
cache_subdir='models',
file_hash='253f8cb515780f3b799900260a226db6')
model.load_weights(weights_path)
if K.backend() == 'theano':
layer_utils.convert_all_kernels_in_model(model)
if K.image_data_format() == 'channels_first':
if include_top:
maxpool = model.get_layer(name='block5_pool')
shape = maxpool.output_shape[1:]
dense = model.get_layer(name='fc1')
layer_utils.convert_dense_weights_data_format(dense, shape,
'channels_first')
elif weights is not None:
model.load_weights(weights)
return model