使用vgg16模型,该如何导入模型,并测试?并且如何能够得到网络的每一层的输入输出特征值?
Created by: taoja12
对于得到每一层的输入输出特征值,类似于tensorflow的代码。 `import cv2 import os import tensorflow as tf import numpy as np from caffe_classes import class_names np.set_printoptions(threshold=np.inf)
interpreter =tf.lite.Interpreter(model_path='alexnet.tflite') interpreter.allocate_tensors() input_details = interpreter.get_input_details() output_details = interpreter.get_output_details()
image = './images/llama.jpeg' image = cv2.imread(image) image = cv2.resize(image, (227, 227))
image = image.reshape((1, 227, 227, 3)) input_data = image.astype(np.float32) index = input_details[0]['index'] interpreter.set_tensor(index, input_data) interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
tensor_detail = interpreter._get_tensor_details(20) output = interpreter.get_tensor(tensor_detail['index']) f = open(r'./each_layer_output/conv1.txt', 'w') print(output, file=f) f.close() ` 这是我的网络模型的链接 链接: https://pan.baidu.com/s/1LMsIETIcqlh6pedRFQG74Q 提取码: 9mf8