【发布时间】:2021-07-03 15:57:00
【问题描述】:
我正在尝试使用 inceptionv1 进行迁移学习,但分类器无法很好地预测一张图像,这是怎么回事?
from skimage.transform import resize
m = tf.keras.Sequential([hub.KerasLayer("https://tfhub.dev/google/imagenet/inception_v1/classification/4")]) # load the tensorflow hub model
m.build([None, 224, 224, 3])
rimg = resize(img, output_shape=(1,224,224,3),anti_aliasing=True) # resize and reshape the image to [1,224,224,3]
rimg = (rimg-np.min(rimg))/(np.max(rimg)-np.min(rimg)).astype(np.float32) # normalize the image to a [0,1] range
logits = m(rimg) # feed the image into the model to obtain the logits
probs = np.exp(logits)/(np.sum(np.exp(logits))) # convert logits to probabilities
【问题讨论】:
标签: tensorflow deep-learning conv-neural-network tensorflow-hub