【发布时间】:2020-01-17 14:39:35
【问题描述】:
所以我正在尝试打印预训练 VGG16 模型的 model.output(张量)的值,但不幸的是,下面列出的所有方法都不适用于我的情况,这是我从之前的回答中发现的类似的问题。
1)首先基于this帖子我尝试使用
打印(K.eval(model.output()))
但它引发了错误
TypeError: 'Tensor' 对象不可调用
2) 然后在浏览this 帖子后,我尝试使用
K.print_tensor(model.output, message='model.output = ')
approach 但这次没有输出输出。
这是我的代码:
from keras.applications.vgg16 import VGG16
from keras.applications.vgg16 import preprocess_input
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.models import Model
import keras.backend as K
from matplotlib import pyplot
from numpy import expand_dims
import numpy as np
# load the model
model = VGG16()
img = load_img('../input/treebird/bird.jpg', target_size=(224, 224))
img = img_to_array(img)
img = expand_dims(img, axis=0)
img = preprocess_input(img)
prediction = model.predict(img)
print(model.output) #Tensor("predictions_19/Softmax:0", shape=(?, 1000), dtype=float32)
print(K.eval(model.output())) # throws TypeError: 'Tensor' object is not callable
K.print_tensor(model.output, message='model.output = ')
我在上述方法的实现中是否缺少某些地方,或者在这种情况下我应该使用其他方法来打印张量?
【问题讨论】:
标签: python-3.x tensorflow keras deep-learning conv-neural-network