【问题标题】:How to load an image for inference in Flux.jl?如何在 Flux.jl 中加载图像进行推理?
【发布时间】:2021-11-23 14:20:38
【问题描述】:

我有一个使用特定数据集训练的模型。我最初并没有将设置分解为训练集和测试集(我应该拥有)。话虽如此,我想做一些临时测试,看看当我给模型提供特定图像时它的表现如何。我尝试执行类似Images.load("/Users/logankilpatrick/Desktop/train/dog.10697.jpg") 的操作来加载图像,然后将其直接传递给模型,但我得到了 inout 大小不匹配错误。加载图片的正确方法是什么?

【问题讨论】:

标签: julia flux.jl


【解决方案1】:

要使用图像进行推理,您需要执行几个步骤,如下所示:

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)

请注意,其中一些可能会根据您使用的模型和其他因素而改变,但这是您需要做的一般想法。编写一个为您执行此操作的简单函数可能会起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 2018-10-18
    • 2015-09-04
    • 1970-01-01
    • 2015-08-08
    • 2019-06-28
    相关资源
    最近更新 更多