What is the output of your model? Maybe the type error is caused by output. Try
auto output = module.forward(img);
IValue[] outputTuple = output.toTuple(); 
Tensor outputTensor = outputTuple[0].toTensor();
...

Break the forward statement into two lines for easier debugging.