Inference Discrepancy between PyTorch and DJL implementation via Kotlin
I have a PyTorch model trained on the 17flowers dataset, and converted via PyTorch's tracing to a JIT model. I have tested the inference output for the PyTorch model and the JIT converted model, and the results are equivalent there. This leads me to believe there is an issue with my implementation of the DJL framework.
There is an issue when I attempt to utilized DJL for inference utilizing the converted JIT model, which is necessary for DJL. I am not getting 100% match, which I expected.
The Kotlin implementation for djl.ai is straightforward and essentially follows the instructions here.
I have a sanitized version of the Kotlin code below:
@Throws(IOException::class, ModelException::class, TranslateException::class)
internal fun main(args: Array&lt;String&gt;) {
    val artifactId = &quot;ai.djl.localmodelzoo:torchscript_17flowers&quot;
    val pipeline = Pipeline()
    pipeline.add(CenterCrop(224, 224))
        .add(Resize(224, 224))
        .add(ToTensor())
        .add(Normalize(floatArrayOf(0.485f, 0.456f, 0.406f), floatArrayOf(0.229f, 0.224f, 0.225f)))
    val translator = ImageClassificationTranslator.builder()
        .setPipeline(pipeline)
        .optSynsetArtifactName(&quot;synset.txt&quot;)
        .optApplySoftmax(true)
        .build();

    System.setProperty(&quot;ai.djl.repository.zoo.location&quot;,&quot;build/pytorch_models/torchscript_17flowers&quot;)

    val criteria = Criteria.builder()
        .setTypes(Image::class.java, Classifications::class.java) // defines input and output data type
        .optTranslator(translator)
        .optArtifactId(artifactId) // defines which model to load
        .optProgress(ProgressBar())
        .build()

    val model = ModelZoo.loadModel(criteria)

    // single image test
    var img = ImageFactory.getInstance().fromUrl(&quot;https://image.jpg&quot;);
    img.getWrappedImage()

    val predictor: Predictor&lt;Image, Classifications&gt; = model.newPredictor()
    val classifications: Classifications = predictor.predict(img)
    val best = classifications.best&lt;Classifications.Classification&gt;()
}

My issue isn't getting things to run so much as it is getting the inference results to match. It is my understanding that they should match, and that Kotlin should work fine as DJL is meant to work for Java. I'm curious if there are any thoughts surrounding this encountered issue.

The discrepancy most likely comes from image pre-processing:
pipeline.add(CenterCrop(224, 224))
        .add(Resize(224, 224))
        .add(ToTensor())
        .add(Normalize(floatArrayOf(0.485f, 0.456f, 0.406f), floatArrayOf(0.229f, 0.224f, 0.225f)))

Many of PyTorch CV models, they don't do a center crop.
In order to get the same result as python, you must to make sure you process them the same way as python code does.
DJL image operation align with openCV operators, if you use PILLOW in python, you might see some difference in the result.
