Problems with using models to generate images in Android

#1
by huangjiangzheng - opened

I tried to use the aotgan model to generate an image in the Android project, but the output is strange and I don't know why.
I input the picture:

test_input_image.png

test_input_mask.png

The model output picture:

Snipaste_2024-07-26_10-27-01.jpg

my code:

    String tfliteName="aotgan.tflite";
    String imgName="test_input_image.png";
    String maskName="test_input_mask.png";
    
    Pair<MappedByteBuffer, String> modelAndHash = TFLiteHelpers.loadModelFile(context.getAssets(), tfliteName);
    Pair<Interpreter, Map<TFLiteHelpers.DelegateType, Delegate>> iResult = TFLiteHelpers.CreateInterpreterAndDelegatesFromOptions(
            modelAndHash.first,
            AIHubDefaults.delegatePriorityOrderForDelegates(new HashSet<>() /* No delegates; cpu only */),
            AIHubDefaults.numCPUThreads,
            context.getApplicationInfo().nativeLibraryDir,
            context.getCacheDir().getAbsolutePath(),
            modelAndHash.second
    );
    Interpreter myTfLiteInterpreter = iResult.first;

    // Validate TF Lite model fits requirements for this app
    float[][][][] floatinputarray1=new float[1][512][512][3];
    float[][][][] floatinputarray2=new float[1][512][512][1];
    
    AssetManager assets = context.getAssets();

    Bitmap image=Bitmap.createScaledBitmap(BitmapFactory.decodeStream(assets.open(imgName)),512,512,true);
    Bitmap markImage=Bitmap.createScaledBitmap(BitmapFactory.decodeStream(assets.open(maskName)),512,512,true);

    floatinputarray1[0]=getRGB(image);
    floatinputarray2[0]=getGreyImg(markImage);

    float[][][][] floatoutputarray=new float[1][512][512][3];
    Map<Integer,Object> outputMap=new HashMap<>();
    outputMap.put(0,floatoutputarray);
    Object[] input={floatinputarray1,floatinputarray2};
    myTfLiteInterpreter.runForMultipleInputsOutputs(input,outputMap);

    Bitmap bitmap = convertFloatArrayToBitmap(((float[][][][]) outputMap.get(0))[0], 512, 512);

    return bitmap;
Qualcomm org

That's strange. Can you quickly check if you get good results with a different inpainting model like LaMaDilated to unblock yourself. I can take a look in the meantime to see what the issue is with AOT GAN.

Sign up or log in to comment