我有一个使用特定数据集训练的模型。我最初并没有将设置分解为训练和测试集(我应该有)。说到这里,我想做一些特别的测试,看看当我给模型提供特定的图像时,模型的性能如何。我尝试执行类似Images.load("/Users/logankilpatrick/Desktop/train/dog.10697.jpg")的操作来加载图像,然后将其直接传递给模型,但我得到了inout大小不匹配错误。加载图像的正确方式是什么?
发布于 2021-11-23 14:20:39
要使用镜像进行推理,您需要执行几个步骤,如下图所示:
x = Images.load("/Users/logankilpatrick/Desktop/train/dog.10697.jpg")
x = Images.imresize(x, (224,224)...) # 224x224 depends on the model size
x = permutedims(channelview(x), (3,2,1))
# Channelview returns a view of A, splitting out (if necessary) the color channels of A into a new first dimension.
x = reshape(x, size(x)..., 1) # Add an extra dim to show we only have 1 image
float32.(x) # Convert to float32 instead of float64
model(x)请注意,根据您使用的模型和其他因素,其中一些可能会发生变化,但这是您需要做的一般想法。写一个简单的函数来帮你做这件事是可行的。
https://stackoverflow.com/questions/70082540
复制相似问题