🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
1 Tag Serie
🎥 Künstliche Intelligenz Videos 🕛 kürzlich 17 Min Lesezeit
0

How to Create a Cartoonizer with TensorFlow Lite

↗ Quelle (blog.tensorflow.org)
🗣️ Stimme:
📑 Inhaltsübersicht
A guest post by ML GDEs (PyImageSearch)

We created this end-to-end tutorial to help developers with these objectives:
  • Provide a reference for the developers looking to convert models written in TensorFlow 1.x to their TFLite variants using the new features of the latest (v2) converter — for example, the MLIR-based converter, more supported ops, and improved kernels, etc.
    (In order to convert TensorFlow 2.x models in TFLite please follow for model saving/conversion, populating metadata; and the Android code on GitHub for details. While this tutorial discusses the steps of how to create the TFLite models , feel free to download them directly from TensorFlow Hub by Xinrui Wang and Jinze Yu. For this tutorial, we used the generator part of White-box CartoonGAN.

    Create the TensorFlow Lite Model

    The authors of White-box CartoonGAN . Here is a step-by-step summary of what we will be covering in this section:
    • Generate a SavedModel out of the pre-trained model checkpoints.
    • Convert SavedModel with post-training quantization using the latest TFLiteConverter.
    • Run inference in Python with the converted model.
    • Add metadata to enable easy integration with a mobile app.
    • Run model benchmark to make sure the model runs well on mobile.

    Generate a SavedModel from the pre-trained model weights

    The pre-trained weights of White-box CartoonGAN come in the following format (also referred to as checkpoints) -
    TEXT
    ├── checkpoint
    ├── model-33999.data-00000-of-00001
    └── model-33999.index
    As the original White-box CartoonGAN model is implemented in TensorFlow 1, we first need to generate a single self-contained model file in the SavedModel format using TensorFlow 1.15. Then we will switch to TensorFlow 2 later to convert it to the lightweight TFLite format. To do this we can follow this workflow -
    • Create a placeholder for the model input.
    • Instantiate the model instance and run the input placeholder through the model to get a placeholder for the model output.
    • Load the pre-trained checkpoints into the current session of the model.
    • Finally, export to SavedModel.
    Note that the aforementioned workflow will be based on TensorFlow 1.x.
    This is how all of this looks in code in TensorFlow 1.x:
    PYTHON
    with tf.Session() as sess:
    input_photo = tf.placeholder(tf.float32, [1, None, None, 3], name='input_photo')

    network_out = network.unet_generator(input_photo)
    final_out = guided_filter.guided_filter(input_photo, network_out, r=1, eps=5e-3)
    final_out = tf.identity(final_out, name='final_output')

    all_vars = tf.trainable_variables()
    gene_vars = [var for var in all_vars if 'generator' in var.name]
    saver = tf.train.Saver(var_list=gene_vars)
    sess.run(tf.global_variables_initializer())
    saver.restore(sess, tf.train.latest_checkpoint(model_path))

    # Export to SavedModel
    tf.saved_model.simple_save(
    sess,
    saved_model_directory,
    inputs={input_photo.name: input_photo},
    outputs={final_out.name: final_out}
    )
    Now that we have the original model in the SavedModel format, we can switch to TensorFlow 2 and proceed toward converting it to TFLite.

    Convert SavedModel to TFLite

    TFLite provides support for three different .
    In order to let the TFLiteConverter take advantage of this strategy, we need to just pass converter.representative_dataset = representative_dataset_gen and remove converter.target_spec.supported_types = [tf.float16].
    So after we generated these different models here’s how we stand in terms of model size -
    .
    These models are available on .

    Running inference in Python

    After you have generated the TFLite models, it is important to make sure that models perform as expected. A good way to ensure that is to run inference with the models in Python before integrating them in mobile applications.
    Before feeding an image to our White-box CartoonGAN TFLite models it’s important to make sure that the image is preprocessed well. Otherwise, the models might perform unexpectedly. The original model was trained using BGR images, so we need to account for this fact in the preprocessing steps as well. You can find all of the preprocessing steps in this Again, you can find all of the postprocessing steps in . But in this section, we are going to provide you with some of the important pointers about metadata population for the TFLite models we generated. You can follow running in background and another with an Repeat above steps for the other two tflite models: float16 and int8 variants.
    In summary, here is the average inference time we got from the benchmark tool running on a Pixel 4:
    | .

    Model deployment to Android

    Now that we have the quantized TensorFlow Lite models with metadata by either following the previous steps (or by downloading the models directly from TensorFlow Hub .
    The Android app uses Jetpack Navigation Component for UI navigation and CameraX for image capture. We use the new ML Model Binding feature for importing the tflite model and then Kotlin Coroutine for async handling of the model inference so that the UI is not blocked while waiting for the results.
    Let’s dive into the details step by step:
    • Download Android Studio 4.1 Preview.
    • Create a new Android project and set up the UI navigation.
    • Set up the CameraX API for image capture.
    • Import the .tflite models with ML Model Binding.
    • Putting everything together.

    Download Android Studio 4.1 Preview

    We need to first install Android Studio Preview (4.1 Beta 1) in order to use the new ML Model Binding feature to import a .tflite model and auto code generation. You can then explore the tfllite models visually and most importantly use the generated classes directly in your Android projects.
    Download the Android Studio Preview to learn more details about this support library.
    There are 3 screens in this sample app:
    • PermissionsFragment.kt handles checking the camera permission.
    • CameraFragment.kt handles camera setup, image capture and saving.
    • CartoonFragment.kt handles the display of input and cartoon image in the UI.
    The navigation graph in nav_graph.xml defines the navigation of the three screens and data passing between CameraFragment and CartoonFragment.

    Set up CameraX for image capture

    CameraX is a Jetpack support library which makes camera app development much easier.
    Camera1 API was simple to use but it lacked a lot of functionality. Camera2 API provides more fine control than Camera1 but it’s very complex — with almost 1000 lines of code in a very basic example.
    CameraX on the other hand, is much easier to set up with 10 times less code. In addition, it’s lifecycle aware so you don’t need to write the extra code to handle the Android lifecycle.
    Here are the steps to set up CameraX for this sample app:
    • Update build.gradle dependencies
    • Use CameraFragment.kt to hold the CameraX code
    • Request camera permission
    • Update AndroidManifest.ml
    • Check permission in MainActivity.kt
    • Implement a viewfinder with the CameraX Preview class
    • Implement image capture
    • Capture an image and convert it to a Bitmap
    CameraSelector is configured to be able to take use of the front facing and rear facing camera since the model can stylize any type of faces or objects, and not just a selfie.
    Once we capture an image, we convert it to a Bitmap which is passed to the TFLite model for inference. Navigate to a new screen CartoonFragment.kt where both the original image and the cartoonized image are displayed.

    Import the TensorFlow Lite models

    Now that the UI code has been completed. It’s time to import the TensorFlow Lite model for inference. ML Model Binding takes care of this with ease. In Android Studio, go to File > New > Other > TensorFlow Lite Model: This import accomplishes two things:
    • automatically create a ml folder and place the model file .tflite file under there.
    • auto generate a Java class under the folder: app/build/generated/ml_source_out/debug/[package-name]/ml, which handles all the tasks such as model loading, image pre-preprocess and post-processing, and run model inference for stylizing the input image.
    Once the import completes, we see the *.tflite display the model metadata info as well as code snippets in both Kotlin and Java that can be copy/pasted in order to use the model: This brings us to the end of the tutorial. We hope you have enjoyed reading it and will apply what you learned to your real-world applications with TensorFlow Lite. If you have created any cool samples with what you learned here, please remember to add it to project with end-to-end tutorial was created with the great collaboration by ML GDEs and the TensorFlow Lite team. This is the one of a series of : Xinrui Wang and Jinze Yu.
    When developing applications, it’s important to consider for resources and tools you can use.
    Vollständiger Original-Bericht
    Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf blog.tensorflow.org.
    ↗ Original-Artikel auf blog.tensorflow.org lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to Create a Cartoonizer with TensorFlow Lite

Thematisch verwandte Begriffe: Create, Cartoonizer, with, TensorFlow · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...