python cnn模型_如何在Python中使用预训练的CNN模型

基本上,如果您指定任何不是imagenet的weights,它只会使用keras model.load_weights来加载它,我猜{}不是keras可以直接在这里加载的有效文件。在if weights == 'imagenet':

if include_top:

weights_path = keras_utils.get_file(

'vgg16_weights_tf_dim_ordering_tf_kernels.h5',

WEIGHTS_PATH,

cache_subdir='models',

file_hash='64373286793e3c8b2b4e3219cbf3544b')

else:

weights_path = keras_utils.get_file(

'vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5',

WEIGHTS_PATH_NO_TOP,

cache_subdir='models',

file_hash='6d6bbae143d832006294945121d1f1fc')

model.load_weights(weights_path)

if backend.backend() == 'theano':

keras_utils.convert_all_kernels_in_model(model)

elif weights is not None:

model.load_weights(weights)

默认情况下,keras将使用imagenet作为默认权重,输出类号为1000。但是,如果您没有此模型的其他有效权重,您仍然可以通过一种可能的方式利用imagenet权重:可以将include_top设置为False,并直接使用VGG16 Conv输出(没有最后的3个FC层)。在

^{pr2}$

include_top: whether to include the 3 fully-connected

layers at the top of the network.

weights: one of `None` (random initialization),

'imagenet' (pre-training on ImageNet),

or the path to the weights file to be loaded.

classes: optional number of classes to classify images

into, only to be specified if `include_top` is True, and

if no `weights` argument is specified.

你可能感兴趣的:(python,cnn模型)