卷积层由多个卷积核组成,可以将每个卷积核视为一种特征提取方式。当一个卷积核处理图像数据后,卷积核会提取图中的特征,形成新的特征图。
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.applications.vgg16 import VGG16
model = VGG16(weights=‘imagenet’)
model.summary()
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.vgg16 import preprocess_input, decode_predictions
from numpy as np
img_path = ‘0a0c3edd8a0bb0f5b4d6466c9a1af3c6-0.jpg’
#缩放
img = image.load_img(img_path,target_size=(224,224))
#显示图片
plt.imshow(img)
plt.show()
x = image.img_to_array(img)
#维度扩展
x = np.expand_dims(x,axis&