Hi!
I am struggeling a bit with NX and TorchX and got a bit stuck!
I have created a model and state and I am trying to run this function:
The function load!
reads a model and state that is saved to disk using term_to_binary
and when inspecting the model and state they look OK.
I am feeding the function path to a PNG file.
def predict(path) do
mat = Evision.imread(path, flags: Evision.Constant.cv_IMREAD_GRAYSCALE())
mat = Evision.resize(mat, {28, 28})
data =
Evision.Mat.to_nx(mat)
|> Nx.reshape({1, 28, 28})
|> List.wrap()
|> Nx.stack()
|> Nx.backend_transfer(Torchx.Backend)
{model, state} = load!()
model
|> Axon.predict(state, data, debug: true)
|> Nx.argmax()
|> Nx.to_number()
end
I am currently getting this error message as the result from the predict
function:
** (RuntimeError) Torchx: Unable to get tensor param in NIF
(torchx 0.9.2) lib/torchx.ex:447: Torchx.unwrap!/1
(torchx 0.9.2) lib/torchx.ex:450: Torchx.unwrap_tensor!/2
(torchx 0.9.2) lib/torchx/backend.ex:992: Torchx.Backend.dot/7
(nx 0.9.2) lib/nx/defn/evaluator.ex:441: Nx.Defn.Evaluator.eval_apply/4
(nx 0.9.2) lib/nx/defn/evaluator.ex:256: Nx.Defn.Evaluator.eval/3
(elixir 1.17.1) lib/enum.ex:1829: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(nx 0.9.2) lib/nx/defn/evaluator.ex:419: Nx.Defn.Evaluator.eval_apply/4
#cell:kkr4tfn454cgrk4x:3: (file)
I have tried to debug this and search the internet for similar errors with no luck so I hoped to find some help here!