https://kotlinlang.org logo
#ai
Title
# ai
a

Alexandre Brown

08/23/2021, 7:18 PM
Hello, what would you guys recommend to use for image pre-processing on Kotlin ? (Equivalent to what PIL offers) I'm looking for something simple that can do what PIL did for me on Python when it came to loading raw images bytes into (m,C,H,W) matrix. If possible I'd prefer a library that is lightweight, I just need to do preprocessing of raw bytes into rgb matrix and maybe basic normalization if possible. But if there is no library just for that then I'll take whatever works. Should I try D4J or OpenCV Java or is there a better Kotlin alternative? Thanks
z

zaleslaw

08/25/2021, 7:08 AM
Could you share please the list of required preprocessing ops or the whole Python code?
At this moment opencv is the best option, but it's opencv
a

Alexandre Brown

08/25/2021, 11:11 AM
@zaleslaw Sure, nothing crazy, Normalization (mean,std),ByteArray to RGB N-array, reshape. PS: I can't wait for Kotlin to overtake the data science world.
K 1
I can send you code snippets when I get home
z

zaleslaw

08/25/2021, 11:14 AM
Yes, it will be great
a

Alexandre Brown

08/25/2021, 1:12 PM
@zaleslaw Something like this but in Kotlin (one screenshot uses PyTorch, the other one does almost the same thing but in Numpy instead) PS: The normalize values are just fillers for the purpose of the discussion, we might not always want grayscale.
z

zaleslaw

08/25/2021, 1:23 PM
What torch transforms do you usually use? I see to tensor/normalize. Do you use any resize method or methods for noise removing?
Maybe something else?
What np operations do you use? (I see reshape) what about transpose?
a

Alexandre Brown

08/25/2021, 2:02 PM
Yes resizing transforms, horizontal flip are other transforms that we could use
👍 1
We are trying to see if we can do the preprocessing/postprocessing in kotlin and keep the model in python or if we must do the pre-processing in python as well. I will explore OpenCV Java, if you have a better alternative let me know.
z

zaleslaw

08/25/2021, 2:52 PM
It's actual question for me too, of course I share if found something better or image preprocessing dsl in KotlinDL will cover more basic use cases
👍 1
a

Alexandre Brown

08/27/2021, 11:28 AM
@zaleslaw Does KotlinDL have those preprocessing mentioned above ? Load image into tensor, reshape tensor, resize, normalize ? If not what do you use ?
It will be extended in the 0.3, we are planned to add a few transformation from torchvision to support preprocessing (and postprocessing) for ONNX models for Image Recognition, Object Detection, Face Alignment and so on
👍 1
22 Views