Skip to content

abuhasanbaskara/prototype-tensor-flow-flutter

Repository files navigation

Pristine Checker - AI欠陥検出アプリ

概要

Pristine Checkerは、TensorFlow Liteを使用したリアルタイム欠陥検出モバイルアプリケーションです。カメラを使用して製品の品質をAIで分析し、欠陥の有無を即座に判定します。

プロジェクト構造

主要ファイル

  • メインエントリーポイント: lib/main.dart - Flutterアプリのメイン構造
  • TensorFlow Liteモデル: assets/models/model_unquant.tflite - 欠陥検出用のMLモデル
  • モデルラベル: assets/models/labels.txt - 分類ラベル(0: Good, 1: Defect)
  • 依存関係: pubspec.yaml - Flutter依存関係とアセット設定
  • Android設定: android/app/src/main/AndroidManifest.xml - Android権限と設定
  • iOS設定: ios/Runner/Info.plist - iOS権限と設定

アーキテクチャ

pristine_checker/
├── lib/
│   └── main.dart                 # メインアプリケーション
├── assets/
│   └── models/
│       ├── model_unquant.tflite  # TensorFlow Liteモデル
│       └── labels.txt           # 分類ラベル
├── android/                      # Android固有の設定
├── ios/                         # iOS固有の設定
└── pubspec.yaml                 # 依存関係とアセット設定

技術スタック

フレームワーク

  • Flutter: クロスプラットフォームモバイル開発フレームワーク
  • Dart: Flutterのプログラミング言語

主要パッケージ

  • camera: ^0.10.5+9 - カメラ機能の実装
  • permission_handler: ^11.3.1 - プラットフォーム間の権限管理
  • tflite_flutter: ^0.11.0 - TensorFlow Liteモデルの実行

AI/ML

  • TensorFlow Lite: モバイル最適化された機械学習フレームワーク
  • リアルタイム推論: カメラストリームからの連続的な画像分析

機能

1. リアルタイム欠陥検出

  • カメラを使用したライブ画像分析
  • 224x224ピクセルにリサイズしてモデルに送信
  • BGRA8888フォーマットからRGBへの変換
  • [-1, 1]範囲での正規化

2. 分類結果

  • Good: 欠陥なし(緑色表示)
  • Defect: 欠陥あり(赤色表示)
  • Waiting for object: 背景検出時(青色表示)

3. 信頼度表示

  • パーセンテージでの信頼度表示
  • Softmax関数による確率計算
  • 背景検出のための閾値処理

4. 権限管理

  • カメラ権限の動的リクエスト
  • 設定画面への誘導
  • アプリ再開時の権限状態確認

セットアップと実行

前提条件

  • Flutter SDK 3.8.1以上
  • Android Studio / Xcode
  • 物理デバイス(カメラ機能のテスト用)

インストール手順

  1. リポジトリのクローン
git clone <repository-url>
cd pristine_checker
  1. 依存関係のインストール
flutter pub get
  1. アセットの確認
# モデルファイルとラベルファイルが存在することを確認
ls assets/models/
  1. アプリの実行
# Android
flutter run

# iOS
flutter run -d ios

TensorFlow Liteモデルの詳細

モデル仕様

  • 入力: 224x224x3 (RGB画像)
  • 出力: 2クラス分類 (Good/Defect)
  • フォーマット: 非量子化モデル (.tflite)
  • 正規化: [-1, 1]範囲

前処理パイプライン

  1. 画像取得: カメラからBGRA8888フォーマットで取得
  2. フォーマット変換: BGRA → RGB変換
  3. リサイズ: 224x224ピクセルにリサイズ
  4. 正規化: [0, 255] → [-1, 1]範囲に変換
  5. 推論実行: TensorFlow Liteインタープリターで実行

後処理

  1. Softmax適用: 生のロジットを確率に変換
  2. 信頼度計算: 各クラスの確率を計算
  3. 背景検出: 信頼度差と最大信頼度による判定
  4. UI更新: 結果に基づく色とテキストの更新

パフォーマンス最適化

推論最適化

  • スロットリング: 300ms間隔での処理制限
  • 並行処理防止: _isProcessingフラグによる制御
  • メモリ効率: Float32Listの直接使用

UI最適化

  • 安定化処理: 400msの待機時間による結果安定化
  • 背景検出: 信頼度差0.2未満で背景と判定
  • リアルタイム更新: setStateによる即座のUI更新

プラットフォーム固有の設定

Android設定

<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true" />

iOS設定

<!-- Info.plist -->
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to detect defects in products using AI analysis.</string>

トラブルシューティング

よくある問題

  1. カメラ権限エラー

    • 設定アプリでカメラ権限を手動で有効化
    • アプリの再起動
  2. モデル読み込みエラー

    • assets/models/フォルダの存在確認
    • pubspec.yamlのアセット設定確認
  3. 推論エラー

    • デバイスのメモリ不足
    • モデルファイルの破損

デバッグ

  • コンソールログで詳細な処理状況を確認
  • flutter analyzeでコード品質チェック
  • 物理デバイスでのテスト推奨

開発ガイドライン

コード品質

  • Flutter Lintsルールに準拠
  • 適切なエラーハンドリング
  • 非同期処理の適切な実装

テスト

  • 物理デバイスでの動作確認
  • 異なる照明条件でのテスト
  • 様々な製品タイプでの検証

ライセンス

このプロジェクトはプライベートプロジェクトです。

貢献

プロジェクトへの貢献については、プロジェクトオーナーにお問い合わせください。


Pristine Checker - AI Defect Detection App

Overview

Pristine Checker is a real-time defect detection mobile application using TensorFlow Lite. It analyzes product quality using AI through the camera and instantly determines the presence of defects.

Project Structure

Key Files

  • Main Entry Point: lib/main.dart - Main Flutter app structure
  • TensorFlow Lite Model: assets/models/model_unquant.tflite - ML model for defect detection
  • Model Labels: assets/models/labels.txt - Classification labels (0: Good, 1: Defect)
  • Dependencies: pubspec.yaml - Flutter dependencies and asset configuration
  • Android Config: android/app/src/main/AndroidManifest.xml - Android permissions and configuration
  • iOS Config: ios/Runner/Info.plist - iOS permissions and configuration

Architecture

pristine_checker/
├── lib/
│   └── main.dart                 # Main application
├── assets/
│   └── models/
│       ├── model_unquant.tflite  # TensorFlow Lite model
│       └── labels.txt           # Classification labels
├── android/                      # Android-specific configuration
├── ios/                         # iOS-specific configuration
└── pubspec.yaml                 # Dependencies and asset configuration

Technology Stack

Framework

  • Flutter: Cross-platform mobile development framework
  • Dart: Programming language for Flutter

Key Packages

  • camera: ^0.10.5+9 - Camera functionality implementation
  • permission_handler: ^11.3.1 - Cross-platform permission management
  • tflite_flutter: ^0.11.0 - TensorFlow Lite model execution

AI/ML

  • TensorFlow Lite: Mobile-optimized machine learning framework
  • Real-time Inference: Continuous image analysis from camera stream

Features

1. Real-time Defect Detection

  • Live image analysis using camera
  • Resize to 224x224 pixels for model input
  • BGRA8888 to RGB format conversion
  • Normalization to [-1, 1] range

2. Classification Results

  • Good: No defects (green display)
  • Defect: Defects present (red display)
  • Waiting for object: Background detected (blue display)

3. Confidence Display

  • Percentage-based confidence display
  • Probability calculation using Softmax function
  • Threshold processing for background detection

4. Permission Management

  • Dynamic camera permission requests
  • Settings navigation guidance
  • Permission status check on app resume

Setup and Execution

Prerequisites

  • Flutter SDK 3.8.1 or higher
  • Android Studio / Xcode
  • Physical device (for camera functionality testing)

Installation Steps

  1. Clone Repository
git clone <repository-url>
cd pristine_checker
  1. Install Dependencies
flutter pub get
  1. Verify Assets
# Confirm model and label files exist
ls assets/models/
  1. Run Application
# Android
flutter run

# iOS
flutter run -d ios

TensorFlow Lite Model Details

Model Specifications

  • Input: 224x224x3 (RGB image)
  • Output: 2-class classification (Good/Defect)
  • Format: Unquantized model (.tflite)
  • Normalization: [-1, 1] range

Preprocessing Pipeline

  1. Image Capture: Acquire BGRA8888 format from camera
  2. Format Conversion: BGRA → RGB conversion
  3. Resize: Resize to 224x224 pixels
  4. Normalization: Convert [0, 255] → [-1, 1] range
  5. Inference Execution: Execute using TensorFlow Lite interpreter

Post-processing

  1. Softmax Application: Convert raw logits to probabilities
  2. Confidence Calculation: Calculate probability for each class
  3. Background Detection: Determine based on confidence difference and maximum confidence
  4. UI Update: Update colors and text based on results

Performance Optimization

Inference Optimization

  • Throttling: 300ms interval processing limitation
  • Concurrent Processing Prevention: Control using _isProcessing flag
  • Memory Efficiency: Direct use of Float32List

UI Optimization

  • Stabilization Processing: Result stabilization with 400ms wait time
  • Background Detection: Determine background when confidence difference < 0.2
  • Real-time Updates: Immediate UI updates via setState

Platform-Specific Configuration

Android Configuration

<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true" />

iOS Configuration

<!-- Info.plist -->
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to detect defects in products using AI analysis.</string>

Troubleshooting

Common Issues

  1. Camera Permission Error

    • Manually enable camera permission in Settings app
    • Restart the application
  2. Model Loading Error

    • Verify existence of assets/models/ folder
    • Check asset configuration in pubspec.yaml
  3. Inference Error

    • Device memory shortage
    • Model file corruption

Debugging

  • Check detailed processing status via console logs
  • Use flutter analyze for code quality check
  • Test on physical devices recommended

Development Guidelines

Code Quality

  • Comply with Flutter Lints rules
  • Proper error handling
  • Appropriate async processing implementation

Testing

  • Verify operation on physical devices
  • Test under different lighting conditions
  • Validate with various product types

License

This project is a private project.

Contributing

For contributions to this project, please contact the project owner.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published