中间特征层可视化
导入ImageNet VGG16网络
导入基础包
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
导入ImageNet VGG16网络
VGG16_model = tf.keras.applications.VGG16(include_top=True)
VGG16_model.summary()
加载任一图片
随便网上找一张图,比如使用率最高的猫星人
读取本地图片
def prepocess(x):
x = tf.io.read_file(x)
x = tf.image.decode_jpeg(x, channels=3)
print(x.shape)
x = tf.image.resize(x, [224,224])
x = tf.cast(x, dtype=tf.float32)/255.
return x
img_path='Cat.jpg'
img=prepocess(img_path