A mobile application built with React Native and integrated with an image-based cat re-identification system to prevent redundant medical treatments of stray cats. This system is designed to support volunteers, animal hospitals, and TNR organizations, especially in the Kansai region of Japan. This project is made as a part of a Project-Based-Learning Course which spans over 15 weeks.
Project Pipeline & Model Workflow:
- Users upload or capture a cat image via the mobile app or web interface.
- The backend detects and crops the cat face using a YOLO-based detector.
- The processed image is passed through a Siamese neural network (EfficientNetB3 backbone) to generate a 128-dimensional embedding.
- The embedding is compared to a database of known cat embeddings using Euclidean distance.
- If a match is found (distance below threshold), the system returns the cat's profile and medical info; otherwise, it provides guidance for registration.
- Results and confidence scores are displayed in a user-friendly UI on both web and mobile platforms.
Here is the Project's Documentation Website: Project Documentation Website
Below are a few key images from the project repository. They are included here to make it easier to understand the mobile experience and the model outputs.
-
Mobile preview: mobile-app_preview.jpg
A screenshot mockup of the Expo/React Native mobile app used by volunteers. The preview shows the main identification flow: capture or upload an image, run the identification, and display the match result with confidence. This image helps reviewers understand the mobile UX and how the backend re-ID results surface to users.
-
Figure 1: Figure_1.png
Training and evaluation curves for the contrastive Siamese model (accuracy and loss over epochs). This figure illustrates training stability and the validation performance used to pick the final model checkpoint.
-
Figure 2: Figure_2.png
Visualization of dataset composition and distribution (images per class / cat). This helps explain why certain classes may be under-represented and informs future data collection priorities.
This project uses high-quality cat re-identification datasets, originally scraped and organized for machine learning research:
- Kaggle Dataset: Cat Re-Identification Image Dataset
- HelloStreetCat Dataset: HelloStreetCat Individuals Dataset
- Scraping Toolkit: WebScrape_neko-jirushi GitHub Repository
- Input: Two (contrastive) or three (triplet) images, each resized to 200x200x3.
- Backbone:
- Pretrained EfficientNetB3 (default), VGG16, or MobileNetV2 (configurable).
- The backbone processes each image independently (shared weights).
- Embedding Head:
- Global Average Pooling (if not present in backbone)
- Dense layer (128 units, ReLU activation)
- Optional Batch Normalization and Dropout for regularization
- Output: 128-dimensional L2-normalized embedding vector for each image
- Contrastive Loss:
- For a pair of images (x1, x2):
- Compute Euclidean distance between embeddings: D = ||f(x1) - f(x2)||
- Loss = y * D^2 + (1 - y) * max(0, margin - D)^2
- y = 1 for positive pair (same cat), 0 for negative pair
- margin = 1.0 (configurable)
- For a pair of images (x1, x2):
- Triplet Loss:
- For a triplet (anchor, positive, negative):
- Loss = max(0, D(anchor, positive) - D(anchor, negative) + margin)
- margin = 0.2 (configurable)
- For a triplet (anchor, positive, negative):
- Optimizer: Adam (learning rate 0.0001)
- Batch Size: 16 (configurable)
- Epochs: 50 (production), 1 (debug)
- Data Augmentation: Optional (flip, rotate, noise)
- Early Stopping: Monitors validation loss
- Learning Rate Scheduler: Reduces LR on plateau
- Preprocessing:
- Detect and crop cat face (YOLO-based detector)
- Resize to 200x200, normalize to [0,1]
- Embedding Extraction:
- Pass image through backbone and embedding head
- Matching:
- Compute Euclidean distance to all known cat embeddings
- If distance < threshold (0.4), report as match
- Otherwise, report as no match
- Training: Saved as Keras .h5 (with custom objects) or TensorFlow SavedModel (recommended for deployment)
- Deployment: Loads SavedModel or .h5 (if compatible)
- All architecture parameters (backbone, embedding size, margin, etc.) are configurable in
config_siamese.py. - Easily switch between contrastive and triplet loss modes.
This project builds upon the research presented in:
- Research Paper: Siamese Networks for Cat Re-Identification: Exploring Neural Models for Cat Instance Recognition (Trein & Garcia, 2024)
- Implementation Repository: Hello Street Cat Reidentification by Tobias Trein
The research paper demonstrates the effectiveness of Siamese Networks for cat re-identification using VGG16 with contrastive loss on a dataset of 2,796 images of 69 cats from the Hello Street Cat initiative.
To streamline the Trap-Neuter-Return (TNR) process and reduce unnecessary hospital visits for stray cats in the Kansai region of Japan by enabling users to:
- Identify previously captured and treated cats using AI-based image matching.
- View and manage cat profiles with medical histories.
- Coordinate efficiently between caretakers, hospitals, and organizations.
- Ensure data integrity, usability, and privacy compliance.
- Upload or capture a photo of a stray cat to check for prior registration.
- AI provides a confidence score and match result (high, moderate, or low).
- Feedback system for users to report false matches.
- Role-based access for Volunteers, Animal Hospitals, and Administrators.
- Profile creation, editing, verification, and deletion supported.
- Password recovery and secure authentication mechanisms.
- View and update cat profiles: age, gender, vaccination status, and treatment history.
- Hospitals can log surgeries and medical interventions.
- Tagging system (e.g., neutered, under treatment, released).
- Supports photo capture via device camera or gallery upload.
- Validates format, size, and resolution (≥ 1280x720, ≤ 5MB).
- Mobile and offline-capable submission process.
- System dashboards for match statistics and cat counts.
- Access control, audit logs, and activity tracking.
- Re-ID match reviews and visualization of trends.
| Role | Description |
|---|---|
| Volunteers | Submit cat sightings, upload images, and help reduce redundant captures. |
| Animal Hospitals | Update medical histories, create/edit profiles, and manage treatment logs. |
| Administrators | Oversee system users, manage content, and monitor analytics. |
- Initial deployment in Kansai Region, Japan.
- Supports up to 1000 volunteers and 3 animal hospitals.
- Mobile-first design compatible with Android and iOS (React Native).
- Backend support via Flask (Python) and TensorFlow-based re-ID model.
| Layer | Technology |
|---|---|
| Frontend | React Native, Expo |
| Backend | Python (Flask) |
| AI Model | TensorFlow (Cat Re-ID) |
- Total cats in dataset: 250 cats
- Total images: 1,880 images
- Average images per cat: 7.52 images
- Training subset: 20 cats with 12 images each (240 total training images)
- Image formats: PNG (470 images), JPG (1,410 images)
- Dataset structure: Each cat in separate folder with cat ID and metadata
Contrastive Learning Model:
- Accuracy: 69.4% (0.694)
- Precision: 67.7% (0.677)
- Recall: 69.4% (0.694)
- F1-Score: 68.2% (0.682)
- Status: Successfully trained and evaluated
Triplet Learning Model:
- Status: Training completed but evaluation failed
- Note: Model files exist but evaluation pipeline had issues
- Contrastive Learning Works Well: Achieved ~69% accuracy with limited training data
- Triplet Learning Challenges: More complex optimization, requires more data
- Production Ready: Contrastive model is ready for deployment
git clone https://github.com/your-org/cat-reid-app.git
cd PBL3_GroupH- Install Python dependencies:
pip install flask ultralytics opencv-python
- Register known cats:
python ai_model/register_known_cats.py
- Start the server:
python serve.py
- The server will run on
http://<your-ip>:5000.
- Install Node.js (v18+) and Expo CLI:
npm install -g expo-cli
- Install dependencies:
cd PBL3Expo npm install npx expo install expo-camera expo-image-picker - Start the app:
npm start
- Run on your phone:
- Install Expo Go from the App Store/Google Play.
- Connect your phone and computer to the same WiFi.
- Scan the QR code from the terminal/browser.
For training the Siamese network models:
# Set up environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txt
# Configure training mode
# Edit train_siamese.py and set DEBUG_MODE = False for production
# Run training
python run_training.pyPBL3_GroupH/
├── post_processing/ # Dataset directory (250 cats, 1,880 images)
├── ai_model/ # AI model components
├── config/ # Configuration files
├── core/ # Core utilities
├── data/ # Database and logs
├── gui/ # GUI components
├── images/ # Image storage
├── PBL3Expo/ # React Native mobile app
├── train_siamese.py # Main training script
├── run_training.py # Training pipeline runner
├── dataset_analyzer.py # Dataset analysis
├── config_siamese.py # Training configuration
├── requirements.txt # Python dependencies
├── serve.py # Flask backend server
├── best_siamese_contrastive.h5 # Trained contrastive model (81MB)
├── best_siamese_triplet.h5 # Trained triplet model (81MB)
├── training_history_contrastive.png # Training curves
├── training_history_triplet.png # Training curves
├── siamese_training_results.csv # Performance metrics
├── dataset_analysis.png # Dataset distribution
├── dataset_analysis.csv # Detailed dataset stats
├── selected_cats_for_training.csv # Training subset info
└── README.md # This file
DEBUG_MODE = Trueintrain_siamese.py- Uses 2 cats, 2 images per cat, 1 epoch
- MobileNetV2, 64x64 images
- Fast testing on CPU
DEBUG_MODE = Falseintrain_siamese.py- Uses 20 cats, 12 images per cat, 50 epochs
- EfficientNetB3, 200x200 images
- Full training on GPU
- Open the mobile app (on phone or emulator)
- Take a photo or choose from gallery
- Tap 'Identify Cat'
- View results (match, no match, or error)
- Configure server in the Explore tab if needed
- Start the server:
python serve.py - Access the web interface at
http://localhost:5000 - Upload cat photos for identification
- View detailed results with confidence scores
The system includes administrative endpoints for authorized personnel:
curl http://localhost:5000/statuscurl -H "X-API-Key: admin_key_2024" http://localhost:5000/admin/catscurl -X POST -H "X-API-Key: admin_key_2024" \
-F "image=@cat_photo.jpg" \
-F "cat_id=cat_12345" \
-F "cat_name=Fluffy" \
-F "notes=Found in downtown area" \
http://localhost:5000/admin/registercurl -H "X-API-Key: admin_key_2024" http://localhost:5000/admin/config# Basic Training
python run_training.py
# Skip Analysis
python run_training.py --skip-analysis
# Analysis Only
python run_training.py --analysis-only
# Fast Mode
python run_training.py --fast- Python 3.8+
- TensorFlow 2.x
- OpenCV
- NumPy, Pandas, Matplotlib
- scikit-learn
- Flask (for backend)
- React Native, Expo (for mobile app)
- Format: Each cat in a separate folder named
cat_XXXXX/ - Images: PNG, JPG, JPEG files
- Minimum: 3+ images per cat
- Recommended: 10+ images per cat for better results
- Current: 250 cats with 1,880 total images
- Debug Mode: ~1 minute on CPU
- Production Mode: ~30-60 minutes on GPU
- Contrastive Model Accuracy: 69.4% on test set
- Model Size: ~81 MB per model
- Training Data: 240 images (20 cats × 12 images)
- Uses pairs of images (positive: same cat, negative: different cats)
- Learns to minimize distance for positive pairs and maximize for negative pairs
- Good for binary similarity learning
- Uses triplets (anchor, positive, negative)
- Learns embeddings where positive is closer to anchor than negative
- Often provides better discriminative features
- EfficientNetB3: Current default, good balance of accuracy and speed
- VGG16: Classic architecture, good for transfer learning
- MobileNetV2: Lightweight, good for mobile deployment
- Test Set: 20% of data (stratified split)
- Evaluation Method: Pair-based classification
- Distance Threshold: 0.4 (from research papers)
- Metrics: Accuracy, Precision, Recall, F1-Score
- 69.4% accuracy achieved with limited training data
- Robust performance despite small dataset
- Ready for production use
- Training completed successfully
- Evaluation pipeline failed (known bug)
- Model files exist but metrics unreliable
To enable data augmentation, modify config_siamese.py:
USE_AUGMENTATION = True
AUGMENTATION_TYPES = ['flip', 'rotate', 'noise']Change the base model in config_siamese.py:
BASE_MODEL = 'vgg' # or 'mobilenet'Modify training parameters in config_siamese.py:
EPOCHS = 100
LEARNING_RATE = 0.0001
BATCH_SIZE = 16- Data Loading: Loads images from your organized dataset
- Preprocessing: Resizes images to 200x200 and normalizes to [0,1]
- Pair/Triplet Generation: Creates training pairs or triplets
- Model Training: Trains with early stopping and learning rate reduction
- Evaluation: Tests on held-out data using nearest neighbor classification
The pipeline evaluates models using:
- Accuracy: Overall classification accuracy
- Precision: Precision for each class (weighted average)
- Recall: Recall for each class (weighted average)
- F1-Score: Harmonic mean of precision and recall
Run the comprehensive test suite to verify system behavior:
# Test no-auto-registration policy
python test_no_auto_registration.pyThis test verifies:
- System only performs identification
- Auto-registration is explicitly disabled
- Admin authorization required for registration
- Proper guidance provided when no match is found
- Administrative endpoints are properly secured
- Start the server:
python serve.py - Test identification: Upload a cat photo via web interface
- Test admin endpoints: Use curl commands with API key
- Verify no auto-registration: Confirm new cats aren't added automatically
- Out of Memory: Reduce batch size in
config_siamese.py - Slow Training: Use GPU or reduce image size
- Import Errors: Ensure all dependencies are installed
- Dataset Issues: Check folder structure and image formats
- Evaluation Failures: Triplet model evaluation may fail (known issue)
- Port Conflicts: If port 5000 is in use, use
PORT=5001 python serve.py
# Check GPU availability
nvidia-smi
# Install GPU version of TensorFlow (if needed)
pip install tensorflow-gpuThe system is designed with a strict no-auto-registration policy to prevent database pollution and ensure data quality:
- Identification Only: The system only performs identification against previously registered cats
- Auto-Registration Disabled: New cats are never automatically added to the database
- Admin Authorization Required: Only authorized personnel can register new cats
- TNR Compliance: Registration requires completion of Trap-Neuter-Return procedures
- Data Quality Control: Prevents duplicate registrations and ensures proper documentation
- API Key Authentication: Administrative endpoints require valid API keys
- File Size Limits: Uploads limited to 10MB to prevent abuse
- Input Validation: All inputs are validated and sanitized
- Error Handling: Comprehensive error handling with user-friendly messages
- Audit Trail: All administrative actions are logged with timestamps
- TNR Process: Cat must complete Trap-Neuter-Return procedures
- Photo Documentation: Clear photos from multiple angles required
- Admin Review: Authorized personnel review and approve registration
- Database Entry: Cat is manually registered with proper documentation
- Verification: System verifies registration and creates embeddings
- Account creation with verification (FR-1, FR-4)
- Photo upload and Re-ID results with confidence scores (FR-7, FR-8)
- View, add, edit, delete cat profiles (FR-9, FR-10, FR-11)
- Role-based access and logging (FR-15)
- Admin analytics and match management (FR-13, FR-14)
- Mobile-first design with responsive layouts and offline sync.
- Visual accessibility (WCAG 2.2 AA) and performance optimizations.
- Secure session management and encryption (TLS, AES-256).
- Data privacy and GDPR/Japanese compliance.
- Disaster resilience and eco-friendly cloud architecture.
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License and is part of PBL3 Group H coursework.

