admin管理员组文章数量:1576346
"""
调用VGG19模型
输入一张彩色图像
输出指定层的特征
VGG19模型的输入图像是四维的,但是加载进去的图像是三维的,所以要提前reshape
指定层的输出是四维的,所以要reshape到三维
如果要可视化,使用spyder只能显示而是图像
"""
from __future__ import print_function
from keras.preprocessing.image import load_img, save_img, img_to_array
import numpy as np
from scipy.optimize import fmin_l_bfgs_b
import time
import argparse
import matplotlib.image as mpimg # mpimg 用于读取图片
from keras.applications import vgg19
from keras import backend as K
import matplotlib.pyplot as plt
from keras.preprocessing import image
import os
model = vgg19.VGG19(weights='imagenet', include_top=False,)
from keras.models import Model
#print(model.layers)
img_path ='C:\\Users\\Administrator\\Pictures\\Saved Pictures\\kobe.jpg'
img=image.load_img(img_path)
img=np.array(img)
a,b,c=img.shape
img=img.reshape(1,a,b,c)
#VGG19模型的实际深度是26,本文使用的模型去掉了三个全连接层
layer_model=Model(inputs=model.input,outputs=model.layers[20].output)
out=layer_model.predict(img)
print(out.shape)
w,x,y,z=out.shape
out=out.reshape(x,y,z)
plt.imshow(out[:,:,40])
指定某一层的的输出特征图
版权声明:本文标题:VGG19模型,输入图像,输出指定层特征 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727803808a1130847.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论