smistad / FAST

A framework for high-performance medical image processing, neural network inference and visualization
https://fast.eriksmistad.no
BSD 2-Clause "Simplified" License
433 stars 101 forks source link

Option to set channel ordering of NeuralNetwork in pyFAST #174

Closed ingridtv closed 1 year ago

ingridtv commented 1 year ago

I am trying to set up a window for running inference and visualization of classification predictions with a pyTorch model in pyFAST. When trying to run the pyFAST window, I get an error message saying "FAST exception caught in Qt event handler Invalid shape size".

After some discussion with @andreped, we believe the issue might be that pyTorch uses channel first ordering, but pyFAST assumes channel last ordering. We don't see a way to set channel ordering for a NeuralNetwork in pyFAST.

Is it possible to add support for setting this with fast.NeuralNetwork.create()?

smistad commented 1 year ago

Yes, I can add support for setting this manually. But are you sure that that this is the cause of the error? FAST tries to detect the channel dimension by seeing if the first og the last dimension is <= 4. You can get more debug info if you write fast.Reporter.setGlobalReportMethod(fast.Reporter.COUT) before loading the neural network.

ingridtv commented 1 year ago

I see from the console output that the model seemingly takes channel last ordering

INFO [12856] ONNXRuntime Session created
INFO [12856] Found input node: 0 : 16 5 384 384 3
INFO [12856] Guessed image ordering to be channel last as shape was 16 5 384 384 3 
INFO [12856] Found output node: 375 : 16 5 27
INFO [12856] Found output node: 382 : 16 5 2

so we think that the model (or model conversion to .onnx) might be the issue here, so we'll check this and follow up if we have more questions or would still like the functionality.

ingridtv commented 1 year ago

It turned out that the conversion to .onnx was the issue here. FAST detected the channel ordering as expected! I'll close the issue since it has been resolved on our end👍