تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
إذا كان تطبيقك يستخدم تنسيقًا مخصّصًا
TensorFlow Lite، يمكنك
استخدام تعلُّم الآلة في Firebase لنشر نماذجك. من خلال نشر النماذج باستخدام Firebase، يمكنك
يمكنك تقليل حجم التنزيل الأولي لتطبيقك وتعديل نماذج تعلُّم الآلة الخاصة به.
بدون طرح إصدار جديد من التطبيق وباستخدام "الإعداد عن بُعد" وA/B
الاختبار، يمكنك عرض نماذج مختلفة بشكل ديناميكي لمجموعات مختلفة من المستخدمين.
طُرز TensorFlow Lite
نماذج TensorFlow Lite هي نماذج تعلُّم الآلة التي تم تحسينها لتعمل على الأجهزة الجوّالة.
الأجهزة. للحصول على نموذج TensorFlow Lite، اتّبِع الخطوات التالية:
تجدر الإشارة إلى أنّه في حال عدم توفّر مكتبة TensorFlow Lite محفوظة لـ Dart،
التكامل مع مكتبة TensorFlow Lite الأصلية
الأساسية. هذا الدمج غير موثَّق هنا.
من الدليل الجذري لمشروع Flutter، شغِّل ما يلي:
لتثبيت المكوّن الإضافي لأداة تنزيل نموذج تعلُّم الآلة:
flutterpubaddfirebase_ml_model_downloader
إعادة إنشاء مشروعك:
flutterrun
1- نشر النموذج
انشر نماذج TensorFlow المخصّصة باستخدام وحدة تحكُّم Firebase أو
حزم تطوير البرامج (SDK) الخاصة بمشرفي Firebase وهما Python وNode.js. عرض
نشر النماذج المخصَّصة وإدارتها
بعد إضافة نموذج مخصّص إلى مشروعك على Firebase، يمكنك الرجوع إلى
النموذج في تطبيقاتك باستخدام الاسم الذي حددته. يمكنك في أي وقت نشر
نموذج TensorFlow Lite الجديد وتنزيل النموذج الجديد على حسابات المستخدمين الأجهزة بواسطة
الاتصال بـ getModel() (انظر أدناه).
2- تنزيل النموذج على الجهاز وإعداد أداة الترجمة الفورية من TensorFlow Lite
لاستخدام نموذج TensorFlow Lite في تطبيقك، عليك أولاً استخدام أداة تنزيل النموذج.
لتنزيل أحدث إصدار من الطراز على الجهاز. ثم، قم بإنشاء مثيل
أداة الترجمة الفورية من TensorFlow Lite باستخدام النموذج.
لبدء تنزيل النموذج، يمكنك استدعاء طريقة getModel() لأداة تنزيل النموذج،
تحديد الاسم الذي عينته للنموذج عند تحميله، سواء
ترغب دائمًا في تنزيل أحدث طراز، والحالات التي بموجبها
يريدون السماح بالتنزيل.
يمكنك الاختيار من بين ثلاثة سلوكيات للتنزيل:
نوع عملية التنزيل
الوصف
localModel
الحصول على الطراز المحلي من الجهاز
في حال عدم توفُّر نموذج محلي، سيتم
يتصرف مثل latestModel. استخدام هذه المسودة
نوع التنزيل إذا لم تكن مهتمًا
البحث عن تحديثات النموذج. على سبيل المثال:
تستخدم "الإعداد عن بُعد" لاسترداد
أسماء النماذج ودائمًا تحميل النماذج
تحت أسماء جديدة (يُنصح بهذا الخيار)
localModelUpdateInBackground
الحصول على الطراز المحلي من الجهاز
تحديث النموذج في الخلفية.
في حال عدم توفُّر نموذج محلي، سيتم
يتصرف مثل latestModel.
latestModel
احصل على أحدث طراز. إذا كان النموذج المحلي
يعرض أحدث إصدار،
الأمثل. أو يمكنك تنزيل أحدث إصدار
الأمثل. سيتم حظر هذا السلوك حتى
تنزيل أحدث إصدار (ليس
(يوصى به). لا تستخدم هذا السلوك إلا في
الحالات التي تحتاج فيها صراحة إلى أحدث
.
ينبغي لك تعطيل الوظائف المتعلقة بالنموذج، على سبيل المثال، الوضع الرمادي أو
إخفاء جزء من واجهة المستخدم — إلى أن تتأكد من تنزيل النموذج.
FirebaseModelDownloader.instance.getModel("yourModelName",FirebaseModelDownloadType.localModel,FirebaseModelDownloadConditions(iosAllowsCellularAccess:true,iosAllowsBackgroundDownloading:false,androidChargingRequired:false,androidWifiRequired:false,androidDeviceIdleRequired:false,)).then((customModel){// Download complete. Depending on your app, you could enable the ML// feature, or switch from the local model to the remote model, etc.// The CustomModel object contains the local path of the model file,// which you can use to instantiate a TensorFlow Lite interpreter.finallocalModelPath=customModel.file;// ...});
تبدأ العديد من التطبيقات مهمة التنزيل من خلال رمز الإعداد الخاص بها، ولكن يمكنك إجراء ذلك
لذا في أي وقت قبل أن تحتاج إلى استخدام النموذج.
3- إجراء استنتاج على بيانات الإدخال
الآن بعد أن يتوفّر لديك ملف الطراز على الجهاز، يمكنك استخدامه مع
أداة الترجمة الفورية من TensorFlow Lite لإجراء الاستنتاج. في حالة عدم وجود
مكتبة TensorFlow Lite لـ Dart، ستحتاج إلى الدمج مع
مكتبات TensorFlow Lite الأصلية
لأجهزة iOS وAndroid.
الملحق: أمان النموذج
بغض النظر عن كيفية إتاحة طُرز TensorFlow Lite
تخزنها تكنولوجيا تعلُّم الآلة في Firebase، بتنسيق أولي تسلسلي عادي
التخزين المحلي.
ومن الناحية النظرية، يعني هذا أنه بإمكان أي شخص نسخ نموذجك. ومع ذلك،
عمليًا، تكون معظم النماذج خاصة بالتطبيقات ومشوَّشة بواسطة
تتشابه المخاطر مع تلك الخاصة بالمنافسين الذين يقومون بتفكيكها
إعادة استخدام التعليمات البرمجية. ومع ذلك، يجب أن تكون على دراية بهذا الخطر قبل استخدام
نموذج مخصص في تطبيقك.
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Use a custom TensorFlow Lite model with Flutter\n\n\u003cbr /\u003e\n\nIf your app uses custom\n[TensorFlow Lite](https://www.tensorflow.org/lite/) models, you can\nuse Firebase ML to deploy your models. By deploying models with Firebase, you\ncan reduce the initial download size of your app and update your app's ML models\nwithout releasing a new version of your app. And, with Remote Config and A/B\nTesting, you can dynamically serve different models to different sets of users.\n\nTensorFlow Lite models\n----------------------\n\nTensorFlow Lite models are ML models that are optimized to run on mobile\ndevices. To get a TensorFlow Lite model:\n\n- Use a pre-built model, such as one of the [official TensorFlow Lite models](https://www.tensorflow.org/lite/models)\n- [Convert a TensorFlow model, Keras model, or concrete function to TensorFlow Lite.](https://www.tensorflow.org/lite/convert)\n\nNote that in the absence of a maintained TensorFlow Lite library for Dart, you\nwill need to integrate with the native TensorFlow Lite library for your\nplatforms. This integration is not documented here.\n\nBefore you begin\n----------------\n\n1. [Install and initialize the Firebase SDKs for Flutter](/docs/flutter/setup)\n if you haven't already done so.\n\n2. From the root directory of your Flutter project, run the following\n command to install the ML model downloader plugin:\n\n flutter pub add firebase_ml_model_downloader\n\n3. Rebuild your project:\n\n flutter run\n\n1. Deploy your model\n--------------------\n\nDeploy your custom TensorFlow models using either the Firebase console or\nthe Firebase Admin Python and Node.js SDKs. See\n[Deploy and manage custom models](/docs/ml/manage-hosted-models).\n\nAfter you add a custom model to your Firebase project, you can reference the\nmodel in your apps using the name you specified. At any time, you can deploy a\nnew TensorFlow Lite model and download the new model onto users' devices by\ncalling `getModel()` (see below).\n\n2. Download the model to the device and initialize a TensorFlow Lite interpreter\n--------------------------------------------------------------------------------\n\nTo use your TensorFlow Lite model in your app, first use the model downloader\nto download the latest version of the model to the device. Then, instantiate a\nTensorFlow Lite interpreter with the model.\n\nTo start the model download, call the model downloader's `getModel()` method,\nspecifying the name you assigned the model when you uploaded it, whether you\nwant to always download the latest model, and the conditions under which you\nwant to allow downloading.\n\nYou can choose from three download behaviors:\n\n| Download type | Description |\n|--------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `localModel` | Get the local model from the device. If there is no local model available, this behaves like `latestModel`. Use this download type if you are not interested in checking for model updates. For example, you're using Remote Config to retrieve model names and you always upload models under new names (recommended). |\n| `localModelUpdateInBackground` | Get the local model from the device and start updating the model in the background. If there is no local model available, this behaves like `latestModel`. |\n| `latestModel` | Get the latest model. If the local model is the latest version, returns the local model. Otherwise, download the latest model. This behavior will block until the latest version is downloaded (not recommended). Use this behavior only in cases where you explicitly need the latest version. |\n\nYou should disable model-related functionality---for example, grey-out or\nhide part of your UI---until you confirm the model has been downloaded. \n\n FirebaseModelDownloader.instance\n .getModel(\n \"yourModelName\",\n FirebaseModelDownloadType.localModel,\n FirebaseModelDownloadConditions(\n iosAllowsCellularAccess: true,\n iosAllowsBackgroundDownloading: false,\n androidChargingRequired: false,\n androidWifiRequired: false,\n androidDeviceIdleRequired: false,\n )\n )\n .then((customModel) {\n // Download complete. Depending on your app, you could enable the ML\n // feature, or switch from the local model to the remote model, etc.\n\n // The CustomModel object contains the local path of the model file,\n // which you can use to instantiate a TensorFlow Lite interpreter.\n final localModelPath = customModel.file;\n\n // ...\n });\n\nMany apps start the download task in their initialization code, but you can do\nso at any point before you need to use the model.\n\n3. Perform inference on input data\n----------------------------------\n\nNow that you have your model file on the device you can use it with the\nTensorFlow Lite interpreter to perform inference. In the absence of a maintained\nTensorFlow Lite library for Dart, you will need to integrate with the\n[native TensorFlow Lite libraries](https://www.tensorflow.org/lite)\nfor iOS and Android.\n\nAppendix: Model security\n------------------------\n\nRegardless of how you make your TensorFlow Lite models available to\nFirebase ML, Firebase ML stores them in the standard serialized protobuf format in\nlocal storage.\n\nIn theory, this means that anybody can copy your model. However,\nin practice, most models are so application-specific and obfuscated by\noptimizations that the risk is similar to that of competitors disassembling and\nreusing your code. Nevertheless, you should be aware of this risk before you use\na custom model in your app."]]