Style transfer on android: lateinit property sessionManager not initialized

To report an issue or request support with the Android SDK, please include the following:

Hello! I am trying to implement a style transfer with the fritz api and I am continually running into an error message which says:

java.lang.RuntimeException: kotlin.UninitializedPropertyAccessException: lateinit property sessionManager has not been initialized

I have only tried to implement a very simple style transfer following the tutorial from this link: https://docs.fritz.ai/develop/vision/style-transfer/android.html

No where in the tutorial or in my code does it say to initialize the sessionManager, so I am not sure how to fix this issue.

Here is the code I am using to try and apply this functionality:

Fritz.configure(this, “MY_KEY”)
var paintingModels: PaintingStyleModels = FritzVisionModels.getPaintingStyleModels()
var styleOnDeviceModel = paintingModels.starryNight
predictor = FritzVision.StyleTransfer.getPredictor(styleOnDeviceModel)
var visionImage = FritzVisionImage.fromBitmap(uploadBitmap)
var styleReadable: FritzVisionStyleResult = predictor.predict(visionImage)
var newImage = styleReadable.toBitmap()

The full error message is here:

2020-04-29 18:19:23.322 12815-12815/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ait.comicbook, PID: 12815
java.lang.RuntimeException: kotlin.UninitializedPropertyAccessException: lateinit property sessionManager has not been initialized
at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:112)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property sessionManager has not been initialized
at ai.fritz.core.Fritz.getSessionManager(Fritz.kt:40)
at ai.fritz.core.FritzCustomModelService.checkModelUpdateJob(FritzCustomModelService.kt:58)
at ai.fritz.core.FritzCustomModelService.onStartJob(FritzCustomModelService.kt:48)
at android.app.job.JobService$1.onStartJob(JobService.java:62)
at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:108)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

The implementations I have in my build gradle are as follows:

implementation ‘ai.fritz:core:+’
implementation ‘ai.fritz:vision:+’
implementation ‘ai.fritz:vision-style-painting-models:+’

My min sdk version is 21 and target sdk version is 29, and this appe is running on a Pixel 3 API 29 Emulator. Please let me know if you have any suggestions for how I can fix this issue! Thanks!

Hi @benhinthorne - Can you pin the android version to 6.0.0-beta.6 and the style models version to 3.0.0 and let me know if it happens on the latest version?

Hi @eric, thanks for getting back to me. Unfortunately, even after those changes I have the same issue. Here are the versions I now have in my build gradle:

implementation ‘ai.fritz:core:6.0.0-beta.6’
implementation ‘ai.fritz:vision:6.0.0-beta.6’
implementation ‘ai.fritz:vision-style-painting-models:3.0.0’

The error message remains the same. Thanks again for your help, please let me know if you have any other suggestions!

Thanks for that info. Can you provide more context around where you’re calling Fritz.configure? One thing to check is to make sure you’re calling Fritz.configure when the Application (or main Activity) is created (onCreate lifecycle method) and before any other SDK method.

Hi Eric,

Thanks again for helping. I was not calling Fritz.configure in my MainActivity, however after moving that call to the main activity I still have the same issue. Currently, I call Fritz.configure as the first line of the OnCreate method of the launching/main activity. The method looks like this:

override fun onCreate(savedInstanceState: Bundle?) {
Fritz.configure(this, “MY_API_KEY”)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

}

I then attempt to apply the style transfer in a separate activity. In this activity, I define the predictor variable:
lateinit var predictor: FritzVisionStylePredictor

I then initialize the predictor in the onCreate method of this activity with the following lines:

var paintingModels: PaintingStyleModels = FritzVisionModels.getPaintingStyleModels()
var styleOnDeviceModel = paintingModels.starryNight
predictor = FritzVision.StyleTransfer.getPredictor(styleOnDeviceModel)

I then attempt to create a style transfer in another method with the following lines:
var visionImage = FritzVisionImage.fromBitmap(uploadBitmap)
var styleReadable: FritzVisionStyleResult = predictor.predict(visionImage)
var newImage = styleReadable.toBitmap()
ivImage.setImageBitmap(newImage)

Please let me know if you see any issues with what I am doing here…Thank you again for your help.

That’s odd. If the MainActivity is the launching Activity, then configure should get called first. Can you debug the app and just make sure that Fritz.configure gets called before the crash happens? A good way to do this is to set a breakpoint on that line and make sure it gets called (before FritzVision.StyleTransfer.getPredictor).

Can you try upgrading to Fritz SDK version 6.0.0-beta.10 and letting us know if that solves your issue?