Figure: VerifyVision-Pro Web Interface - Displaying Image Forgery Detection Results and Detailed Analysis
VerifyVision-Pro is a comprehensive deep learning-based system designed to detect image forgeries with high accuracy. The system integrates robust data processing pipelines, state-of-the-art deep learning models, and an intuitive web interface for real-time detection.
-
🧠 Multi-Model Architecture Support: Integrates cutting-edge deep learning models including EfficientNet, ResNet, Xception, and CNN, with transfer learning capabilities and custom architecture support for optimal detection across diverse scenarios
-
🔄 End-to-End Complete Pipeline: Comprehensive solution spanning from raw data preprocessing, model training, performance evaluation to production deployment, featuring automated data augmentation and model optimization
-
🎨 Modern Web Interface: Responsive user interface built on Bootstrap 5.3.2, supporting drag-and-drop uploads, real-time preview, dark theme toggle, and intuitive detection result visualization
-
📊 Intelligent Analytics Engine: Provides confidence scoring, probability distribution analysis, confusion matrix visualization, ROC curve and AUC metrics support, enabling deep understanding of detection results
-
⚡ High-Performance Inference Optimization: Supports CUDA GPU acceleration, model quantization, batch inference processing, delivering millisecond-level response times for large-scale image detection tasks
-
🔧 Enterprise-Grade Features: Built-in logging system, error handling, API interfaces, Docker containerization support, meeting production environment deployment requirements
VerifyVision-Pro/
│
├── data/ # Data directory
│ ├── real/ # Real images
│ ├── fake/ # Forged images
│ └── processed/ # Preprocessed images
│
├── models/ # Model directory (gitignored)
│ └── saved/ # Saved model weights
│
├── src/ # Source code
│ ├── data_utils/ # Data processing utilities
│ │ ├── dataset.py # Dataset class
│ │ └── data_processor.py # Data preprocessing tools
│ │
│ ├── models/ # Model definitions
│ │ └── models.py # Deep learning model implementations
│ │
│ ├── training/ # Training related
│ │ ├── train.py # Training scripts
│ │ └── evaluate.py # Evaluation scripts
│ │
│ └── web/ # Web application
│ └── app.py # Flask application
│
├── static/ # Static resources
│ ├── css/ # CSS styles
│ │ └── style.css # Custom styles
│ │
│ ├── js/ # JavaScript
│ │ └── main.js # Main JS file
│ │
│ └── uploads/ # User uploaded images
│
├── templates/ # HTML templates
│ ├── base.html # Base template
│ ├── index.html # Home page
│ ├── result.html # Results page
│ └── about.html # About page
│
├── generate_test_images.py # Test image generation script
├── main.py # Project main entry program
├── requirements.txt # Project dependencies
└── README.md # Project description
- Python: 3.7+
- PyTorch: 2.0+
- RAM: 4GB (CPU only), 8GB (with GPU)
- Storage: 1GB for code and basic datasets
- OS: Windows 10+, macOS 10.15+, Ubuntu 18.04+
- Python: 3.9+
- PyTorch: 2.0+ with CUDA
- GPU: NVIDIA GPU with CUDA support (8GB+ VRAM)
- RAM: 16GB
- Storage: 10GB+ for extended datasets
- OS: Ubuntu 20.04+ or macOS 12+
git clone https://github.com/lintsinghua/VerifyVision-Pro.git
cd VerifyVision-Pro# For macOS/Linux
python -m venv imgvenv
source imgvenv/bin/activate
# For Windows
python -m venv imgvenv
imgvenv\Scripts\activatepip install -r requirements.txt# Check if PyTorch is properly installed with CUDA (if available)
python -c "import torch; print('CUDA available:', torch.cuda.is_available())"If you have an NVIDIA GPU, ensure you have installed the appropriate CUDA toolkit and cuDNN versions compatible with your PyTorch installation.
Follow this guide to quickly set up and run the VerifyVision-Pro system:
First, generate sample images for testing the system:
python generate_test_images.pyThis creates 20 real images and 20 fake images in the respective data directories.
Prepare the images for model training:
# Process real images
python main.py preprocess --input-dir data/real --output-dir data/processed/real --target-size 224 224
# Process fake images
python main.py preprocess --input-dir data/fake --output-dir data/processed/fake --target-size 224 224Train a basic CNN model using the preprocessed data:
python main.py train \
--real-dir data/processed/real \
--fake-dir data/processed/fake \
--model cnn \
--pretrained \
--epochs 5 \
--batch-size 4 \
--save-dir models/savedNote: For initial testing, a small number of epochs (5) is sufficient. Increase for better performance.
Start the web interface to interact with your trained model:
python main.py web \
--model-path models/saved/best_model.pth \
--model-name cnn \
--port 8080 \
--debugImportant: On macOS, port 5000 may be occupied by AirPlay service. Using port 8080 is recommended.
Open your browser and visit http://localhost:8080 to use the system.
Several methods are available to gather data for training and testing:
The built-in script generates synthetic data for testing purposes:
python generate_test_images.pyWhat it does:
- Creates
data/realanddata/fakedirectories - Generates 20 sample real images with random content
- Creates 20 corresponding fake images with manipulations
- Suitable for initial system testing and validation
Access information about public image forgery detection datasets:
python main.py download-infoThis displays links to valuable datasets commonly used in image forgery detection research, including:
- CASIA v1.0 and v2.0
- Columbia Image Splicing Detection
- CoMoFoD (Copy-Move Forgery Dataset)
- Coverage
- IEEE IFS-TC Image Forensics Challenge Dataset
Build your own dataset by:
-
Collecting real images:
- Place authentic images in
data/realdirectory - Use personal photos or public domain images
- Ensure diversity in content, lighting, and source devices
- Place authentic images in
-
Creating fake images:
python main.py create-fake \ --real-dir data/real \ --fake-dir data/fake \ --method splice \ --num-images 1000
Available forgery methods:
splice: Combines regions from different imagescopy: Duplicates regions within the same imagenoise: Adds localized noise to create inconsistenciescolor: Manipulates color properties in specific regions
Before training, images need to be preprocessed for consistency:
python main.py preprocess \
--input-dir data/real \
--output-dir data/processed/real \
--target-size 224 224 \
--max-images 5000Preprocessing operations include:
- Resizing to uniform dimensions
- Normalization
- Optional augmentation (rotation, flipping, etc.)
- Format standardization
- Optional color space conversion
Parameters:
--input-dir: Source directory containing images--output-dir: Destination for processed images--target-size: Output dimensions (width height)--max-images: Limit number of images to process (optional)--augment: Apply data augmentation (optional)
VerifyVision-Pro supports training various deep learning models for image forgery detection:
python main.py train \
--real-dir data/processed/real \
--fake-dir data/processed/fake \
--model efficientnet_b0 \
--pretrained \
--epochs 30 \
--batch-size 32 \
--learning-rate 0.001 \
--save-dir models/saved \
--early-stopping \
--patience 5The system implements several state-of-the-art architectures:
| Model | Description | Parameters | Suitable For |
|---|---|---|---|
cnn |
Custom CNN | ~500K | Quick testing, limited data |
resnet18 |
ResNet-18 | ~11M | Small to medium datasets |
resnet50 |
ResNet-50 | ~25M | Medium datasets |
efficientnet_b0 |
EfficientNet-B0 | ~5M | Balanced performance |
xception |
Xception | ~22M | Advanced features |
The training module offers comprehensive customization:
| Parameter | Description | Default | Notes |
|---|---|---|---|
--real-dir |
Real image directory | - | Required |
--fake-dir |
Fake image directory | - | Required |
--model |
Model architecture | efficientnet_b0 |
See available models |
--pretrained |
Use pretrained weights | False |
Flag |
--epochs |
Training epochs | 30 |
|
--batch-size |
Batch size | 32 |
Reduce for less memory |
--learning-rate |
Learning rate | 0.001 |
|
--weight-decay |
L2 regularization | 0.0001 |
|
--save-dir |
Save directory | models/saved |
|
--early-stopping |
Enable early stopping | False |
Flag |
--patience |
Epochs for early stopping | 5 |
|
--validation-split |
Validation data ratio | 0.2 |
During training, the system:
- Splits data into training and validation sets
- Loads or initializes the selected model architecture
- Applies transfer learning if pretrained weights are requested
- Optimizes using Adam optimizer with specified learning rate
- Implements learning rate scheduling for better convergence
- Monitors validation metrics to prevent overfitting
- Saves the best-performing model based on validation accuracy
- Generates training curves and performance statistics
- Early Stopping: Automatically stops training when performance plateaus
- Learning Rate Scheduling: Reduces learning rate when progress stalls
- Checkpointing: Saves model at regular intervals during training
- Mixed Precision: Uses FP16 training when supported by hardware
- Gradient Clipping: Prevents exploding gradients
- Data Augmentation: Optional real-time augmentation during training
After training, assess your model's performance using:
python main.py evaluate \
--real-dir data/processed/real \
--fake-dir data/processed/fake \
--model efficientnet_b0 \
--checkpoint models/saved/best_model.pth \
--results-dir results \
--confusion-matrix \
--roc-curveThe evaluation module provides comprehensive performance metrics:
| Metric | Description | Range |
|---|---|---|
| Accuracy | Overall correct predictions | 0-1 |
| Precision | True positives / predicted positives | 0-1 |
| Recall | True positives / actual positives | 0-1 |
| F1 Score | Harmonic mean of precision & recall | 0-1 |
| AUC-ROC | Area Under ROC Curve | 0-1 |
| Confusion Matrix | Visualization of predictions vs. ground truth | - |
- Per-class Analysis: Detailed metrics for real and fake classes
- Confidence Distribution: Histogram of prediction confidences
- Failure Analysis: Examination of misclassified samples
- Feature Visualization: Activation maps showing influential regions
- Cross-validation: Optional k-fold cross-validation for robust evaluation
The evaluation results help understand:
- How well the model generalizes to unseen data
- Whether it's biased toward a particular class
- Types of images that cause detection failures
- Confidence level in predictions
- Areas for potential improvement
Start the web application to interact with your trained model:
python main.py web \
--model-path models/saved/best_model.pth \
--model-name efficientnet_b0 \
--port 8080 \
--host 0.0.0.0 \
--debugThe VerifyVision-Pro web interface provides:
- User-friendly Upload: Simple drag-and-drop or file selection interface
- Real-time Analysis: Immediate processing and results display
- Visual Feedback: Clear indication of authenticity with confidence scores
- Heatmap Visualization: Optional visualization of suspicious regions
- Result History: Session-based history of analyzed images
- Responsive Design: Works on desktop and mobile devices
| Parameter | Description | Default | Notes |
|---|---|---|---|
--model-path |
Path to model file | - | Required |
--model-name |
Model architecture | - | Required |
--port |
Server port | 5000 |
Use 8080 on macOS |
--host |
Host address | 127.0.0.1 |
Use 0.0.0.0 for external access |
--debug |
Enable debug mode | False |
Flag |
--max-size |
Max upload size (MB) | 5 |
|
--threshold |
Detection threshold | 0.5 |
Range: 0-1 |
-
Upload an Image:
- Click "Choose File" or drag-and-drop an image onto the upload area
- Supported formats: JPG, JPEG, PNG
- Maximum file size: 5MB (configurable)
-
Analyze the Image:
- Click "Upload & Detect" button
- The system processes the image through the model
-
View Results:
- Real/Fake classification is displayed
- Confidence score indicates detection certainty
- Optional heatmap visualization highlights suspicious regions
- Additional metadata shows image properties
-
Interpret Results:
- Higher confidence scores indicate greater certainty
- Scores near 0.5 indicate uncertainty
- Consider using multiple models for ambiguous cases
For production deployment, consider:
- Nginx/Apache: Set up reverse proxy for better security and performance
- Docker: Containerized deployment for consistent environment
- Cloud Platforms: AWS, Google Cloud, or Azure for scalability
- SSL Certificate: Enable HTTPS for secure communication
- Rate Limiting: Prevent abuse of the service
VerifyVision-Pro is built on modern technologies for reliable performance:
- OpenCV: Image loading, preprocessing, and manipulation
- PIL (Pillow): Image format handling and transformations
- Albumentations: Advanced data augmentation pipeline
- NumPy: Efficient numerical operations on image data
- PyTorch: Primary deep learning framework
- TorchVision: Pre-trained models and dataset utilities
- CUDA: GPU acceleration for training and inference
- torchinfo: Model architecture visualization and analysis
- EfficientNet: Resource-efficient convolutional architecture
- ResNet: Deep residual networks with skip connections
- Xception: Depthwise separable convolutions for efficiency
- Custom CNN: Lightweight architecture for basic detection
- Flask: Lightweight web server implementation
- Werkzeug: WSGI utility library for web applications
- Jinja2: Templating engine for HTML generation
- Flask-WTF: Form handling and validation
- Bootstrap: Responsive design framework
- JavaScript: Dynamic client-side functionality
- Chart.js: Interactive visualization of results
- Dropzone.js: Enhanced file upload experience
The system implements a two-class classification approach with:
- Feature Extraction: Convolutional layers capture spatial features
- Feature Aggregation: Pooling operations aggregate local information
- Classification Head: Fully connected layers for final prediction
- Transfer Learning: Adaptation of pre-trained networks
- Domain-specific Features: Custom layers for forgery detection
The training system implements:
- Dataset Management: Custom PyTorch datasets for efficient loading
- Balanced Sampling: Ensures equal representation of classes
- Augmentation Strategy: Applied during training for robustness
- Mixed Precision: FP16 for faster training where supported
- Distributed Training: Optional multi-GPU support
The inference system includes:
- Preprocessing: Consistent with training pipeline
- Batched Processing: Efficient handling of multiple images
- Model Ensemble: Optional combination of multiple models
- Post-processing: Confidence calibration and thresholding
- Visualization: Generation of heatmaps for interpretability
Extend VerifyVision-Pro with custom model architectures:
-
Adding a New Model:
Modify
src/models/models.pyto include your architecture:class CustomModel(nn.Module): def __init__(self, num_classes=2, pretrained=False): super(CustomModel, self).__init__() # Define your model architecture here def forward(self, x): # Define forward pass return x
-
Registering the Model:
Add your model to the model factory:
def get_model(name, num_classes=2, pretrained=False): models = { # Existing models 'custom_model': CustomModel, } return models[name](num_classes=num_classes, pretrained=pretrained)
-
Using Your Model:
python main.py train \ --real-dir data/processed/real \ --fake-dir data/processed/fake \ --model custom_model \ --epochs 30
Enhance model performance with advanced dataset handling:
Create additional training data using generative methods:
python main.py generate-synthetic \
--base-images data/real \
--output-dir data/synthetic \
--count 1000 \
--techniques "copy,splice,removal,noise"Test model generalization across different datasets:
python main.py cross-validate \
--train-real data/datasetA/real \
--train-fake data/datasetA/fake \
--test-real data/datasetB/real \
--test-fake data/datasetB/fake \
--model efficientnet_b0Implement active learning to prioritize labeling efforts:
python main.py active-learning \
--unlabeled data/unlabeled \
--labeled data/labeled \
--model-path models/saved/model.pth \
--selection-method "entropy" \
--batch-size 100Understand model decisions with advanced visualization:
python main.py interpret \
--image path/to/image.jpg \
--model-path models/saved/model.pth \
--method "gradcam" \
--output-dir visualizationsAvailable interpretation methods:
gradcam: Gradient-weighted Class Activation Mappinglime: Local Interpretable Model-agnostic Explanationsshap: SHapley Additive exPlanationsocclusion: Occlusion sensitivity analysis
Maximize system performance with hardware optimizations:
Enable GPU acceleration for faster training and inference:
# Check GPU availability
python -c "import torch; print(torch.cuda.is_available(), torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'No GPU')"
# Train with GPU (automatic if available)
python main.py train --model efficientnet_b0 --batch-size 64 --real-dir data/processed/real --fake-dir data/processed/fakeDistribute training across multiple GPUs for larger models:
python -m torch.distributed.launch --nproc_per_node=4 main.py train \
--distributed \
--real-dir data/processed/real \
--fake-dir data/processed/fake \
--model efficientnet_b0 \
--batch-size 128Optimize CPU performance when GPU is unavailable:
# Set number of CPU threads
python main.py train --num-workers 8 --pin-memory --real-dir data/processed/real --fake-dir data/processed/fakeManage memory usage for efficient processing:
Adjust batch size based on available memory:
| Hardware | Recommended Batch Size |
|---|---|
| CPU | 8-16 |
| GPU 4GB VRAM | 16-32 |
| GPU 8GB VRAM | 32-64 |
| GPU 16GB+ VRAM | 64-128 |
# Smaller batch size for limited memory
python main.py train --batch-size 8 --real-dir data/processed/real --fake-dir data/processed/fake
# Larger batch size for high-end systems
python main.py train --batch-size 128 --real-dir data/processed/real --fake-dir data/processed/fakeTrain with large effective batch sizes on limited memory:
python main.py train \
--batch-size 16 \
--gradient-accumulation 4 \
--real-dir data/processed/real \
--fake-dir data/processed/fakeThis simulates a batch size of 64 (16 × 4) while only requiring memory for 16 samples.
Speed up production deployment:
Reduce model size and increase inference speed:
python main.py quantize \
--model-path models/saved/best_model.pth \
--quantized-model-path models/saved/quantized_model.pth \
--calibration-images data/processed/realThis reduces model size by up to 75% and increases inference speed by 2-4x.
Process multiple images simultaneously:
python main.py batch-inference \
--input-dir data/test \
--output-file results.csv \
--model-path models/saved/best_model.pth \
--batch-size 32Remove unnecessary connections for faster inference:
python main.py prune \
--model-path models/saved/best_model.pth \
--pruned-model-path models/saved/pruned_model.pth \
--prune-ratio 0.3This section addresses frequently encountered problems:
Symptoms: PyTorch installation succeeds but CUDA is not detected or crashes occur during GPU operations.
Solution:
-
Ensure compatible versions:
# Check CUDA version nvcc --version # Install compatible PyTorch version pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 -f https://download.pytorch.org/whl/torch_stable.html
-
Verify installation:
python -c "import torch; print('CUDA available:', torch.cuda.is_available())"
Symptoms: pip install fails with dependency conflicts.
Solution:
-
Create a fresh virtual environment:
python -m venv fresh_env source fresh_env/bin/activate -
Install dependencies one by one:
pip install numpy pip install torch torchvision pip install -r requirements.txt
Symptoms: Errors occur when installing dependencies with newer Python versions (e.g., Python 3.13), especially with numpy and pkgutil packages.
Solution:
-
Create a virtual environment with Python 3.9-3.10:
# First check available Python versions which -a python3 python3 -V /usr/bin/python3 -V # This might show the system Python version # Create a virtual environment with compatible versions /usr/bin/python3 -m venv imgvenv source imgvenv/bin/activate
-
Verify Python version:
python -V # This should show a compatible version, e.g., Python 3.9.x -
Install dependencies:
pip install -r requirements.txt
Note: The project dependencies are most compatible with Python 3.8-3.10. Newer versions might require adjustments to dependency versions or waiting for package updates to support new Python versions.
Symptoms: Web application fails to start with "Address already in use" error.
Solution:
-
On macOS, port 5000 is typically used by the AirPlay service, use a different port (like 8080):
python main.py web --model-path models/saved/best_model.pth --model-name cnn --port 8080
-
Or find and kill the process using port 5000 (not recommended, may affect system services):
sudo lsof -i :5000 kill -9 <PID>
-
You can also specify a local-only interface when starting the web application:
python main.py web --model-path models/saved/best_model.pth --model-name cnn --port 5000 --host 127.0.0.1
Note: In macOS Monterey and newer versions, port 5000 is reserved for the AirPlay Receiver service. To use the default port, disable the AirPlay Receiver in system settings or choose an alternative port.
Symptoms: Training crashes with "CUDA out of memory" or system memory errors.
Solution:
-
Reduce batch size:
python main.py train --batch-size 4 --real-dir data/processed/real --fake-dir data/processed/fake
-
Use gradient accumulation:
python main.py train --batch-size 2 --gradient-accumulation 8 --real-dir data/processed/real --fake-dir data/processed/fake
-
Use a smaller model:
python main.py train --model resnet18 --real-dir data/processed/real --fake-dir data/processed/fake
Symptoms: Training fails with "dataset is empty" errors.
Solution:
-
Verify directory paths:
ls -la data/processed/real data/processed/fake
-
Check file formats (should be .jpg, .jpeg, or .png):
find data/processed/real -type f | grep -v -E '\.(jpg|jpeg|png)$'
-
Generate test data to verify system:
python generate_test_images.py
Symptoms: Model achieves low accuracy or doesn't improve during training.
Solution:
-
Increase training duration:
python main.py train --epochs 50 --real-dir data/processed/real --fake-dir data/processed/fake
-
Try different models:
python main.py train --model efficientnet_b0 --pretrained --real-dir data/processed/real --fake-dir data/processed/fake
-
Ensure balanced dataset:
python main.py analyze-dataset --real-dir data/processed/real --fake-dir data/processed/fake
-
Enable data augmentation:
python main.py train --augmentation --real-dir data/processed/real --fake-dir data/processed/fake
Symptoms: Validation accuracy stops improving early in training.
Solution:
-
Adjust learning rate:
python main.py train --learning-rate 0.0001 --real-dir data/processed/real --fake-dir data/processed/fake
-
Implement learning rate scheduling:
python main.py train --scheduler cosine --real-dir data/processed/real --fake-dir data/processed/fake
-
Try different optimizers:
python main.py train --optimizer adamw --real-dir data/processed/real --fake-dir data/processed/fake
Symptoms: Training accuracy is high but validation accuracy is low.
Solution:
-
Add regularization:
python main.py train --weight-decay 0.001 --dropout 0.3 --real-dir data/processed/real --fake-dir data/processed/fake
-
Use early stopping:
python main.py train --early-stopping --patience 5 --real-dir data/processed/real --fake-dir data/processed/fake
-
Increase dataset size or diversity.
The quality of training data directly impacts model performance:
- Size: 1,000+ images per class minimum for good performance
- Balance: Maintain equal numbers of real and fake images
- Diversity: Include various image sources, lighting conditions, and content
- Authenticity: Ensure "real" images are truly unmanipulated
- Realism: Create forgeries that represent realistic manipulation methods
- Metadata: Preserve relevant metadata (camera model, editing software, etc.)
Choose models based on your specific requirements:
| Priority | Recommended Model |
|---|---|
| Speed | cnn or resnet18 |
| Accuracy | efficientnet_b0 or xception |
| Balance | resnet18 or efficientnet_b0 |
| Limited Data | cnn with heavy augmentation |
| Production | Ensemble of multiple models |
For real-world deployment:
- Security: Implement rate limiting and file validation
- Scalability: Use load balancing for high-traffic applications
- Privacy: Consider local processing for sensitive materials
- Transparency: Communicate confidence levels and limitations
- Updates: Regularly retrain with new forgery techniques
- Fallback: Have human review for critical or ambiguous cases
Be aware of system limitations:
- Detection accuracy varies by forgery type and quality
- Advanced AI-generated images may require specialized models
- Very small manipulations might be missed
- Results should be treated as probabilistic, not definitive
- System should be part of a broader verification strategy
We welcome contributions to VerifyVision-Pro! Here's how you can help:
- Use the GitHub issue tracker to report bugs
- Include detailed steps to reproduce the issue
- Attach sample images when relevant (ensure you have rights to share)
- Specify your environment (OS, Python version, etc.)
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name
- Make your changes
- Run tests:
python -m pytest tests/
- Submit a pull request
We particularly welcome contributions in:
- New Models: Implementations of state-of-the-art architectures
- Detection Methods: Novel approaches to identifying manipulations
- UI Improvements: Enhancing the web interface and visualization
- Performance Optimization: Improving speed and resource usage
- Documentation: Tutorials, examples, and clarifications
- Localization: Translations of documentation and interface
Please follow these guidelines:
- PEP 8 compliant Python code
- Docstrings for all functions, classes, and modules
- Type hints where appropriate
- Comprehensive comments for complex logic
- Unit tests for new functionality
VerifyVision-Pro is released under the MIT License.
This project incorporates components from third-party open source projects:
- PyTorch (BSD License)
- Flask (BSD License)
- TorchVision (BSD License)
- OpenCV (Apache 2.0 License)
- Bootstrap (MIT License)
- Various other packages as listed in requirements.txt
⭐ If this project helps you, please give us a Star!
